Skip to content

Commit 975ee44

Browse files
committed
Update README for call.provision API and stateless registration
1 parent 3d1a2d1 commit 975ee44

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ fun Application.module() {
102102
post {
103103
val params = call.receiveParameters()
104104
call.sessions.set(MySession(apiKey = params["api_key"]))
105-
complete(claims = mapOf("username" to params["username"]))
105+
call.provision.complete {
106+
withClaim("username", params["username"])
107+
}
106108
}
107109
}
108110

@@ -181,17 +183,18 @@ install(OAuth) {
181183
server {
182184
// Client validation
183185
clients {
184-
// Dynamic registration (RFC 7591)
186+
// Dynamic registration (RFC 7591) - public clients only
185187
// Has access to: origin, headers, resource, request
186188
registration = true // or:
187-
// registration { clientId, clientName ->
189+
// registration { clientName ->
188190
// origin.remoteHost in allowedIps
189191
// }
190192

191-
// Client credentials grant
193+
// Confidential clients with pre-configured credentials
194+
// Validated at /token (RFC 6749 Section 2.3)
192195
// Has access to: origin, headers, resource, request
193196
credentials { clientId, secret ->
194-
origin.remoteHost !in blockedIps && db.check(clientId, secret)
197+
clientId == "my-app" && secret == "my-secret"
195198
}
196199
// Or static: credentials("app" to "secret", "app2" to "secret2")
197200
}
@@ -372,7 +375,9 @@ routing {
372375
call.sessions.set(MySession(apiKey = apiKey))
373376

374377
// Complete with claims embedded in JWT
375-
complete(claims = mapOf("validated" to "true"))
378+
call.provision.complete {
379+
withClaim("validated", "true")
380+
}
376381
} else {
377382
call.respondText("Invalid API key")
378383
}
@@ -387,13 +392,16 @@ routing {
387392

388393
### Provision Context
389394

390-
Handlers receive `ProvisionRoutingContext` with:
395+
Access provision context via `call.provision`:
391396

392397
| Property | Description |
393398
|----------|-------------|
394-
| `call` | The Ktor `ApplicationCall` (use `call.sessions` for session access) |
395-
| `clientId` | The OAuth client ID |
396-
| `complete()` | Complete provision and continue OAuth flow |
399+
| `call.provision.client` | The client identity (clientId and optionally clientName) |
400+
| `call.provision.complete {}` | Complete provision with optional claims builder |
401+
402+
The claims builder supports:
403+
- `withClaim(key, value)` - Plain claims in JWT
404+
- `withEncryptedClaim(key, value)` - Encrypted claims (use `payload.decryptClaim()` to read)
397405

398406
## Multiple Providers
399407

@@ -410,7 +418,11 @@ routing {
410418
// Provision routes
411419
provision { /* default provider */ }
412420
provision("calendar") {
413-
handle { complete(claims = mapOf("scope" to "calendar")) }
421+
post {
422+
call.provision.complete {
423+
withClaim("scope", "calendar")
424+
}
425+
}
414426
}
415427

416428
// Protected routes
@@ -437,7 +449,7 @@ The plugin automatically discovers which routes are protected by which provider
437449
│ { redirect_uris: [...] } │
438450
│ ───────────────────────────────────────>│
439451
│ │
440-
│ { client_id, client_secret } │
452+
│ { client_id } (public client)
441453
│ <───────────────────────────────────────│
442454
│ │
443455
│ GET /authorize?client_id=... │

0 commit comments

Comments
 (0)