Skip to content

Commit c514979

Browse files
authored
feat: add HTTP client option to OAuthConfig (#616)
* feat: add HTTP client option to OAuthConfig It's already possible to customize the underlying client used by the SSE and streamable HTTP transports, but not the OAuth handler. This adds an option to customize the underlying client used by the OAuth handler. * Use conventional comment on HTTPClient
1 parent b77217e commit c514979

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

client/transport/oauth.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type OAuthConfig struct {
3434
AuthServerMetadataURL string
3535
// PKCEEnabled enables PKCE for the OAuth flow (recommended for public clients)
3636
PKCEEnabled bool
37+
// HTTPClient is an optional HTTP client to use for requests.
38+
// If nil, a default HTTP client with a 30 second timeout will be used.
39+
HTTPClient *http.Client
3740
}
3841

3942
// TokenStore is an interface for storing and retrieving OAuth tokens.
@@ -151,10 +154,13 @@ func NewOAuthHandler(config OAuthConfig) *OAuthHandler {
151154
if config.TokenStore == nil {
152155
config.TokenStore = NewMemoryTokenStore()
153156
}
157+
if config.HTTPClient == nil {
158+
config.HTTPClient = &http.Client{Timeout: 30 * time.Second}
159+
}
154160

155161
return &OAuthHandler{
156162
config: config,
157-
httpClient: &http.Client{Timeout: 30 * time.Second},
163+
httpClient: config.HTTPClient,
158164
}
159165
}
160166

0 commit comments

Comments
 (0)