Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inform user to re-login when cached token is stale after multiple attempts #241

Closed
Closed
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
15 changes: 13 additions & 2 deletions cmd/root/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ func NewWebCommand() *cobra.Command {
return err
}

var apiErr *okta.APIError

for attempt := 1; attempt <= 2; attempt++ {
wsa, err := webssoauth.NewWebSSOAuthentication(cfg)
if err != nil {
return err
}

var ok bool
err = wsa.EstablishIAMCredentials()
if apiErr, ok := err.(*okta.APIError); ok {
apiErr, ok = err.(*okta.APIError)
if ok {
if apiErr.ErrorType == "invalid_grant" && webssoauth.RemoveCachedAccessToken() {
webssoauth.ConsolePrint(cfg, "Cached access token appears to be stale, removing token and retrying device authorization ...\n\n")
continue
Expand All @@ -119,7 +123,14 @@ func NewWebCommand() *cobra.Command {
break
}

return err
if err != nil {
if apiErr != nil && apiErr.ErrorType == "invalid_grant" {
webssoauth.ConsolePrint(cfg, "Authentication failed after multiple attempts. Please log out of Okta in your browser and log back in to resolve the issue.\n")
}
return err
}

return nil
},
}

Expand Down