Skip to content

Commit

Permalink
Merge pull request #256 from okta/Eitol_PR_241
Browse files Browse the repository at this point in the history
Handle Okta authentication failures more gracefully
  • Loading branch information
monde authored Jan 3, 2025
2 parents 84e90f9 + 4368efd commit 7ebb432
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit 7ebb432

Please sign in to comment.