Include metadata scopes in WWW-Authenticate challenge - #2196
Open
sdelamo wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the OAuth2 protected-resource metadata integration by adding an optional scope parameter to the WWW-Authenticate: Bearer challenge, sourced from ProtectedResourceMetadataProvider for the current request (including path-specific metadata). It keeps the existing resource_metadata challenge parameter behavior and documents the new scope-emission behavior.
Changes:
- Add
scopeto the BearerWWW-Authenticatechallenge whenProtectedResourceMetadata.scopesSupported()is non-empty after trimming. - Extend test coverage to validate scope emission and omission for null/empty/blank-only scope lists.
- Update the OAuth protected-resource metadata and
WWW-Authenticatedocumentation to describe provider-backed scope behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
security-oauth2/src/main/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProvider.java |
Adds provider-derived scope parameter emission while preserving existing resource_metadata behavior. |
security-oauth2/src/test/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProviderTest.java |
Adds tests for scope inclusion from path-specific metadata and omission when scopes are null/empty/blank-only. |
src/main/docs/guide/oauth/oauth-endpoints/protectedResourceMetadata.adoc |
Documents that the same metadata provider also drives Bearer challenge scopes. |
src/main/docs/guide/rejection/wwwAuthenticate.adoc |
Documents when scope will be included in the Bearer WWW-Authenticate challenge. |
|
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
scopechallenge parameter fromProtectedResourceMetadataProviderfor the current request or path-specific protected-resource metadata.resource_metadatachallenge behavior and omitscopewhen metadata scopes are null, empty, or blank-only.WWW-Authenticatedocs for the provider-backed behavior.Release Target
5.1.x5.1.05.1.0 Release(Throw an error if multiple annotations are used. #147)Verification
git diff --check -- security-oauth2/src/main/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProvider.java security-oauth2/src/test/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProviderTest.java src/main/docs/guide/oauth/oauth-endpoints/protectedResourceMetadata.adoc src/main/docs/guide/rejection/wwwAuthenticate.adoc./gradlew :micronaut-security-oauth2:test --tests io.micronaut.security.oauth2.metadata.ResourceMetadataWwwAuthenticateChallengeProviderTest --no-daemon --no-build-cache --rerun-tasks(7 tests, 7 successes)PR Assets
Closes #2079
✨ This message was AI-generated using gpt-5