Skip to main content

Overview

SuperTokens Core provides a complete JWT infrastructure with RSA key pair generation, automatic key rotation, JWKS endpoint, and utilities for creating and signing custom JWTs.

Features

RS256 Signing

RSA with SHA-256 for secure JWT signing

Key Rotation

Automatic key rotation with configurable intervals

JWKS Endpoint

Standard JWKS endpoint for public key distribution

Custom Claims

Add any custom claims to your JWTs

Dynamic & Static Keys

Choose between rotating or fixed keys

Multi-Tenant

Separate keys per app for tenant isolation

Creating JWTs

From io/supertokens/jwt/JWTSigningFunctions.java:84-112:

Example: Create Custom JWT

JWT Structure

The created JWT has three parts: Header:
Payload:
Signature:
The kid (key ID) in the header is crucial for verification. It tells verifiers which public key to use from the JWKS endpoint.

JWT Creation with Custom Headers

From io/supertokens/jwt/JWTSigningFunctions.java:114-147:

Example: JWT with Custom Headers

Signing Keys

Key Types

Rotating keys for enhanced security:
  • Automatically rotate at configured intervals
  • Used for access tokens by default
  • Old keys remain valid during transition
  • Better security through key rotation

Key Structure

Asymmetric Key Info

Key Rotation

Configuration

number
default:"168"
Hours between dynamic key rotations (default: 7 days)
number
default:"168"
Alias for access_token_signing_key_update_interval

Rotation Process

1

Generate New Key

Create new RSA-2048 key pair
2

Store in Database

Save with unique key ID and timestamp
3

Start Using

New JWTs signed with new key
4

Transition Period

Old keys remain for verification during token lifetime
5

Cleanup

Remove keys older than configured retention

JWKS Endpoint

SuperTokens exposes a JWKS (JSON Web Key Set) endpoint for public key distribution:

JWKS Response Format

Key Fields

string
Key type, always “RSA” for SuperTokens
string
Key ID matching the kid in JWT headers
string
RSA modulus (base64url-encoded)
string
RSA public exponent (base64url-encoded)
string
Algorithm, always “RS256”
string
Key use, always “sig” (signature)

Verifying JWTs

Using JWKS Endpoint

Java Verification

Multi-Tenancy Support

Keys are app-level, not tenant-level:
Different apps have different signing keys, providing isolation between apps in the same SuperTokens instance.

Use Cases

API Authentication Tokens

Webhook Signatures

Service-to-Service Authentication

Best Practices

Use Short Expiry

Keep JWT validity short (minutes to hours, not days)

Include Minimal Claims

Only include necessary data in payload

Dynamic Keys for Security

Use rotating keys for enhanced security

Static Keys for Persistence

Use static keys for long-lived tokens

Validate on Receipt

Always verify signature, expiry, and issuer

Cache JWKS

Cache public keys to reduce JWKS endpoint calls

Security Considerations

Never include sensitive data in JWTs:
  • Passwords or password hashes
  • API keys or secrets
  • Personal identifiable information (PII) unless necessary
  • Credit card information
JWTs are signed but not encrypted - the payload is readable by anyone.

Signature Verification

Always verify:
  1. Signature: Using public key from JWKS
  2. Expiry (exp claim)
  3. Issued At (iat claim)
  4. Issuer (iss claim)
  5. Audience (aud claim, if used)

Key Management

  • Store private keys securely
  • Rotate dynamic keys regularly
  • Monitor for compromised keys
  • Have key rotation plan for emergencies