Closed
Fix on_behalf_of grant_type duplication in Spring Security 6.5+#47667
Conversation
This commit fixes the issue where the grant_type parameter was being duplicated in the on_behalf_of token request. The problem occurred when multiple converters were chained using addParametersConverter(), which uses MultiValueMap.addAll() that appends values to existing keys instead of replacing them. The fix reimplements createParameters() in AadJwtBearerGrantRequestEntityConverter to: 1. Use parameters.set() instead of parameters.add() to ensure single values 2. Directly create all parameters without calling the deprecated super.createParameters() 3. Follow the pattern used by Spring Security 6.4+ DefaultOAuth2TokenRequestParametersConverter This ensures that when additional converters are added via addParametersConverter(), the grant_type remains a single value instead of being converted into a list. Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Updated the implementation to properly handle both CLIENT_SECRET_BASIC and CLIENT_SECRET_POST authentication methods, following Spring Security 6.4+ DefaultOAuth2TokenRequestParametersConverter pattern: - CLIENT_SECRET_BASIC: credentials sent in Authorization header (NOT in parameters) - CLIENT_SECRET_POST: credentials sent in POST body parameters - Other methods: only client_id in parameters Added test to verify CLIENT_SECRET_BASIC authentication method works correctly. Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Simplified test code by using Instant.now() directly instead of unnecessary conversions. Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
- Fixed Instant usage in noGrantTypeDuplicationWithMultipleConverters test - Improved comments to clarify client authentication method handling Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
- Fixed typo: 'identify' → 'identity' - Improved test assertion message to show count instead of full list Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix incorrect token payload merging with on behalf of grant type
Fix on_behalf_of grant_type duplication in Spring Security 6.5+
Jan 9, 2026
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.
In Spring Security 6.5+, chaining parameter converters via
addParametersConverter()causesgrant_typeto duplicate as a list[jwt-bearer, jwt-bearer]instead of remaining a single value, triggeringAADSTS70003: unsupported grant type.Root cause:
addParametersConverter()usesMultiValueMap.addAll()which appends to existing keys. When the deprecatedsuper.createParameters()usesparameters.add()and a chained converter also adds the same key, values accumulate into a list.Changes
createParameters()to useparameters.set()throughout, ensuring single valuessuper.createParameters()call to avoid inheritance from deprecated implementation usingadd()DefaultOAuth2TokenRequestParametersConverterCLIENT_SECRET_BASIC: credentials in Authorization header onlyCLIENT_SECRET_POST: credentials in POST body parametersclient_idin parameters onlyBefore
After
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.