mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-05 10:58:11 +02:00
zero/api: reset token and url cache if 401 is received (#5256)
zero/api: reset token cache if 401 is received
This commit is contained in:
parent
a04d1a450c
commit
ce12e51cf5
8 changed files with 91 additions and 32 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
"github.com/pomerium/pomerium/internal/zero/apierror"
|
||||
"github.com/pomerium/pomerium/internal/zero/token"
|
||||
)
|
||||
|
@ -20,7 +21,7 @@ func NewTokenFetcher(endpoint string, opts ...ClientOption) (token.Fetcher, erro
|
|||
return func(ctx context.Context, refreshToken string) (*token.Token, error) {
|
||||
now := time.Now()
|
||||
|
||||
resp, err := apierror.CheckResponse[ExchangeTokenResponse](client.ExchangeClusterIdentityTokenWithResponse(ctx, ExchangeTokenRequest{
|
||||
resp, err := apierror.CheckResponse(client.ExchangeClusterIdentityTokenWithResponse(ctx, ExchangeTokenRequest{
|
||||
RefreshToken: refreshToken,
|
||||
}))
|
||||
if err != nil {
|
||||
|
@ -32,9 +33,11 @@ func NewTokenFetcher(endpoint string, opts ...ClientOption) (token.Fetcher, erro
|
|||
return nil, fmt.Errorf("error parsing expires in: %w", err)
|
||||
}
|
||||
|
||||
expires := now.Add(time.Duration(expiresSeconds) * time.Second)
|
||||
log.Ctx(ctx).Debug().Time("expires", expires).Msg("fetched new Bearer token")
|
||||
return &token.Token{
|
||||
Bearer: resp.IdToken,
|
||||
Expires: now.Add(time.Duration(expiresSeconds) * time.Second),
|
||||
Expires: expires,
|
||||
}, nil
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue