implemented access token refreshing - untested
This commit is contained in:
@@ -113,3 +113,39 @@ func (a *Authenticator) GetAccessTokenClaimsAndExpiration(ctx context.Context, a
|
||||
|
||||
return claims, r.Expiry, nil
|
||||
}
|
||||
|
||||
func (a *Authenticator) getRefreshTokenForAccessToken(ctx context.Context, accessToken string) (refreshToken, tokenType string, err error) {
|
||||
rows, err := a.db.Query(
|
||||
ctx,
|
||||
`
|
||||
SELECT
|
||||
refresh_token,
|
||||
token_type
|
||||
FROM
|
||||
oauth_tokens
|
||||
WHERE
|
||||
access_token = @access_token
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"access_token": accessToken,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
type Row struct {
|
||||
Refresh_token string
|
||||
Token_type string
|
||||
}
|
||||
|
||||
r, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByNameLax[Row])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return "", "", consts.ErrNotFound
|
||||
}
|
||||
return "", "", fmt.Errorf("failed to scan row: %w", err)
|
||||
}
|
||||
|
||||
return r.Refresh_token, r.Token_type, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user