fix(oauth): use dict list value for multi-resource RFC 8707 token requests#5078
Open
pjaroliya wants to merge 1 commit into
Open
fix(oauth): use dict list value for multi-resource RFC 8707 token requests#5078pjaroliya wants to merge 1 commit into
pjaroliya wants to merge 1 commit into
Conversation
…uests When oauth_config["resource"] is a list (e.g. learned from a JWT aud claim with multiple audiences), the token exchange and refresh code converted token_data from a dict into a list[tuple[str, str]] to carry multiple resource= parameters. httpx only invokes encode_urlencoded_data() — which produces a ByteStream compatible with AsyncClient — when data= is a Mapping. A list of tuples is not a Mapping, so httpx falls through to encode_content(), which wraps the list in an IteratorByteStream (SyncByteStream only). AsyncClient then raises: RuntimeError: Attempted to send an sync request with an AsyncClient instance. This error surfaces as "Unexpected Error" on the OAuth callback page and affects every authorization attempt after the first one succeeds (because _persist_learned_audience() stores the JWT aud list into oauth_config). Fix: keep token_data as a dict and store the resource list directly as its value. httpx's encode_urlencoded_data() already expands list values into repeated key=value pairs, producing the correct resource=r1&resource=r2 encoding with a ByteStream that AsyncClient accepts. Affects _exchange_code_for_tokens() and refresh_token() in OAuthManager. Closes #XXXX Signed-off-by: pjaroliya <pjaroliya@webmd.net> Signed-off-by: pjaroliya <pjaroliya@pulsepoint.com>
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.
When oauth_config["resource"] is a list (e.g. learned from a JWT aud claim with multiple audiences), the token exchange and refresh code converted token_data from a dict into a list[tuple[str, str]] to carry multiple resource= parameters.
httpx only invokes encode_urlencoded_data() — which produces a ByteStream compatible with AsyncClient — when data= is a Mapping. A list of tuples is not a Mapping, so httpx falls through to encode_content(), which wraps the list in an IteratorByteStream (SyncByteStream only). AsyncClient then raises:
RuntimeError: Attempted to send an sync request with an AsyncClient instance.
This error surfaces as "Unexpected Error" on the OAuth callback page and affects every authorization attempt after the first one succeeds (because _persist_learned_audience() stores the JWT aud list into oauth_config).
Fix: keep token_data as a dict and store the resource list directly as its value. httpx's encode_urlencoded_data() already expands list values into repeated key=value pairs, producing the correct
resource=r1&resource=r2 encoding with a ByteStream that AsyncClient accepts.
Affects _exchange_code_for_tokens() and refresh_token() in OAuthManager.
Closes #XXXX
🔗 Related Issue
Closes #
📝 Summary
What does this PR do and why?
🏷️ Type of Change
🧪 Verification
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes (optional)
Screenshots, design decisions, or additional context.