Skip to content

Commit

Permalink
Ask to renew token that receives 401 (#166)
Browse files Browse the repository at this point in the history
* if token has no access - create a new one

* update logs

---------

Co-authored-by: Dean Oren <[email protected]>
  • Loading branch information
do87 and Dean Oren authored Apr 11, 2023
1 parent b9825fa commit f2a76fa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/clients/key_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ func (c *KeyFlow) Do(req *http.Request) (*http.Response, error) {
func (c *KeyFlow) GetAccessToken() (string, error) {
accessTokenIsValid, err := c.validateToken(c.token.AccessToken)
if err != nil {
return "", errors.Wrap(err, "failed initial validation")
return "", errors.Wrap(err, "failed to validate existing keyflow token")
}
if accessTokenIsValid {
return c.token.AccessToken, nil
}
if err := c.recreateAccessToken(); err != nil {
return "", errors.Wrap(err, "failed during token recreation")
return "", errors.Wrap(err, "failed to recreate keyflow token")
}
return c.token.AccessToken, nil
}
Expand Down Expand Up @@ -378,6 +378,9 @@ func (c *KeyFlow) validateToken(token string) (bool, error) {
return false, nil
}
if _, err := c.parseToken(token); err != nil {
if strings.Contains(err.Error(), "401") {
return false, nil
}
return false, err
}
return true, nil
Expand Down

0 comments on commit f2a76fa

Please sign in to comment.