pr changes

This commit is contained in:
jay brown
2025-04-18 12:29:02 -07:00
parent 9562b9239d
commit 11942d6756
2 changed files with 10 additions and 3 deletions
+7 -2
View File
@@ -10,6 +10,11 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)
const (
JWKS_CACHE_TTL = 24 * time.Hour
JWKS_CLIENT_TIMEOUT = 10 * time.Second
)
// GetJWKS returns the cached JWKS or fetches a new one if needed
// This function implements caching logic to minimize external requests
// Used during token validation to get the key set for signature verification
@@ -45,7 +50,7 @@ func GetJWKS(jwksURL string, logger *slog.Logger) (jwk.Set, error) {
jwksCache.KeySet = keySet
// Cache for 24 hours - you can adjust this based on your needs
jwksCache.ExpiresAt = time.Now().Add(24 * time.Hour)
jwksCache.ExpiresAt = time.Now().Add(JWKS_CACHE_TTL)
return keySet, nil
}
@@ -54,7 +59,7 @@ func GetJWKS(jwksURL string, logger *slog.Logger) (jwk.Set, error) {
// Used to get the public keys needed to verify token signatures
// Makes an HTTP request to the JWKS URL and returns the raw JSON
func fetchJWKS(jwksURL string) (string, error) {
client := &http.Client{Timeout: 10 * time.Second}
client := &http.Client{Timeout: JWKS_CLIENT_TIMEOUT}
req, err := http.NewRequest("GET", jwksURL, nil)
if err != nil {
return "", err
+3 -1
View File
@@ -16,6 +16,8 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt"
)
const PKCE_SESSION_TTL = 5 * time.Minute
// verifyToken verifies the JWT token and returns its claims
// Used during both OAuth callback and subsequent API requests with bearer token
// Verifies signature, expiration, issuer, and other JWT claims
@@ -104,7 +106,7 @@ func storePKCESession(state, codeVerifier string, logger *slog.Logger) {
session := &PKCESession{
CodeVerifier: codeVerifier,
CreatedAt: time.Now(),
ExpiresAt: time.Now().Add(5 * time.Minute),
ExpiresAt: time.Now().Add(PKCE_SESSION_TTL),
}
pkceSessionMap.sessions[state] = session