Skip to content

feat: fluent API shorthand — client builders, resource setup, constants & response helpers#26

Merged
dasiths merged 3 commits into
mainfrom
feat/fluent-api-shorthand
May 28, 2026
Merged

feat: fluent API shorthand — client builders, resource setup, constants & response helpers#26
dasiths merged 3 commits into
mainfrom
feat/fluent-api-shorthand

Conversation

@dasiths
Copy link
Copy Markdown
Collaborator

@dasiths dasiths commented May 28, 2026

Summary

Fluent API improvements across the AAuth SDK (Phases 5–10), reducing verbosity for the three main developer surfaces: agent client construction, resource server setup, and endpoint request handling.

Key Changes

Agent-Side (Client Builder)

Pattern Before After
Self-issued identity SelfIssued(key, iss, sub, kid) SelfIssuing(key).As(iss, sub)
AP-enrolled client 7 lines (3 constructor calls) Enrolled(key).RefreshingFrom(...)
Call chaining manual exchange .WithCallChaining(ctx)

Resource-Side (Server Setup)

Pattern Before After
Full middleware setup 3 separate calls with repeated config app.MapAAuthResource() (reads from DI)
Challenge an agent 3 lines (header + format + status) ctx.ChallengeAAuth(rt)
Read token type (string?)parsed.Header?["typ"] ctx.GetAAuthTokenType()
Read verification ctx.Features.Get<AAuthVerificationResult>() ctx.GetAAuthVerification()
Set error header ctx.Response.Headers[...] = msg ctx.SetAAuthError(msg)

Infrastructure

  • AAuthConstants — centralized protocol constants (headers, schemes, token types, DWK files)
  • AAuthTokenType enum — type-safe token type with ParseTokenType/ToHeaderValue helpers
  • AAuthHttpContextExtensions — typed access to verification results and protocol response helpers
  • Bare string literals replaced with constants across SDK internals

Files Changed

  • 7 new source files (builders, constants, enum, extensions, pipeline options)
  • 5 new test files (96 new test cases)
  • 31 modified files (samples, docs, SDK internals)
  • All 635 tests pass (295 unit + 340 conformance)
  • All E2E workflows verified (JWT, HWK, JWKS-URI, JKT-JWT, call-chain via Orchestrator)

Breaking Changes

  • AAuthVerificationResult.TokenType changed from string? to AAuthTokenType enum
  • AAuthClientBuilder.SelfIssued(key, iss, sub, kid) removed (use SelfIssuing(key).As(iss, sub))
  • AAuthClientBuilder.WithSelfIssuedToken() made internal (use SelfIssuing(key).As(iss, sub))

Testing

Passed! - Failed: 0, Passed: 295 - AAuth.Tests.dll
Passed! - Failed: 0, Passed: 340 - AAuth.Conformance.dll

All AgentConsole workflows pass E2E against live sample servers.

…ants, and response helpers

Phases 5-10 of the Client Builder Fluent Shorthand initiative:

- Phase 5: SelfIssuing(key).As(iss, sub) fluent sub-builder replacing
  positional SelfIssued(key, iss, sub, kid) [marked Obsolete]
- Phase 6: Enrolled(key).RefreshingFrom(...) for AP-enrolled clients
- Phase 7: MapAAuthResource() unified middleware setup from DI options
- Phase 8: All samples and docs updated to use new fluent APIs
- Phase 9: AAuthConstants, AAuthTokenType enum, HttpContext extensions
  (GetAAuthVerification, GetAAuthParsedKey, GetAAuthTokenType)
- Phase 10: Resource-side response helpers (ChallengeAAuth, SetAAuthError)

All 648 tests pass (308 unit + 340 conformance).
All AgentConsole workflows verified E2E (JWT, HWK, JWKS-URI, JKT-JWT, call-chain).
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Phases 5–10 of the AAuth SDK fluent API initiative. Adds verb-form sub-builders for self-issued and AP-enrolled clients, a unified resource-side MapAAuthResource() pipeline, central protocol constants, an AAuthTokenType enum, and HttpContext extension helpers — replacing scattered string literals, manual Items[] casts, and multi-call middleware setup.

Changes:

  • New fluent client builders: AAuthClientBuilder.SelfIssuing(key).As(...) and AAuthClientBuilder.Enrolled(key).RefreshingFrom(...); legacy SelfIssued(...) marked [Obsolete].
  • New server-side surface: AAuthConstants, AAuthTokenType enum (breaking change to AAuthVerificationResult.TokenType), AAuthHttpContextExtensions (GetAAuthVerification/GetAAuthParsedKey/GetAAuthTokenType/ChallengeAAuth/SetAAuthError), and app.MapAAuthResource() unified pipeline.
  • SDK internals, samples, and docs broadly refactored to use the new constants, enum, and extension helpers; six new test files (~30+ tests added).
