Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions pkg/cmd/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (o *authenticationOptions) grantOptionSet() (s authentication.GrantOptionSe
SkipOpenBrowser: o.SkipOpenBrowser,
BrowserCommand: o.BrowserCommand,
AuthenticationTimeout: time.Duration(o.AuthenticationTimeoutSec) * time.Second,
ConfiguredTimeout: time.Duration(o.AuthenticationTimeoutSec) * time.Second,
LocalServerCertFile: o.LocalServerCertFile,
LocalServerKeyFile: o.LocalServerKeyFile,
OpenURLAfterAuthentication: o.OpenURLAfterAuthentication,
Expand Down
13 changes: 13 additions & 0 deletions pkg/usecases/authentication/authcode/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type BrowserOption struct {
BrowserCommand string
BindAddress []string
AuthenticationTimeout time.Duration
ConfiguredTimeout time.Duration
OpenURLAfterAuthentication string
RedirectURLHostname string
AuthRequestExtraParams map[string]string
Expand All @@ -33,6 +34,7 @@ type Browser struct {

func (u *Browser) Do(ctx context.Context, o *BrowserOption, oidcClient client.Interface) (*oidc.TokenSet, error) {
u.Logger.V(1).Infof("starting the authentication code flow using the browser")

state, err := oidc.NewState()
if err != nil {
return nil, fmt.Errorf("could not generate a state: %w", err)
Expand Down Expand Up @@ -61,8 +63,17 @@ func (u *Browser) Do(ctx context.Context, o *BrowserOption, oidcClient client.In
LocalServerKeyFile: o.LocalServerKeyFile,
}

success := false
ctx, cancel := context.WithTimeout(ctx, o.AuthenticationTimeout)
defer cancel()
defer func() {
if !success {
o.AuthenticationTimeout = o.AuthenticationTimeout * 2
if o.AuthenticationTimeout > 4*time.Hour {
o.AuthenticationTimeout = 4 * time.Hour
}
}
}()
readyChan := make(chan string, 1)
var out *oidc.TokenSet
var eg errgroup.Group
Expand Down Expand Up @@ -91,6 +102,8 @@ func (u *Browser) Do(ctx context.Context, o *BrowserOption, oidcClient client.In
if err := eg.Wait(); err != nil {
return nil, fmt.Errorf("authentication error: %w", err)
}
success = true
o.AuthenticationTimeout = o.ConfiguredTimeout
u.Logger.V(1).Infof("finished the authorization code flow via the browser")
return out, nil
}
Expand Down