Prerequisites
- A Better Auth instance deployed and running
- The OIDC Provider and JWT plugins configured
- Access to the Char dashboard
Quick Links
Better Auth Docs
Official Better Auth documentation
OIDC Provider Plugin
Configure Better Auth as an OIDC provider
JWT Plugin
JWT token configuration and JWKS
GitHub
Better Auth source code
Installation Guide
Get started with Better Auth
Framework Integrations
React, Next.js, Vue, Svelte, and more
SDK References
better-auth
Better Auth core package
React Integration
React hooks and components
Next.js Integration
Next.js App Router and Pages
Vue Integration
Vue 3 composables
Svelte Integration
SvelteKit integration
All Plugins
OAuth, 2FA, Organizations, and more
Configuration Steps
Install Better Auth
Install the Better Auth package in your application. See the installation guide for details.Configure your environment variables:
Configure OIDC Provider and JWT Plugins
Set up Better Auth as an OIDC provider with JWT support for JWKS-based token validation:
Configure Char
In the Char Dashboard:
- Navigate to Settings → Integration
- Under SSO Configuration, select Custom OIDC as the provider
- Enter your Issuer URL (your Better Auth base URL, e.g.,
https://auth.yourapp.com) - Enter your Client ID (the
clientIdfrom your trusted client config) - Click Test Connection to verify
- Click Save Changes
Configuration Reference
| Char Field | Better Auth Value | Example |
|---|---|---|
| Provider Type | Custom OIDC | oidc |
| Issuer URL | Your Better Auth base URL | https://auth.yourapp.com |
| Client ID | Trusted client ID | your-app-client-id |
Better Auth exposes the JWKS endpoint at
/api/auth/jwks by default. The discovery document is available at /.well-known/openid-configuration when using the OIDC Provider plugin.Using Upstream Identity Providers
If you’re using Better Auth with social login (Google, GitHub, etc.) or enterprise SSO, Better Auth acts as your identity layer. Char validates Better Auth’s tokens, not the upstream provider’s tokens.Understanding Auth Platforms vs Direct IDPs
Learn how auth platforms like Better Auth issue their own tokens after upstream OAuth flows
Token Requirements
Char validates Better Auth ID tokens with these requirements:| Claim | Requirement |
|---|---|
iss | Must match your configured issuer URL |
aud | Must include your configured Client ID |
sub | Required - used as the user identifier |
exp | Must not be expired |
Better Auth ID Token Claims
When using the JWT plugin with OIDC Provider, tokens include these claims based on requested scopes:| Scope | Claims Included |
|---|---|
openid | sub (user ID) |
profile | name, picture, given_name, family_name |
email | email, email_verified |
getAdditionalUserInfoClaim callback in the OIDC Provider configuration.
Example: Obtaining and Passing the Token
- React (better-auth/react)
- Vanilla JavaScript
- Next.js (SSR with Ticket)
JWKS Endpoint
Better Auth with the JWT plugin exposes a JWKS endpoint for token verification:| Endpoint | URL |
|---|---|
| JWKS | https://auth.yourapp.com/api/auth/jwks |
| Discovery | https://auth.yourapp.com/.well-known/openid-configuration |
Key Rotation
Better Auth supports automatic key rotation:Troubleshooting
INVALID_ISSUER error
INVALID_ISSUER error
The token issuer doesn’t match your configured URL:
- Verify the Issuer URL in Char matches your Better Auth
metadata.issuerexactly - Ensure you’re using the full URL including
https:// - Check that
BETTER_AUTH_URLenvironment variable is set correctly
INVALID_AUDIENCE error
INVALID_AUDIENCE error
The token’s
aud claim doesn’t match your configured Client ID:- Ensure the Client ID matches your
trustedClientsconfiguration - Verify you’re using the ID token, not a session token
- Check that the client is registered in the OIDC Provider plugin
JWKS_FETCH_FAILED error
JWKS_FETCH_FAILED error
Char couldn’t reach Better Auth’s JWKS endpoint:
- Verify your Better Auth instance is publicly accessible
- Check that the JWT plugin is enabled with
useJWTPlugin: true - Ensure
/api/auth/jwksendpoint is not blocked by middleware - Use Test Connection in the dashboard to verify
Token signature verification failed
Token signature verification failed
If tokens fail signature verification:
- Ensure
useJWTPlugin: trueis set in the OIDC Provider config - Check that the JWT plugin is using the same keys for signing
- If keys were recently rotated, wait for cache refresh or clear JWKS cache
Better Auth Features
Better Auth offers additional features that complement Char integration:| Feature | Description |
|---|---|
| Multi-session Support | Users can have multiple active sessions |
| Social Login | Google, GitHub, Discord, and 20+ providers |
| Two-Factor Auth | TOTP and backup codes |
| Organizations | Multi-tenant support with teams |
| Session Management | Revoke sessions, track devices |
Better Auth Documentation
Explore the full Better Auth documentation
Security Best Practices
- Use asymmetric signing with the JWT plugin for production (
useJWTPlugin: true) - Configure key rotation to limit the impact of key compromise
- Use HTTPS for all endpoints in production
- Set appropriate token expiration times
- Register only trusted clients with
skipConsent: true - Monitor auth logs for suspicious activity

