Fix bearer-only security builds and bearer scheme name mapping - #74
Merged
Merged
Conversation
added 4 commits
September 24, 2026 08:18
…heme exists
A spec that applied a bearer scheme without any role, policy or scope did
not compile: the unified Add{Project}Api() referenced the Generated.Security
namespace and AddApiSecurityPolicies() whenever a scheme existed, while the
security DI extractor only emitted them when there was a policy to register.
The extractor now follows the same condition as its caller. With no policy
the method just calls services.AddAuthorization(), which the generated
UseAuthorization() needs anyway - skipping the call instead would have
turned the compile error into a startup failure for hosts that do not
register authorization themselves.
An authenticated operation may return 403 for application-level reasons, such as "not a known user" or "not your resource", without any role, policy or scope in the spec. OPR022 flagged every such operation, which broke builds using TreatWarningsAsErrors on perfectly standard specs. The rule now fires only when the operation has no effective security requirement: none declared, or opted out with "security: []".
…ion scheme
Endpoints passed the securityScheme key to AddAuthenticationSchemes(), but
ASP.NET Core only authenticates against a registered scheme, and
AddJwtBearer() / AddMicrosoftIdentityWebApi() register "Bearer". A spec
using the conventional key "BearerAuth" therefore built green and then
failed every request with "No authentication handler is registered".
A "type: http, scheme: bearer" securityScheme now maps to "Bearer". The new
x-authentication-scheme extension on a securityScheme names any other
registered scheme, and every other scheme type keeps its key.
Hosts that registered AddJwtBearer("<securityScheme key>") to match the old
behaviour must switch to the default AddJwtBearer() or add
x-authentication-scheme to the spec. The Showcase and MultipartDemo hosts
did exactly that and are moved to the default here.
…erenced
No scenario ever produced the unified Add{Project}Api()/Map{Project}Api()
surface, because the test host never referenced Atc.Rest.MinimalApi - which
is how the missing AddApiSecurityPolicies() went unnoticed.
The package is now referenced, but hidden from a scenario unless its Server
marker sets a MinimalApi mode to "Enabled", so the "Auto" scenarios keep
their output. The new SecurityBearerOnly scenario opts in and goes through
the compilation gate, and runtime tests host its generated code on Kestrel:
401 without a token, 200 with one and no role.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
🐛 Fixes
✨ Features
💥 Breaking Changes
♻️ Refactoring
🔧 Configuration
✅ Tests
Breaking Changes