You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Goal: Implement access control for the OpenAPI document endpoints (/openapi/*.json) using OAuth2/OIDC to prevent unauthorized scanning of the API structure.
Secure OpenAPI with OAuth2 in ASP.NET Core
🎯 Summary
/openapi/*.json) using OAuth2/OIDC to prevent unauthorized scanning of the API structure.ASP.NET Core 10.0,Microsoft.AspNetCore.OpenApi,Microsoft.Identity.Web,System.Security.Claims🛠 Roadmap (Pomodoro Tasks)
AuthenticationandAuthorizationservices inProgram.csusingAddMicrosoftIdentityWebAppAuthenticationor standardAddJwtBearer.MapOpenApi().RequireAuthorization("OpenApiPolicy")to protect the generated JSON.OpenApiOptionsconfiguration to addSecurityScheme(Type: OAuth2) to the document for downstream consumer compatibility.OpenApiSecurityRequirementto the document generator to signal that all operations require the defined OAuth2 scheme.UseAuthentication()andUseAuthorization()are called before mapping endpoints.🔍 Acceptance Criteria
/openapi/v1.jsonwithout a validAuthorization: Bearer <token>header returns a401 Unauthorized./openapi/v1.jsonwith a valid token but insufficient permissions returns a403 Forbidden.securityandsecuritySchemescomponents according to the OpenAPI 3.0/3.1 specification.💡 AI-Suggestions
AllowAnonymous()in local Development if requested.📚 Resources