Skip to content

Commit

Permalink
feat: Remove refresh token if token is too big (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
alldoami authored Jan 10, 2025
1 parent 9e957ff commit 23d4604
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion oidc_cli/oidc_impl/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,26 @@ func (c *Cache) refresh(ctx context.Context) (*client.Token, error) {

err = c.storage.Set(ctx, compressedToken)
if err != nil {
return nil, errors.Wrap(err, "Unable to cache the strToken")
if err.Error() == "could not set value to keyring: data passed to Set was too big" {
// TODO: Upgrade keyring library to v0.2.2 to use ErrSetDataTooBig
// if errors.Is(err, keyring.ErrSetDataTooBig) {
logrus.Debug("Token too big, removing refresh token")
strToken, err := token.Marshal(append(c.storage.MarshalOpts(), client.MarshalOptNoRefresh)...)
if err != nil {
return nil, errors.Wrap(err, "unable to marshall token")
}
// gzip encode and save token to storage
compressedToken, err = compressToken(strToken)
if err != nil {
return nil, errors.Wrap(err, "unable to compress token")
}
err = c.storage.Set(ctx, compressedToken)
if err != nil {
return nil, errors.Wrap(err, "Unable to cache the strToken")
}
} else {
return nil, errors.Wrap(err, "Unable to cache the strToken")
}
}

return token, nil
Expand Down

0 comments on commit 23d4604

Please sign in to comment.