Skip to main content
The Generic OAuth plugin provides a flexible way to integrate authentication with any OAuth 2.0 or OpenID Connect (OIDC) provider. Use it to add social login, enterprise IdP authentication, or any custom OAuth flow.

Installation

1

Add the plugin to your auth config

auth.ts
2

Add the client plugin

auth-client.ts

Usage

Initiate sign-in

Add an OAuth provider to an existing user’s account:

Callback URL

The plugin automatically mounts a callback handler at:
Configure your OAuth provider to use this URL as the redirect URI.

Pre-configured providers

Better Auth ships with pre-configured helpers for popular providers:
auth.ts

Configuration options

Each provider configuration object supports:

Advanced usage

Custom token exchange

For providers with non-standard token endpoints:

Custom user info fetching

Profile field mapping

Accessing raw token data

The tokens object includes a raw field with the original token response:

Security: issuer validation

Better Auth validates the OAuth provider’s issuer to protect against mix-up attacks (RFC 9207).
For maximum security with modern OIDC providers (Google, Auth0, Okta), enable requireIssuerValidation: true.