Why integrate authentication?
Revstack’s auth integration bridges your identity provider with your billing infrastructure. When you verify JWTs at the API layer, you can:- Authorize billing operations based on authenticated user sessions
- Link subscriptions and entitlements to verified user IDs
- Track usage by authenticated users
- Prevent unauthorized access to billing data and operations
@revstackhq/auth package provides a unified interface for JWT verification across multiple providers.
How JWT verification works
Revstack uses the industry-standard jose library to verify JSON Web Tokens. The verification process depends on the signing strategy:RS256 (Asymmetric)
Most modern identity providers use RS256 with JWKS (JSON Web Key Set):- Your identity provider signs tokens with a private key
- They publish the public keys at a JWKS endpoint
- Revstack fetches and caches these public keys
- Incoming tokens are verified against the cached keys
- The
issuerandaudienceclaims are validated
HS256 (Symmetric)
Some providers support shared secret verification:- Your identity provider signs tokens with a shared secret
- You configure the same secret in your Revstack auth contract
- Incoming tokens are verified using the shared secret
- The
issuerandaudienceclaims are validated (if configured)
Quick example
Here’s how to set up auth verification with Clerk:Auth contract
ThebuildAuthContract function creates a RevstackAuthContract that contains:
- Provider slug - Which identity provider is being used
- Strategy -
RS256orHS256 - JWKS URI - Remote public key endpoint (RS256 only)
- Signing secret - Shared secret (HS256 only)
- Issuer - Expected
issclaim in the JWT - Audience - Expected
audclaim (optional) - User ID claim - Which claim contains the user ID (defaults to
sub)
RevstackAuth API regardless of the underlying provider.
Session response
Every call toauth.validate() returns a RevstackSession object:
isValidistrueuserIdcontains the extracted user identifierclaimscontains the full decoded JWT payload
isValidisfalseerrorcontains a human-readable messageerrorCodeis one of:TOKEN_EXPIRED,INVALID_SIGNATURE,ISSUER_MISMATCH,NETWORK_ERROR,MISSING_CLAIM,INVALID_FORMAT, orUNKNOWN_ERROR
Error handling
Handle specific error cases to provide better user experience:Performance considerations
JWKS caching
For RS256 verification, Revstack caches the remote JWKS to minimize network requests. You can configure the cache behavior:Contract reuse
Build your auth contract once at startup and reuse theRevstackAuth instance across requests:
Next steps
Choose your identity provider to see specific integration examples:Auth0
Enterprise identity with OIDC and JWKS
Clerk
Modern auth and user management
Supabase
Open-source auth with RS256 or HS256
Cognito
AWS-managed user pools
Firebase
Google’s authentication service