Skip to content

Commit efa1b8b

Browse files
committed
.
1 parent 82302dc commit efa1b8b

File tree

10 files changed

+417
-97
lines changed

10 files changed

+417
-97
lines changed

OIDC_SETUP.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

dev/oidc-provider.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ const configuration = {
1919
{
2020
client_id: "better-auth-dev",
2121
client_secret: "dev-secret-change-in-production",
22-
redirect_uris: ["http://localhost:3000/api/auth/callback/oidc"],
22+
redirect_uris: [
23+
// Better Auth genericOAuth uses /oauth2/callback/:providerId
24+
"http://localhost:3000/api/auth/oauth2/callback/oidc",
25+
"http://localhost:3001/api/auth/oauth2/callback/oidc",
26+
"http://localhost:3002/api/auth/oauth2/callback/oidc",
27+
"http://localhost:3003/api/auth/oauth2/callback/oidc",
28+
],
2329
response_types: ["code"],
2430
grant_types: ["authorization_code", "refresh_token"],
2531
token_endpoint_auth_method: "client_secret_post",
@@ -52,7 +58,6 @@ const configuration = {
5258
},
5359
features: {
5460
devInteractions: { enabled: true }, // Enable dev interactions for easy testing
55-
refreshToken: { enabled: true },
5661
},
5762
ttl: {
5863
AccessToken: 3600, // 1 hour

lib/auth-client.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/auth.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"private": true,
55
"packageManager": "[email protected]",
66
"scripts": {
7-
"dev": "next dev",
7+
"dev": "concurrently -n \"OIDC,Next\" -c \"blue,green\" \"pnpm oidc\" \"pnpm dev:next\"",
8+
"dev:next": "next dev",
89
"build": "next build",
910
"start": "next start",
1011
"lint": "biome check",
@@ -30,6 +31,7 @@
3031
"@types/react-dom": "^19",
3132
"@vitejs/plugin-react": "^5.1.1",
3233
"babel-plugin-react-compiler": "1.0.0",
34+
"concurrently": "^9.2.1",
3335
"husky": "^9.1.7",
3436
"jsdom": "^27.2.0",
3537
"lint-staged": "^16.0.0",

0 commit comments

Comments
 (0)