Resolve Custom JWT auth provider to the registered Bearer scheme - #3821
Souvik Ghosh (souvikghosh04) wants to merge 2 commits into
Conversation
Custom (and any non out-of-box JWT) auth providers registered the JWT handler under the Bearer scheme but ClientRoleHeaderAuthenticationMiddleware resolved the request scheme to the unregistered 'OAuthAuthentication', causing AuthenticateAsync to throw 'No authentication handler is registered for the scheme OAuthAuthentication' on every REST/GraphQL/OpenAPI request. Resolve all JWT-configured providers to JwtBearerDefaults.AuthenticationScheme and remove the now-unused GenericOAuthDefaults. Adds regression test covering Custom/AzureAD/EntraID.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Removing the public GenericOAuthDefaults type may break consumers; retain an obsolete compatibility shim.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
Fixes JWT authentication for custom providers by resolving them to the registered Bearer scheme.
Changes:
- Aligns JWT provider resolution with the registered bearer handler.
- Adds regression tests for Custom, AzureAD, and EntraID.
- Removes the unused OAuth scheme definition.
| File | Description |
|---|---|
src/Service.Tests/Authentication/JwtTokenAuthenticationUnitTests.cs |
Adds JWT provider regression coverage. |
src/Core/AuthenticationHelpers/GenericOAuthDefaults.cs |
Removes the obsolete OAuth scheme definition. |
src/Core/AuthenticationHelpers/ClientRoleHeaderAuthenticationMiddleware.cs |
Maps JWT providers to the registered bearer scheme. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| { | ||
| // Changing this value is a breaking change because non-out of box | ||
| // authentication provider names supplied in dab-config.json indicate | ||
| // that JWT bearer authentication should be used. | ||
| return GenericOAuthDefaults.AUTHENTICATIONSCHEME; | ||
| // Every non-EasyAuth/Simulator/Unauthenticated provider (AzureAD, EntraID, and any | ||
| // custom OAuth/JWT provider such as "Custom") is authenticated via JWT bearer. The JWT | ||
| // handler is always registered under JwtBearerDefaults.AuthenticationScheme ("Bearer") | ||
| // in Startup's ConfigureAuthentication/ConfigureAuthenticationV2, so the resolved scheme |
There was a problem hiding this comment.
I noticed this as well, but I dont think it is an issue that will arise, as I doubt anyone it taking dependencies on this. We could document it however just so that it is made clear.
aaronburtle
left a comment
There was a problem hiding this comment.
Looks good, might want to document the change in pubic facing type.

Summary
Fixes #3541.
Requests fail with
Custom(and any non out‑of‑box JWT) authentication provider:This affects normal REST/GraphQL requests as well as the
/api/openapi(Swagger) endpoint.Root cause
An internal authentication‑scheme name mismatch:
e.g.
Custom), DAB registers the JWT bearer handler underJwtBearerDefaults.AuthenticationScheme("Bearer") in bothConfigureAuthentication(production) andConfigureAuthenticationV2(development,AddJwtBearer()→"Bearer").ClientRoleHeaderAuthenticationMiddleware.ResolveConfiguredAuthNSchemereturned
GenericOAuthDefaults.AUTHENTICATIONSCHEME("OAuthAuthentication") forCustom—a scheme that is never registered as a handler anywhere in the codebase.
httpContext.AuthenticateAsync("OAuthAuthentication")therefore throws.AzureAD/EntraIDworked only because they explicitly returned the matching"Bearer"scheme.
Customis equally a JWT‑bearer provider and must resolve to the same registered scheme.Fix
ResolveConfiguredAuthNSchemenow resolves every JWT‑configured provider (AzureAD, EntraID,and any custom provider such as
Custom) toJwtBearerDefaults.AuthenticationScheme,matching the handler registration.
GenericOAuthDefaultsclass (its"OAuthAuthentication"constant wasnever registered as a handler and was the sole source of the mismatch).
Tests
JwtTokenAuthenticationUnitTests.TestValidToken_JwtConfiguredProviders, a regressiontest that validates a JWT through the middleware for
Custom,AzureAD, andEntraIDproviders and asserts the request is authenticated (HTTP 200). Prior to the fix, the
Customcase threw
No authentication handler is registered for the scheme 'OAuthAuthentication'.JwtTokenAuthenticationUnitTestspass;dotnet format --verify-no-changesis clean on the changed files.