mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-08-28 12:02:35 +00:00
fix(security): DatabaseAuthenticator.RefreshToken surfaces rotated refresh token and expiry
Tests / Unit Tests (push) Failing after 13s
Tests / Integration Tests (push) Failing after 27s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 33s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 35s
Build , Vet Test, and Lint / Build (push) Successful in 35s
Build , Vet Test, and Lint / Lint Code (push) Successful in 39s
Tests / Unit Tests (push) Failing after 13s
Tests / Integration Tests (push) Failing after 27s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 33s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 35s
Build , Vet Test, and Lint / Build (push) Successful in 35s
Build , Vet Test, and Lint / Lint Code (push) Successful in 39s
RefreshToken() hardcoded LoginResponse{Token: userCtx.SessionID, ExpiresIn: 24h}
and silently discarded anything else resolvespec_refresh_token returned. An
implementation that issues its own independent, rotating refresh token (not
just reusing the session/access token as its own refresh token) has nowhere
else to put the new refresh token and real access-token expiry than
UserContext.Claims, since UserContext has no dedicated fields for either.
Now reads claims.refresh_token/claims.expires_in when present and surfaces
them into LoginResponse.RefreshToken/ExpiresIn. Implementations that don't
set these claims keep today's behavior unchanged (empty RefreshToken, 24h
ExpiresIn default) — purely additive, no breaking change.
This commit is contained in:
@@ -551,11 +551,27 @@ func (a *DatabaseAuthenticator) RefreshToken(ctx context.Context, refreshToken s
|
||||
return nil, fmt.Errorf("failed to parse user context: %w", err)
|
||||
}
|
||||
|
||||
return &LoginResponse{
|
||||
// A resolvespec_refresh_token implementation that issues its own rotating
|
||||
// refresh token (independent of the access/session token) returns it
|
||||
// under claims.refresh_token, since UserContext has no dedicated field
|
||||
// for it. Surface that into LoginResponse.RefreshToken so callers don't
|
||||
// need to reach into User.Claims themselves. claims.expires_in
|
||||
// (seconds) similarly overrides the default access-token ExpiresIn when
|
||||
// the procedure provides a real value. Implementations that don't set
|
||||
// these claims keep today's behavior unchanged (empty RefreshToken,
|
||||
// 24h ExpiresIn default).
|
||||
resp := &LoginResponse{
|
||||
Token: userCtx.SessionID, // New session token from stored procedure
|
||||
User: &userCtx,
|
||||
ExpiresIn: int64(24 * time.Hour.Seconds()),
|
||||
}, nil
|
||||
}
|
||||
if refreshToken, ok := userCtx.Claims["refresh_token"].(string); ok && refreshToken != "" {
|
||||
resp.RefreshToken = refreshToken
|
||||
}
|
||||
if expiresIn, ok := userCtx.Claims["expires_in"].(float64); ok && expiresIn > 0 {
|
||||
resp.ExpiresIn = int64(expiresIn)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// JWTAuthenticator provides JWT token-based authentication
|
||||
|
||||
Reference in New Issue
Block a user