|
| 1 | + |
| 2 | + |
| 3 | +ThunderID provider helper for the [Better Auth](https://better-auth.com) |
| 4 | +[Generic OAuth plugin](https://better-auth.com/docs/plugins/generic-oauth). |
| 5 | + |
| 6 | +This is a |
| 7 | +[community provider helper](https://better-auth.com/docs/authentication/other-social-providers#community-provider-helpers): |
| 8 | +it returns a typed `GenericOAuthConfig` for a ThunderID issuer. All OAuth 2.0 / OIDC handling is performed by Better |
| 9 | +Auth itself — this package only supplies configuration, so there is no ThunderID SDK dependency and no protocol logic to |
| 10 | +keep in sync. |
| 11 | + |
| 12 | +## Pre-requisites |
| 13 | + |
| 14 | +- Requires `better-auth` >= 1.7.0 as a peer dependency. |
| 15 | +- A running ThunderID instance with an OAuth 2.0 / OIDC application registered. See the [ThunderID documentation](https://thunderid.dev/) for details. |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install @thunderid/better-auth |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +```ts |
| 26 | +import {thunderid} from '@thunderid/better-auth'; |
| 27 | +import {betterAuth} from 'better-auth'; |
| 28 | +import {genericOAuth} from 'better-auth/plugins'; |
| 29 | + |
| 30 | +export const auth = betterAuth({ |
| 31 | + plugins: [ |
| 32 | + genericOAuth({ |
| 33 | + config: [ |
| 34 | + thunderid({ |
| 35 | + clientId: process.env.THUNDERID_CLIENT_ID!, |
| 36 | + clientSecret: process.env.THUNDERID_CLIENT_SECRET!, |
| 37 | + issuer: process.env.THUNDERID_ISSUER!, |
| 38 | + }), |
| 39 | + ], |
| 40 | + }), |
| 41 | + ], |
| 42 | +}); |
| 43 | +``` |
| 44 | + |
| 45 | +Use your existing Better Auth client, or create one. No client plugin is required, since the generic OAuth |
| 46 | +plugin exposes sign-in through the standard social-provider API: |
| 47 | + |
| 48 | +```ts |
| 49 | +import {createAuthClient} from 'better-auth/react'; |
| 50 | + |
| 51 | +export const authClient = createAuthClient(); |
| 52 | +``` |
| 53 | + |
| 54 | +Sign in from the client with the `thunderid` provider ID: |
| 55 | + |
| 56 | +```ts |
| 57 | +await authClient.signIn.social({ |
| 58 | + provider: 'thunderid', |
| 59 | + callbackURL: '/dashboard', |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | +## Callback URL |
| 64 | + |
| 65 | +Register this redirect URI on your ThunderID application: |
| 66 | + |
| 67 | +``` |
| 68 | +{baseURL}/api/auth/callback/thunderid |
| 69 | +``` |
| 70 | + |
| 71 | +For example, `http://localhost:3000/api/auth/callback/thunderid` in development. |
| 72 | + |
| 73 | +## Options |
| 74 | + |
| 75 | +| Option | Type | Default | Description | |
| 76 | +| ----------------------- | ---------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 77 | +| `issuer` | `string` | — | **Required.** ThunderID issuer URL, e.g. `https://thunderid.example.com`. A trailing slash is trimmed. The OIDC discovery URL is derived as `{issuer}/.well-known/openid-configuration`, so all endpoints come from the discovery document. | |
| 78 | +| `clientId` | `string` | — | **Required.** OAuth client ID. | |
| 79 | +| `clientSecret` | `string` | — | OAuth client secret. Omit for public clients using `tokenEndpointAuth: {method: 'none'}`. | |
| 80 | +| `scopes` | `string[]` | `['openid', 'profile', 'email']` | Requested scopes. | |
| 81 | +| `tokenEndpointAuth` | `object` | provider default | Token endpoint authentication method, e.g. `{method: 'client_secret_post'}`. | |
| 82 | +| `pkce` | `boolean` | discovery default | Force PKCE on or off. | |
| 83 | +| `redirectURI` | `string` | Better Auth default | Override the callback URL. | |
| 84 | +| `endSessionEndpoint` | `string` | discovery default | RP-initiated logout endpoint. | |
| 85 | +| `postLogoutRedirectURI` | `string` | — | Where ThunderID returns the user after logout. | |
| 86 | +| `disableProviderLogout` | `boolean` | `false` | Skip provider logout on sign-out. | |
| 87 | +| `disableImplicitSignUp` | `boolean` | `false` | Require an explicit sign-up request before creating a user. | |
| 88 | +| `disableSignUp` | `boolean` | `false` | Reject sign-in for users who do not already exist. | |
| 89 | +| `overrideUserInfo` | `boolean` | `false` | Refresh the stored user profile from ThunderID on every sign-in. | |
| 90 | + |
| 91 | +Every option other than `issuer` is passed through from Better Auth's |
| 92 | +[`BaseOAuthProviderOptions`](https://better-auth.com/docs/authentication/other-social-providers#built-in-provider-helpers) |
| 93 | +and behaves exactly as it does for the built-in provider helpers. |
| 94 | + |
| 95 | +## License |
| 96 | + |
| 97 | +This project is licensed under the [Apache License 2.0](https://github.com/thunder-id/thunderid/blob/main/LICENSE). |
0 commit comments