Azure / Azure/data-api-builder
[Bug]: Swagger/OpenAPI fails with Custom Auth in DAB 1.7.93: No authentication handler is registered for OAuthAuthentication
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 370
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 8
Description
### What happened?
After upgrading Data API Builder from version 1.1.7 to 1.7.93, the Swagger UI no longer loads correctly when using `Custom` authentication with Auth0.
The Swagger page starts loading, but the OpenAPI endpoint fails. The DAB logs show an unhandled exception while requesting `/api/openapi`.
The same configuration works with DAB 1.1.7 for REST API calls using a valid Auth0 JWT token. In 1.1.7, Swagger UI loads, although Swagger UI does not seem to send the `Authorization` header when trying requests from the UI.
In DAB 1.7.93, `/api/openapi` fails before Swagger can be used.
### Version
Data API Builder 1.7.93
Previous working version: 1.1.7
### Authentication provider
Custom authentication with Auth0 JWT.
Relevant configuration:
```json
{
"data-source": {
"database-type": "mssql",
"connection-string": "@env('SQL_CONNECTION_STRING')"
},
"runtime": {
"rest": {
"enabled": true,
"path": "/api"
},
"host": {
"mode": "development",
"authentication": {
"provider": "Custom",
"jwt": {
"audience": "",
"issuer": "https://.eu.auth0.com/"
}
}
}
}
}
### Version
1.7.93
### What database are you using?
MSSQL
### What hosting model are you using?
Local (including CLI)
### Which API approach are you accessing DAB through?
REST
### Relevant log output
```Text
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:5000/api/maquinas - - -
dbug: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[3]
The request path does not match the path filter
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1001]
1 candidate(s) found for the request path '/api/maquinas'
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1005]
Endpoint 'Azure.DataApiBuilder.Service.Controllers.RestController.Find (Azure.DataApiBuilder.Service)' with route pattern '{*route}' is valid for the request path '/api/maquinas'
dbug: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware[1]
Request matched endpoint 'Azure.DataApiBuilder.Service.Controllers.RestController.Find (Azure.DataApiBuilder.Service)'
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HNLFV59JKKLV", Request id "0HNLFV59JKKLV:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: No authentication handler is registered for the scheme 'OAuthAuthentication'. The registered schemes are: StaticWebAppsAuthentication, AppServiceAuthentication, Bearer, SimulatorAuthentication. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("OAuthAuthentication",...)?
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware.InvokeAsync(HttpContext httpContext) in /_/src/Core/AuthenticationHelpers/ClientRoleHeaderAuthenticationMiddleware.cs:line 76
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Azure.DataApiBuilder.Service.Startup.<>c__DisplayClass23_0.<b__5>d.MoveNext() in /_/src/Service/Startup.cs:line 669
--- End of stack trace from previous location ---
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Azure.DataApiBuilder.Core.Services.PathRewriteMiddleware.InvokeAsync(HttpContext httpContext) in /_/src/Core/Services/PathRewriteMiddleware.cs:line 89
at Azure.DataApiBuilder.Core.Services.CorrelationIdMiddleware.Invoke(HttpContext httpContext) in /_/src/Core/Services/CorrelationIdMiddleware.cs:line 53
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[9]
Connection id "0HNLFV59JKKLV" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 GET http://localhost:5000/api/maquinas - 500 0 - 5.6669ms
```
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Assessment
This issue has not been assessed yet.