Skip to content

Commit 055c187

Browse files
committed
feat: adds OIDC server plugin.
1 parent 913158b commit 055c187

File tree

17 files changed

+2126
-3
lines changed

17 files changed

+2126
-3
lines changed

examples/oidc/README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# OIDC Server Plugin Example
2+
3+
This example demonstrates the `oidc-server` external plugin that provides OpenID Connect authorization server functionality.
4+
5+
## Features
6+
7+
- **Authorization Code Flow** with optional PKCE support
8+
- **Standard OIDC Endpoints**:
9+
- `/.well-known/openid-configuration` - OIDC discovery
10+
- `/oidc/authorize` - Authorization endpoint
11+
- `/oidc/token` - Token endpoint
12+
- `/oidc/userinfo` - Userinfo endpoint
13+
- **Web-based Authentication** with username/password form
14+
- **Configurable Users and Clients** via YAML configuration
15+
- **JWT Token Support** with HS256 signing
16+
- **Standard OIDC Scopes**: `openid`, `profile`, `email`
17+
18+
## Configuration
19+
20+
### User and Client Configuration (`oidc-users.yaml`)
21+
22+
```yaml
23+
users:
24+
- username: "alice"
25+
password: "password123"
26+
claims:
27+
sub: "alice"
28+
29+
given_name: "Alice"
30+
family_name: "Smith"
31+
name: "Alice Smith"
32+
33+
clients:
34+
- client_id: "demo-app"
35+
client_secret: "demo-secret"
36+
redirect_uris:
37+
- "http://localhost:8080/callback"
38+
```
39+
40+
### Imposter Configuration (`imposter-config.yaml`)
41+
42+
```yaml
43+
plugin: oidc-server
44+
resources: []
45+
```
46+
47+
## Usage
48+
49+
1. **Enable External Plugins**:
50+
```bash
51+
export IMPOSTER_EXTERNAL_PLUGINS=true
52+
```
53+
54+
2. **Run Imposter**:
55+
```bash
56+
make run ./examples/oidc
57+
```
58+
59+
3. **Test Authorization Flow**:
60+
Navigate to:
61+
```
62+
http://localhost:8080/oidc/authorize?client_id=demo-app&redirect_uri=http://localhost:8080/callback&response_type=code&scope=openid+profile+email&state=test123
63+
```
64+
65+
4. **Login Credentials**:
66+
- Username: `alice` / Password: `password123`
67+
- Username: `bob` / Password: `password456`
68+
69+
## OIDC Flow Example
70+
71+
### 1. Authorization Request
72+
```
73+
GET /oidc/authorize?client_id=demo-app&redirect_uri=http://localhost:8080/callback&response_type=code&scope=openid+profile+email&state=test123
74+
```
75+
76+
### 2. User Login
77+
Users will see a web form to enter username/password.
78+
79+
### 3. Authorization Response
80+
```
81+
HTTP/1.1 302 Found
82+
Location: http://localhost:8080/callback?code=abc123&state=test123
83+
```
84+
85+
### 4. Token Request
86+
```bash
87+
curl -X POST http://localhost:8080/oidc/token \
88+
-H "Content-Type: application/x-www-form-urlencoded" \
89+
-d "grant_type=authorization_code&client_id=demo-app&client_secret=demo-secret&code=abc123&redirect_uri=http://localhost:8080/callback"
90+
```
91+
92+
### 5. Token Response
93+
```json
94+
{
95+
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
96+
"id_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
97+
"token_type": "Bearer",
98+
"expires_in": 3600,
99+
"scope": "openid profile email"
100+
}
101+
```
102+
103+
### 6. Userinfo Request
104+
```bash
105+
curl -H "Authorization: Bearer <access_token>" http://localhost:8080/oidc/userinfo
106+
```
107+
108+
### 7. Userinfo Response
109+
```json
110+
{
111+
"sub": "alice",
112+
"name": "Alice Smith",
113+
"given_name": "Alice",
114+
"family_name": "Smith",
115+
"email": "[email protected]"
116+
}
117+
```
118+
119+
## PKCE Support
120+
121+
The plugin supports PKCE (RFC 7636) for enhanced security:
122+
123+
1. **Generate Code Verifier and Challenge**:
124+
```javascript
125+
// JavaScript example
126+
const codeVerifier = base64URLEncode(crypto.getRandomValues(new Uint8Array(32)));
127+
const challenge = base64URLEncode(sha256(codeVerifier));
128+
```
129+
130+
2. **Authorization Request with PKCE**:
131+
```
132+
GET /oidc/authorize?client_id=demo-app&redirect_uri=http://localhost:8080/callback&response_type=code&scope=openid&code_challenge=<challenge>&code_challenge_method=S256
133+
```
134+
135+
3. **Token Request with PKCE**:
136+
```bash
137+
curl -X POST http://localhost:8080/oidc/token \
138+
-d "grant_type=authorization_code&client_id=demo-app&code=abc123&redirect_uri=http://localhost:8080/callback&code_verifier=<verifier>"
139+
```
140+
141+
## Discovery Document
142+
143+
The OIDC discovery document is available at:
144+
```
145+
GET /.well-known/openid-configuration
146+
```
147+
148+
This provides metadata about the authorization server endpoints and capabilities.
149+
150+
## Security Notes
151+
152+
- JWT tokens are signed with HS256 using a randomly generated secret
153+
- Passwords in the example use plain text for simplicity - use bcrypt hashed passwords in production
154+
- Authorization codes and access tokens have configurable expiration times
155+
- PKCE is supported for enhanced security with public clients

examples/oidc/imposter-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Example OIDC Server Configuration
2+
# This demonstrates how to use the oidc-server external plugin
3+
4+
plugin: oidc-server
5+
resources: []
6+
7+
# Note: The oidc-server plugin will automatically handle the following endpoints:
8+
# - /.well-known/openid-configuration (OIDC discovery)
9+
# - /oidc/authorize (authorization endpoint)
10+
# - /oidc/token (token endpoint)
11+
# - /oidc/userinfo (userinfo endpoint)
12+
#
13+
# User credentials and client configurations are loaded from oidc-users.yaml
14+
# in the same directory as this configuration file.

examples/oidc/oidc-users.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
users:
2+
- username: "alice"
3+
password: "password123"
4+
claims:
5+
sub: "alice"
6+
7+
given_name: "Alice"
8+
family_name: "Smith"
9+
name: "Alice Smith"
10+
preferred_username: "alice"
11+
- username: "bob"
12+
password: "password456"
13+
claims:
14+
sub: "bob"
15+
16+
given_name: "Bob"
17+
family_name: "Jones"
18+
name: "Bob Jones"
19+
preferred_username: "bob"
20+
21+
clients:
22+
- client_id: "demo-app"
23+
client_secret: "demo-secret"
24+
redirect_uris:
25+
- "http://localhost:3000/callback"
26+
- "http://localhost:8080/callback"
27+
- "https://jwt.io"
28+
- client_id: "public-app"
29+
redirect_uris:
30+
- "http://localhost:3000/auth/callback"
31+
- "http://localhost:8080/auth/callback"

0 commit comments

Comments
 (0)