Skip to content

Apply WithTransport and WithClientTimeout to token clients - #655

Open
adityasingh2400 wants to merge 1 commit into
palantir:developfrom
adityasingh2400:fix/token-client-transport
Open

adityasingh2400 wants to merge 1 commit into
palantir:developfrom
adityasingh2400:fix/token-client-transport

Conversation

@adityasingh2400

Copy link
Copy Markdown

Before this PR

NewTokenSourceClient and NewTokenSourceV4Client (and so NewTokenClient and NewTokenV4Client) build their HTTP client with oauth2.NewClient(context.Background(), ts). With no client in the context, oauth2 uses http.DefaultClient, so token clients always use http.DefaultTransport and have no timeout.

WithTransport and WithClientTimeout therefore only take effect for application and installation clients, although the README describes the timeout as applying to "requests made by all clients". An app that sets a transport for custom TLS or a proxy gets token clients that bypass it, and an app that sets a timeout gets token clients that can wait indefinitely.

After this PR

==COMMIT_MSG==
Token clients now use the transport from WithTransport and the timeout from WithClientTimeout, like application and installation clients. Previously they always used http.DefaultTransport with no timeout.
==COMMIT_MSG==

The helper passes newHTTPClient() to oauth2.NewClient through the oauth2.HTTPClient context key, and oauth2 copies its transport and timeout. The new test fails on develop (timeout is 0s and no request reaches the configured transport).

Possible downsides?

Token client requests now go through the configured transport and fail when they exceed the configured timeout. That matches how the options are documented, but an app that relied on token clients ignoring them would see a change.

Token clients were built with oauth2.NewClient(context.Background(), ts).
With no HTTP client in the context, oauth2 falls back to
http.DefaultClient, so the clients from NewTokenClient,
NewTokenSourceClient and their v4 variants used http.DefaultTransport
and had no timeout, whatever was passed to WithTransport and
WithClientTimeout. Application and installation clients already honor
both options.

Give oauth2.NewClient the same base client the other clients use.
@changelog-app

changelog-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Token clients now use the transport from WithTransport and the timeout from WithClientTimeout, like application and installation clients. Previously they always used http.DefaultTransport with no timeout.

Check the box to generate changelog(s)

  • Generate changelog entry

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