Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions client/transport/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,34 @@ type OAuthHandler struct {
expectedState string // Expected state value for CSRF protection
}

// NewOAuthHandler creates a new OAuth handler
func NewOAuthHandler(config OAuthConfig) *OAuthHandler {
type OAuthHandlerOption func(*OAuthHandler)

// WithOAuthHTTPClient allows setting a custom http.Client for the OAuthHandler.
func WithOAuthHTTPClient(client *http.Client) OAuthHandlerOption {
return func(h *OAuthHandler) {
if client != nil {
h.httpClient = client
}
}
}

// NewOAuthHandler creates a new OAuth handler.
// Optionally accepts functional options such as WithOAuthHTTPClient.
func NewOAuthHandler(config OAuthConfig, opts ...OAuthHandlerOption) *OAuthHandler {
if config.TokenStore == nil {
config.TokenStore = NewMemoryTokenStore()
}

return &OAuthHandler{
handler := &OAuthHandler{
config: config,
httpClient: &http.Client{Timeout: 30 * time.Second},
}

for _, opt := range opts {
opt(handler)
}

return handler
}

// GetAuthorizationHeader returns the Authorization header value for a request
Expand Down
Loading