Show a summary per file
File Description
src/AAuth/AAuthConstants.cs New centralized protocol constants.
src/AAuth/AAuthTokenType.cs New token type enum + parse/format helpers.
src/AAuth/HttpSig/SelfIssuingBuilder.cs New fluent sub-builder for self-issued identity.
src/AAuth/HttpSig/EnrolledBuilder.cs New fluent sub-builder for AP-enrolled clients.
src/AAuth/HttpSig/AAuthClientBuilder.cs Adds SelfIssuing/Enrolled factories, WithSelfIssuedToken, WithPersonServer; obsoletes SelfIssued.
src/AAuth/HttpSig/AAuthSigningHandler.cs Header literals replaced with constants.
src/AAuth/HttpSig/SignatureKeyParser.cs Scheme literals replaced with constants.
src/AAuth/HttpSig/DefaultSignatureKeyResolver.cs Scheme literals replaced with constants.
src/AAuth/Server/AAuthHttpContextExtensions.cs New typed accessors and response helpers.
src/AAuth/Server/AAuthVerificationMiddleware.cs Uses new constants; stores AAuthTokenType enum.
src/AAuth/Server/AAuthVerificationResult.cs TokenType changed to AAuthTokenType enum (breaking).
src/AAuth/Server/AAuthChallengeMiddleware.cs Uses constants and enum for scheme/token-type comparisons.
src/AAuth/Agent/ChallengeHandler.cs Header literals replaced with constants.
src/AAuth/Agent/NamingJwtBuilder.cs Uses AAuthConstants.TokenTypes.NamingJwt.
src/AAuth/Discovery/ServerMetadata.cs Uses AAuthConstants.DwkFiles.
src/AAuth/DependencyInjection/AAuthApplicationBuilderExtensions.cs New MapAAuthResource() unified pipeline.
src/AAuth/DependencyInjection/AAuthResourcePipelineOptions.cs New options class for the unified pipeline.
samples/Orchestrator/Program.cs Uses SelfIssuing(...).As(...) and GetAAuthVerification().
samples/WhoAmI/Program.cs Uses extension helpers and ChallengeAAuth.
samples/MockPersonServer/Program.cs Uses extension helpers and AAuthTokenType.
samples/GuidedTour/CodeSnippets.cs Snippets migrated to new fluent API.
samples/SampleApp/Components/Pages/{Jwt,Hwk,JwksUri,Deferred,CallChain}.razor Display and runtime snippets updated.
docs/**, README.md Migrated examples to fluent shorthand and extension helpers.
tests/AAuth.Tests/AAuthConstantsTests.cs Verifies new constants match existing builder fields.
tests/AAuth.Tests/AAuthTokenTypeTests.cs Enum parse/format round-trip tests.
tests/AAuth.Tests/Server/AAuthHttpContextExtensionsTests.cs Tests for the new HttpContext extensions.
tests/AAuth.Tests/HttpSig/SelfIssuingBuilderTests.cs Tests for SelfIssuingBuilder.
tests/AAuth.Tests/HttpSig/EnrolledBuilderTests.cs Tests for EnrolledBuilder.
tests/AAuth.Tests/HttpSig/AAuthClientBuilderSelfIssuedTests.cs Tests for legacy + new self-issued paths.
.agent/plans/2026-05-28-self-issued-client-builder-shorthand/* Research, implementation plan, before/after summary, plan log.

Copilot's findings

  • Files reviewed: 48/48 changed files
  • Comments generated: 1

Comment thread tests/AAuth.Tests/Server/AAuthHttpContextExtensionsTests.cs
dasiths added 2 commits May 28, 2026 14:53
Alpha SDK — no need to keep deprecated API surface.

- Remove SelfIssued(key, iss, sub, kid) static method entirely
- Make WithSelfIssuedToken() internal (only used by SelfIssuingBuilder)
- Delete duplicate test file (AAuthClientBuilderSelfIssuedTests)
- Merge 4 unique tests into SelfIssuingBuilderTests
- Remove WithSelfIssuedToken from public API docs

635 tests pass (295 unit + 340 conformance).
Addresses PR review comment — the test claimed to verify both header
and status but only checked the header. Now asserts IStatusCodeHttpResult
returns 401.
@dasiths dasiths merged commit 08d70dd into main May 28, 2026
1 check passed
@dasiths dasiths deleted the feat/fluent-api-shorthand branch May 28, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants