fix: use raw Basic auth for custom OIDC/OAuth token exchange#2631
Open
rohanpatel2002 wants to merge 1 commit into
Open
fix: use raw Basic auth for custom OIDC/OAuth token exchange#2631rohanpatel2002 wants to merge 1 commit into
rohanpatel2002 wants to merge 1 commit into
Conversation
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Custom OIDC / OAuth2 providers exchange the authorization code via
oauth2.Config.Exchangewithout settingEndpoint.AuthStyle. In that casegolang.org/x/oauth2uses auto-detect:Authorization: Basicwithurl.QueryEscape(client_id)/url.QueryEscape(client_secret)client_secret_post(credentials in the body)Providers that expect a raw client secret in Basic auth (for example Epic Games, same as
curl -u) reject Attempt 1 when the secret contains characters thatQueryEscaperewrites (+,/,=, …). Attempt 2 then fails because those providers require an Authorization header. Callers only see the Attempt-2 error (e.g. “Authorization header may be invalid or not present”), which hides the realinvalid_client_credentialsfailure.Fixes #2623
What is the new behavior?
For Custom OIDC and Custom OAuth2 providers:
AuthStyleInHeader(no auto-detect / second attempt).QueryEscape).AuthCodeOptions still go throughExchangeas before.Unit tests assert a single token request, raw credentials on the wire for secrets containing
+/ =, and that the first provider error is surfaced.Additional context
This follows RFC 7617-style Basic auth (
curl -u) rather than the library’s QueryEscape-in-header behavior, which is a known footgun for several IdPs. Built-in providers (Google, etc.) are unchanged. Happy to adjust if maintainers prefer an opt-in config flag instead of the default for custom providers. Thank you for reviewing.