fix: a_exchange_token sends None values as empty strings in form-encoded body, causing Keycloak invalid_issuer error#709
Open
adriagarp wants to merge 1 commit intomarcospereirampj:masterfrom
Conversation
cb5d6ba to
c931e16
Compare
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 my team we found out while migrating from sync to async that the async
a_exchange_tokenmethod fails withKeycloakPostError: 400: b'{"error":"invalid_issuer", "error_description": "Invalid subject_issuer parameter"}'while the syncexchange_tokenworks correctly with identical arguments.The root cause is that both
exchange_tokenanda_exchange_tokenbuild the same payload dict, which includes keys withNonevalues for optional parameters that weren't provided (e.g.subject_issuer,requested_issuer,requested_subject).The sync path uses
requests, which silently drops keys withNonevalues from form-encoded bodies:The async path uses
httpx, which serializesNoneas empty strings.This was already identified for query parameters (
ConnectionManager._filter_query_paramsalready addresses this). The proposed fix renames that method to_filter_none_valuesand makes it a@classmethodso that it can be reused from_prepare_httpx_request_content(which is now also a@classmethod).How to reproduce:
Tested with: