Skip to content

Commit

Permalink
fix: respect retry in token introspection (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
hefekranz authored Apr 16, 2020
1 parent a0f0267 commit 88f7b69
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions pipeline/authn/authenticator_oauth2_introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,41 +172,39 @@ func (a *AuthenticatorOAuth2Introspection) Config(config json.RawMessage) (*Auth
return nil, NewErrAuthenticatorMisconfigured(a, err)
}

var rt http.RoundTripper

if c.PreAuth != nil && c.PreAuth.Enabled {
if c.Retry == nil {
c.Retry = &AuthenticatorOAuth2IntrospectionRetryConfiguration{Timeout: "500ms", MaxWait: "1s"}
} else {
if c.Retry.Timeout == "" {
c.Retry.Timeout = "500ms"
}
if c.Retry.MaxWait == "" {
c.Retry.MaxWait = "1s"
}
}
duration, err := time.ParseDuration(c.Retry.Timeout)
if err != nil {
return nil, err
rt = (&clientcredentials.Config{
ClientID: c.PreAuth.ClientID,
ClientSecret: c.PreAuth.ClientSecret,
Scopes: c.PreAuth.Scope,
TokenURL: c.PreAuth.TokenURL,
}).Client(context.Background()).Transport
}

if c.Retry == nil {
c.Retry = &AuthenticatorOAuth2IntrospectionRetryConfiguration{Timeout: "500ms", MaxWait: "1s"}
} else {
if c.Retry.Timeout == "" {
c.Retry.Timeout = "500ms"
}
timeout := time.Millisecond * duration

maxWait, err := time.ParseDuration(c.Retry.MaxWait)
if err != nil {
return nil, err
if c.Retry.MaxWait == "" {
c.Retry.MaxWait = "1s"
}
}
duration, err := time.ParseDuration(c.Retry.Timeout)
if err != nil {
return nil, err
}
timeout := time.Millisecond * duration

a.client = httpx.NewResilientClientLatencyToleranceConfigurable(
(&clientcredentials.Config{
ClientID: c.PreAuth.ClientID,
ClientSecret: c.PreAuth.ClientSecret,
Scopes: c.PreAuth.Scope,
TokenURL: c.PreAuth.TokenURL,
}).
Client(context.Background()).
Transport,
timeout,
maxWait,
)
maxWait, err := time.ParseDuration(c.Retry.MaxWait)
if err != nil {
return nil, err
}

a.client = httpx.NewResilientClientLatencyToleranceConfigurable(rt, timeout, maxWait)

return &c, nil
}

0 comments on commit 88f7b69

Please sign in to comment.