|
| 1 | +# OIDC Authentication Setup |
| 2 | + |
| 3 | +This application supports authentication with any OIDC-compliant identity provider (Okta, Keycloak, Auth0, etc.). |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +1. **Configure your OIDC provider** with these settings: |
| 8 | + - **Callback URL**: `http://localhost:3000/api/auth/oauth2/callback/oidc` (adjust domain/port for production) |
| 9 | + - **Grant Types**: Authorization Code, Refresh Token |
| 10 | + - **Response Type**: code |
| 11 | + - **Scopes**: openid, email, profile |
| 12 | + |
| 13 | +2. **Set environment variables** in `.env.local`: |
| 14 | + |
| 15 | +```bash |
| 16 | +# Better Auth Configuration |
| 17 | +BETTER_AUTH_SECRET=your-random-secret-here |
| 18 | +BETTER_AUTH_URL=http://localhost:3000 |
| 19 | + |
| 20 | +# OIDC Provider Configuration |
| 21 | +OIDC_CLIENT_ID=your-client-id |
| 22 | +OIDC_CLIENT_SECRET=your-client-secret |
| 23 | +OIDC_ISSUER_URL=https://your-oidc-provider.com |
| 24 | +``` |
| 25 | + |
| 26 | +## Local Development |
| 27 | + |
| 28 | +For local testing, this repo includes a test OIDC provider: |
| 29 | + |
| 30 | +1. **Start the OIDC provider**: |
| 31 | + ```bash |
| 32 | + pnpm oidc |
| 33 | + ``` |
| 34 | + |
| 35 | +2. **Use these credentials** in `.env.local`: |
| 36 | + ```bash |
| 37 | + OIDC_CLIENT_ID=better-auth-dev |
| 38 | + OIDC_CLIENT_SECRET=dev-secret-change-in-production |
| 39 | + OIDC_ISSUER_URL=http://localhost:4000 |
| 40 | + ``` |
| 41 | + |
| 42 | +3. **Run the app**: |
| 43 | + ```bash |
| 44 | + pnpm dev |
| 45 | + ``` |
| 46 | + |
| 47 | + Or run both concurrently: |
| 48 | + ```bash |
| 49 | + pnpm dev |
| 50 | + ``` |
| 51 | + |
| 52 | +The test provider automatically logs in as `[email protected]`. |
| 53 | + |
| 54 | +## Provider-Specific Guides |
| 55 | + |
| 56 | +### Okta |
| 57 | + |
| 58 | +1. Create a new App Integration (OIDC - Web Application) |
| 59 | +2. Set Callback URL: `http://localhost:3000/api/auth/oauth2/callback/oidc` |
| 60 | +3. Use Okta domain as OIDC_ISSUER_URL (e.g., `https://dev-12345.okta.com`) |
| 61 | + |
| 62 | +### Keycloak |
| 63 | + |
| 64 | +1. Create a new Client |
| 65 | +2. Set Access Type: confidential |
| 66 | +3. Set Valid Redirect URIs: `http://localhost:3000/api/auth/oauth2/callback/oidc` |
| 67 | +4. Use Realm URL as OIDC_ISSUER_URL (e.g., `https://keycloak.example.com/realms/myrealm`) |
| 68 | + |
| 69 | +### Auth0 |
| 70 | + |
| 71 | +1. Create a Regular Web Application |
| 72 | +2. Set Allowed Callback URLs: `http://localhost:3000/api/auth/oauth2/callback/oidc` |
| 73 | +3. Use Auth0 domain as OIDC_ISSUER_URL (e.g., `https://your-tenant.auth0.com`) |
| 74 | + |
| 75 | +## Architecture |
| 76 | + |
| 77 | +This application uses **stateless authentication**: |
| 78 | +- No database required |
| 79 | +- Session data stored in encrypted JWE cookies |
| 80 | +- 7-day session expiration with 30-day refresh window |
| 81 | +- Works with any OIDC-compliant provider |
0 commit comments