-
-
Notifications
You must be signed in to change notification settings - Fork 194
feat(auth): introduce getClaims method to verify and extract JWT claims #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+927
−20
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds JWT claims verification and extraction functionality to the Auth client, porting the feature from auth-js PR #1030. Key changes: - Add Base64URL encoding/decoding utilities - Extend JWT helper to decode full JWT (header, payload, signature) - Add JWK types (JWK, JWKS, JWTHeader, JWTClaims, etc.) - Add JWTVerifier for asymmetric JWT signature verification (ES256) - Implement getClaims method in AuthClient - Add jwtVerificationFailed error to AuthError The getClaims method verifies JWT signatures and returns claims: - For HS256 (symmetric) and RS256 JWTs: validates server-side via getUser - For ES256 JWTs: verifies signature client-side using CryptoKit - Supports custom JWKS or fetches from /.well-known/jwks.json - Caches JWKS to minimize network requests Note: RS256 client-side verification will be added once swift-crypto's RSA API becomes public. Currently falls back to server-side verification. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit applies changes from auth-js PR #1078 to improve getClaims performance and remove its experimental status. Key changes: - Add global JWKS cache shared across all clients with the same storage key - Implement JWKS cache expiry with TTL (10 minutes) - Add GetClaimsOptions struct with allowExpired and custom jwks options - Remove experimental warning from getClaims documentation - Update getClaims to accept options parameter instead of separate jwks param - Add CachedJWKS struct to track cache timestamps - Implement GlobalJWKSCache actor for thread-safe global caching Performance improvements: - Global cache significantly reduces JWKS fetches in serverless environments - Cache TTL prevents stale keys while minimizing network requests - Especially beneficial for AWS Lambda, Cloud Functions, etc. Breaking change: - getClaims now accepts GetClaimsOptions instead of JWKS parameter - Old: getClaims(jwt:jwks:) - New: getClaims(jwt:options:) Migration: ```swift // Before let response = try await client.auth.getClaims(jwks: customJWKS) // After let response = try await client.auth.getClaims( options: GetClaimsOptions(jwks: customJWKS) ) // With allowExpired let response = try await client.auth.getClaims( options: GetClaimsOptions(allowExpired: true) ) ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit applies changes from auth-js PR #1080 to handle key rotation scenarios more gracefully. Key changes: - Change fetchJWK to return optional JWK? instead of throwing errors - Return nil when JWKS is empty or key not found in JWKS - Restructure getClaims logic to try fetching JWK first - Fallback to server-side verification (getUser) if key not found - Handle symmetric algorithms (HS256) and RS256 with nil check Why this matters: When developers rotate keys faster than cache TTL (10 minutes), a JWT may be signed with a key ID that's not yet in the cached JWKS. Instead of failing with an error, the method now gracefully falls back to server-side verification via getUser(). This ensures: - Zero downtime during key rotation - Better resilience against cache staleness - Transparent fallback for users Example scenario: 1. JWKS is cached with key ID "abc123" 2. Admin rotates standby key to active (new key ID "xyz789") 3. User receives JWT signed with "xyz789" 4. fetchJWK returns nil (key not in cache) 5. getClaims automatically falls back to getUser() 6. Verification succeeds server-side 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Pull Request Test Coverage Report for Build 18316862621Details
💛 - Coveralls |
o-santi
approved these changes
Oct 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR ports the
getClaims
feature from auth-js#1030 and follow-up improvements from auth-js#1078 and auth-js#1080 to supabase-swift. ThegetClaims
method allows developers to verify and extract claims from JWTs with significant performance improvements through global caching and graceful key rotation handling.What changed
New Types
allowExpired
and customjwks
parametersNew Files
Modified Files
getClaims(jwt:options:)
method for JWT verificationfetchJWK(kid:jwks:)
private method with cache expiry checkingjwtVerificationFailed
error casedecode(_:)
method to return full JWT structureHow it works
The
getClaims
method provides flexible JWT verification with performance optimizations:getUser()
API callUsage Example
Related
getClaims()
non experimental, add global cache auth-js#1078getUser()
if thekid
of the JWT is not found auth-js#1080🤖 Generated with Claude Code