implemented access token refreshing - untested

This commit is contained in:
2026-01-04 21:34:24 -07:00
parent e36c759dc2
commit 8ccc795812
5 changed files with 221 additions and 23 deletions
+36
View File
@@ -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
}