Installation
1
Install the package
2
Add the plugin to your auth config
auth.ts
3
Migrate the database
4
Add the client plugin
auth-client.ts
Registering providers
Register an OIDC provider
Better Auth automatically fetches the provider’s OIDC discovery document, so most endpoint fields are optional:- Client
- Server
Discovery endpoints must be in your
trustedOrigins configuration. Add the IdP origin: trustedOrigins: ["https://your-org.okta.com"]Register a SAML provider
- Client
- Server
Sign in with SSO
Provisioning
User provisioning
Run custom logic whenever a user signs in through SSO:auth.ts
Organization provisioning
Automatically add SSO users to organizations:auth.ts
Linking providers to organizations
acmecorp.com signing in through this provider are automatically added to the Acme Corp organization.
SAML endpoints
The plugin creates these endpoints automatically:Get SP metadata
SAML security
InResponseTo validation
Prevent replay attacks and unsolicited responses:auth.ts
Timestamp validation
auth.ts
Algorithm validation
auth.ts
Replay protection (assertion ID deduplication) is always enabled and cannot be disabled.
OIDC discovery
Better Auth automatically fetches the IdP’s discovery document from{issuer}/.well-known/openid-configuration. The following fields are auto-discovered:
authorizationEndpointtokenEndpointjwksEndpointuserInfoEndpointdiscoveryEndpointtokenEndpointAuthentication
Discovery errors
Domain verification
Enable domain verification to require ownership proof before trusting SSO providers:auth.ts
1
Register the provider — a verification token is returned in the response.
2
Add a DNS TXT record:
_better-auth-token-{providerId} with the token value.3
Submit a verification request:
Schema
The plugin creates anssoProvider table: