Skip to content

Fix: apply DialContextFunc to OAuth2 token-fetch transport#911

Open
yuri-tceretian wants to merge 1 commit into
prometheus:mainfrom
yuri-tceretian:fix/oauth2-token-transport-dialcontextfunc
Open

Fix: apply DialContextFunc to OAuth2 token-fetch transport#911
yuri-tceretian wants to merge 1 commit into
prometheus:mainfrom
yuri-tceretian:fix/oauth2-token-transport-dialcontextfunc

Conversation

@yuri-tceretian
Copy link
Copy Markdown

Problem

function newOauth2TokenSource builds its own http.Transport to fetch tokens but doesn't set DialContext on it. Any DialContextFunc passed via WithDialContextFunc is applied to the main request transport but silently skipped for the token endpoint.

Solution

The fix is a one-liner - set DialContext on the token transport the same way it's set on the main one. When dialContextFunc is nil the behaviour is unchanged since http.Transport falls back to its default dialer.

newOauth2TokenSource builds its own http.Transport to fetch tokens but
doesn't set DialContext on it. Any DialContextFunc passed via
WithDialContextFunc is applied to the main request transport but silently
skipped for the token endpoint.

Set DialContext on the token transport the same way it is set on the main
one. When dialContextFunc is nil the behaviour is unchanged since
http.Transport falls back to its default dialer.

Added TestOAuth2DialContextFunc to verify that WithDialContextFunc blocks
the token endpoint fetch, not only the final request.

Signed-off-by: Yuri Tseretyan <[email protected]>
@yuri-tceretian yuri-tceretian force-pushed the fix/oauth2-token-transport-dialcontextfunc branch from 3fb131c to 7a5a530 Compare May 27, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant