-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix OAuth2 JWT Bearer parameter duplication in on-behalf-of flow #47677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix OAuth2 JWT Bearer parameter duplication in on-behalf-of flow #47677
Conversation
…f-of flow Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
|
@copilot How about keep the delegation, and replace |
Using
When Spring Security composes these converters using The current fix (removing delegation) ensures we only add Azure-specific parameters, while Spring Security's default converter handles the standard OAuth2 parameters once. This prevents the duplication at the composition level. |
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
rujche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please change target branch to main branch.
will use another PR to avoid changes from other files |
Problem
When using Azure AD on-behalf-of flow with Spring Security 7.x, the
grant_typeparameter gets duplicated in token requests, causingAADSTS70003: unsupported_grant_type 'urn:ietf:params:oauth:grant-type:jwt-bearer,urn:ietf:params:oauth:grant-type:jwt-bearer'.Root cause:
AadJwtBearerGrantRequestParametersConverterdelegated toDefaultOAuth2TokenRequestParametersConverter, which already addsgrant_type. WhenRestClientJwtBearerTokenResponseClient.addParametersConverter()composes converters viaMultiValueMap.addAll(), it appends rather than replaces, creating duplicate entries.Changes
AadJwtBearerGrantRequestParametersConverter: Removed delegation toDefaultOAuth2TokenRequestParametersConverter. Now returns only the Azure-specificrequested_token_use=on_behalf_ofparameter, letting Spring Security's default converter handle standard OAuth2 parameters.Test coverage: Added assertions verifying the converter adds only the Azure-specific parameter without duplicating standard OAuth2 parameters.
Before:
After:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.