Skip to main content
This plugin will soon be deprecated in favor of a newer OAuth Provider plugin. New projects should check the Better Auth documentation for the most up-to-date provider plugin.
The OIDC Provider plugin enables you to build and manage your own OpenID Connect (OIDC) provider using Better Auth. Other services can authenticate users through your OIDC provider instead of relying on third-party services like Okta or Azure AD. Key capabilities:
  • Client registration (static trusted clients and dynamic registration)
  • Authorization Code Flow
  • Refresh token support
  • OAuth consent screens (with bypass support for trusted apps)
  • UserInfo endpoint
  • JWKS endpoint integration via the JWT plugin
  • Custom claims
This plugin is in active development. Report any issues on GitHub.

Installation

1

Add the plugin to your auth config

auth.ts
2

Migrate the database

3

Add the client plugin

auth-client.ts

Registering clients

Dynamic registration

Clients can register via the /oauth2/register endpoint (RFC 7591):
Dynamic registration requires authentication by default. To allow public registration:

Trusted clients (static configuration)

For first-party applications, configure trusted clients directly. They bypass database lookups and can skip the consent screen:
auth.ts

OIDC endpoints

The plugin exposes these standard OIDC endpoints:

UserInfo endpoint

The UserInfo endpoint returns claims based on the granted scopes: Server-side:
External client:

Custom claims

auth.ts
Custom claims appear in both the UserInfo response and the ID token. By default, Better Auth shows a built-in consent screen. Customize it with a consentPage path:
auth.ts
Better Auth redirects to this path with consent_code, client_id, and scope query parameters. After the user consents, call:
Trusted clients with skipConsent: true bypass the consent screen entirely.

Handling login

When users are not signed in and reach the authorization endpoint, they are redirected to loginPage. After a new session is created, the plugin automatically continues the authorization flow.
auth.ts

JWKS integration

Combine with the JWT plugin for asymmetric ID token signing:
auth.ts
When useJWTPlugin is false (default), ID tokens are signed with HMAC-SHA256 using the application secret.

Customize OIDC metadata

auth.ts

Schema

oauthApplication

oauthAccessToken

oauthConsent