Skip to content

Commit c0eace7

Browse files
committed
feat: support allow_expired query parameter for JWT validation
1 parent f409d11 commit c0eace7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal/api/auth.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,22 @@ func (a *API) parseJWTClaims(bearer string, r *http.Request) (context.Context, e
7474
ctx := r.Context()
7575
config := a.config
7676

77-
p := jwt.NewParser(jwt.WithValidMethods(config.JWT.ValidMethods))
77+
// Check if allow_expired query parameter is set
78+
allowExpired := r.URL.Query().Get("allow_expired") == "true"
79+
80+
// Configure JWT parser based on allowExpired flag
81+
var p *jwt.Parser
82+
if allowExpired {
83+
// Skip claims validation (including exp check) when explicitly requested
84+
p = jwt.NewParser(
85+
jwt.WithValidMethods(config.JWT.ValidMethods),
86+
jwt.WithoutClaimsValidation(),
87+
)
88+
} else {
89+
// Default behavior: validate all claims including expiration
90+
p = jwt.NewParser(jwt.WithValidMethods(config.JWT.ValidMethods))
91+
}
92+
7893
token, err := p.ParseWithClaims(bearer, &AccessTokenClaims{}, func(token *jwt.Token) (interface{}, error) {
7994
if kid, ok := token.Header["kid"]; ok {
8095
if kidStr, ok := kid.(string); ok {

0 commit comments

Comments
 (0)