@20baht/elysia-oauth-provider 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +432 -2
- package/dist/config.d.ts +35 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/core/bearer.d.ts +11 -0
- package/dist/core/bearer.d.ts.map +1 -0
- package/dist/core/pkce.d.ts +6 -0
- package/dist/core/pkce.d.ts.map +1 -0
- package/dist/core/provider.d.ts +100 -0
- package/dist/core/provider.d.ts.map +1 -0
- package/dist/core/rate-limit.d.ts +55 -0
- package/dist/core/rate-limit.d.ts.map +1 -0
- package/dist/core/redirect-uri.d.ts +12 -0
- package/dist/core/redirect-uri.d.ts.map +1 -0
- package/dist/core/resource.d.ts +18 -0
- package/dist/core/resource.d.ts.map +1 -0
- package/dist/core/scope.d.ts +7 -0
- package/dist/core/scope.d.ts.map +1 -0
- package/dist/crypto/hash.d.ts +10 -0
- package/dist/crypto/hash.d.ts.map +1 -0
- package/dist/crypto/jwt.d.ts +36 -0
- package/dist/crypto/jwt.d.ts.map +1 -0
- package/dist/crypto/props-encryption.d.ts +11 -0
- package/dist/crypto/props-encryption.d.ts.map +1 -0
- package/dist/crypto/random.d.ts +8 -0
- package/dist/crypto/random.d.ts.map +1 -0
- package/dist/endpoints/authorize.d.ts +4 -0
- package/dist/endpoints/authorize.d.ts.map +1 -0
- package/dist/endpoints/http.d.ts +22 -0
- package/dist/endpoints/http.d.ts.map +1 -0
- package/dist/endpoints/metadata.d.ts +9 -0
- package/dist/endpoints/metadata.d.ts.map +1 -0
- package/dist/endpoints/register.d.ts +4 -0
- package/dist/endpoints/register.d.ts.map +1 -0
- package/dist/endpoints/revoke.d.ts +4 -0
- package/dist/endpoints/revoke.d.ts.map +1 -0
- package/dist/endpoints/token.d.ts +4 -0
- package/dist/endpoints/token.d.ts.map +1 -0
- package/dist/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1991 -0
- package/dist/index.js.map +32 -0
- package/dist/plugin.d.ts +423 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/storage/conformance.d.ts +36 -0
- package/dist/storage/conformance.d.ts.map +1 -0
- package/dist/storage/conformance.js +105 -0
- package/dist/storage/conformance.js.map +10 -0
- package/dist/storage/keys.d.ts +30 -0
- package/dist/storage/keys.d.ts.map +1 -0
- package/dist/storage/memory.d.ts +31 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/redis.d.ts +64 -0
- package/dist/storage/redis.d.ts.map +1 -0
- package/dist/storage/redis.js +87 -0
- package/dist/storage/redis.js.map +10 -0
- package/dist/storage/types.d.ts +27 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/types.d.ts +270 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +67 -4
package/README.md
CHANGED
|
@@ -1,3 +1,433 @@
|
|
|
1
|
-
#
|
|
1
|
+
# elysia-oauth-provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn an Elysia app that already has ordinary login into a **standards-compliant
|
|
4
|
+
OAuth 2.1 authorization server**, so MCP clients (Claude, Cursor, MCP Inspector,
|
|
5
|
+
…) can authenticate against it. A Bun + Elysia port of the ideas in
|
|
6
|
+
[`@cloudflare/workers-oauth-provider`](https://github.com/cloudflare/workers-oauth-provider)
|
|
7
|
+
with **pluggable storage** instead of Workers KV.
|
|
8
|
+
|
|
9
|
+
You keep owning the login UI and the user database. The plugin owns the
|
|
10
|
+
protocol:
|
|
11
|
+
|
|
12
|
+
- `GET /.well-known/oauth-authorization-server` (RFC 8414)
|
|
13
|
+
- `GET /.well-known/oauth-protected-resource[/path]` (RFC 9728, what MCP clients look for)
|
|
14
|
+
- `POST /register` – Dynamic Client Registration (RFC 7591), optional / gated
|
|
15
|
+
- `GET /authorize` – validated, then delegated to **your** login page
|
|
16
|
+
- `POST /token` – `authorization_code` + `refresh_token`
|
|
17
|
+
- `POST /revoke` (RFC 7009)
|
|
18
|
+
- Bearer validation on your routes with a typed `ctx.oauth`, and a correct
|
|
19
|
+
`WWW-Authenticate: Bearer resource_metadata="…"` challenge on 401
|
|
20
|
+
|
|
21
|
+
Security posture: PKCE **S256 mandatory**, exact redirect-URI matching (RFC 8252
|
|
22
|
+
loopback port exception), one-time codes with short TTL (replay revokes the
|
|
23
|
+
whole grant), refresh-token rotation with one-generation grace, RFC 8707
|
|
24
|
+
`resource`/audience binding, RFC 9207 `iss`, secrets/codes/tokens stored only
|
|
25
|
+
as SHA-256, props encrypted at rest with per-grant keys, constant-time compares,
|
|
26
|
+
`no-store` everywhere, no implicit flow, no plain PKCE.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quickstart
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
bun add @20baht/elysia-oauth-provider
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Elysia, t } from 'elysia'
|
|
38
|
+
import { oauthProvider, MemoryStorage } from '@20baht/elysia-oauth-provider'
|
|
39
|
+
|
|
40
|
+
// Whatever your protected handlers need to know about the user.
|
|
41
|
+
type Props = { userId: number; username: string }
|
|
42
|
+
|
|
43
|
+
const app = new Elysia()
|
|
44
|
+
.use(
|
|
45
|
+
oauthProvider<Props>({
|
|
46
|
+
issuer: 'https://api.example.com', // public URL of this server
|
|
47
|
+
storage: new MemoryStorage(), // dev only – see Storage
|
|
48
|
+
resource: 'https://api.example.com/mcp', // bind tokens to your MCP endpoint
|
|
49
|
+
scopesSupported: ['expenses:read', 'profile'],
|
|
50
|
+
|
|
51
|
+
// GET /authorize was validated. Show YOUR login page.
|
|
52
|
+
handleAuthorize: ({ authRequestId }) =>
|
|
53
|
+
Response.redirect(`https://api.example.com/login?auth=${authRequestId}`),
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
// Your login page's form handler. You verify the password.
|
|
58
|
+
.post(
|
|
59
|
+
'/login',
|
|
60
|
+
async ({ body, oauthProvider, redirect }) => {
|
|
61
|
+
const user = await myUsers.verify(body.username, body.password)
|
|
62
|
+
if (!user) return new Response('nope', { status: 401 })
|
|
63
|
+
|
|
64
|
+
const { redirectTo } = await oauthProvider.completeAuthorization({
|
|
65
|
+
authRequestId: body.auth,
|
|
66
|
+
userId: String(user.id),
|
|
67
|
+
scopes: ['expenses:read', 'profile'],
|
|
68
|
+
props: { userId: user.id, username: user.username },
|
|
69
|
+
})
|
|
70
|
+
return redirect(redirectTo, 302)
|
|
71
|
+
},
|
|
72
|
+
{ body: t.Object({ auth: t.String(), username: t.String(), password: t.String() }) },
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
// Protected route: `oauth: true` requires a valid bearer token.
|
|
76
|
+
.post('/mcp', ({ oauth }) => handleMcp(oauth.props.userId), { oauth: true })
|
|
77
|
+
|
|
78
|
+
// …with a scope requirement (403 insufficient_scope otherwise).
|
|
79
|
+
.get('/mcp/me', ({ oauth }) => oauth.props, { oauth: { scopes: ['profile'] } })
|
|
80
|
+
|
|
81
|
+
.listen(3000)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`ctx.oauth` is fully typed from the `Props` generic:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
interface OAuthContext<Props> {
|
|
88
|
+
userId: string
|
|
89
|
+
clientId: string
|
|
90
|
+
grantId: string
|
|
91
|
+
scopes: string[]
|
|
92
|
+
props: Props
|
|
93
|
+
expiresAt: number // epoch seconds
|
|
94
|
+
audience?: string // RFC 8707 resource the token is bound to
|
|
95
|
+
token: string
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
A complete runnable app with a login page and an MCP endpoint lives in
|
|
100
|
+
[`examples/oauth-provider-basic`](../../../examples/oauth-provider-basic).
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## The authorization flow
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
MCP client elysia-oauth-provider your app
|
|
108
|
+
│ GET /authorize?… │ │
|
|
109
|
+
│──────────────────────────────▶│ validate client, redirect_uri, │
|
|
110
|
+
│ │ PKCE, scope, resource │
|
|
111
|
+
│ │ stash as authreq:{id} (10 min) │
|
|
112
|
+
│ │────── handleAuthorize({id}) ─────▶│ render / redirect to login
|
|
113
|
+
│◀──────────────────────────────┼───────────────────────────────────┤
|
|
114
|
+
│ user logs in on your page │ │
|
|
115
|
+
│──────────────────────────────────────────────────────────────────▶│ POST /login
|
|
116
|
+
│ │◀── completeAuthorization({id, │
|
|
117
|
+
│ │ userId, scopes, props }) ────┤
|
|
118
|
+
│◀── 302 redirect_uri?code&state&iss ───────────────────────────────┤
|
|
119
|
+
│ POST /token (code, verifier) │ │
|
|
120
|
+
│──────────────────────────────▶│ → access + refresh token │
|
|
121
|
+
│ POST /mcp Bearer … │ │
|
|
122
|
+
│──────────────────────────────▶│ macro `oauth` → ctx.oauth ───────▶│ handler
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`completeAuthorization` can also be called with a parsed `authRequest` instead
|
|
126
|
+
of an id if you prefer to run the workers-oauth-provider style
|
|
127
|
+
(`oauthProvider.parseAuthRequest(request)` → stash it yourself → complete).
|
|
128
|
+
|
|
129
|
+
Use `rejectAuthorization({ authRequestId })` when the user cancels; the client
|
|
130
|
+
receives `error=access_denied`.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Config reference
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
oauthProvider<Props>(config: OAuthProviderConfig<Props>)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
| Option | Type | Default | Notes |
|
|
141
|
+
| -------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
142
|
+
| `issuer` **(required)** | `string` | – | Absolute http(s) URL, optional base path (`https://x.com/auth`). Used for all advertised URLs; never the Host header. |
|
|
143
|
+
| `storage` **(required)** | `OAuthStorage` | – | See [Storage](#storage). |
|
|
144
|
+
| `handleAuthorize` **(required)** | `(input) => Response \| Promise<Response>` | – | `input = { authRequest, authRequestId, client, request }`. |
|
|
145
|
+
| `paths` | `Partial<{ authorize, token, register, revoke, jwks }>` | `/authorize`, `/token`, `/register`, `/revoke`, `/.well-known/jwks.json` | Relative to the issuer's base path. |
|
|
146
|
+
| `resource` | `string` | – | Canonical RFC 8707 resource. When set, every token is bound to it and other `resource` values → `invalid_target`. |
|
|
147
|
+
| `resourceMetadata` | `{ resource?, authorizationServers?, scopesSupported?, resourceName?, resourceDocumentation? }` | derived | Extra fields for the RFC 9728 document. |
|
|
148
|
+
| `scopesSupported` | `string[]` | – (any syntactically valid scope) | Advertised and enforced at `/authorize`, `/register`, `completeAuthorization`. |
|
|
149
|
+
| `accessTokenTTL` | seconds | `3600` | |
|
|
150
|
+
| `refreshTokenTTL` | seconds | `2592000` (30 d) | `0` disables refresh tokens. |
|
|
151
|
+
| `authCodeTTL` | seconds | `600` | |
|
|
152
|
+
| `authRequestTTL` | seconds | `600` | How long the user has to finish logging in. |
|
|
153
|
+
| `clientRegistrationTTL` | seconds \| `undefined` | `7776000` (90 d) | For dynamically registered clients only. Pass `undefined` explicitly for no expiry. |
|
|
154
|
+
| `clientRegistration` | `boolean \| { allowPublicClients?, maxBodyBytes? }` | `true` | `false` removes `/register` and `registration_endpoint`. Public clients allowed by default (MCP needs them). |
|
|
155
|
+
| `tokenFormat` | `'opaque' \| { type:'jwt', alg, privateKey, publicKey?, kid? } \| { type:'jwt', alg:'HS256', secret }` | `'opaque'` | JWT mode (via `jose`) also serves `jwks_uri`. Tokens are still recorded server-side so revocation works. |
|
|
156
|
+
| `encryptProps` | `boolean` | `true` | Encrypt `props` at rest with a per-grant AES-GCM key wrapped by the token (server cannot read props without a live token). |
|
|
157
|
+
| `cors` | `boolean` | `true` | Reflects `Origin` on OAuth endpoints and protected routes; answers `OPTIONS` on OAuth endpoints. |
|
|
158
|
+
| `rateLimit` | `boolean \| RateLimitConfig` | off | `true` = `DEFAULT_RATE_LIMITS` (token 30/min, register 10/h, authorize 60/min) with an in-process counter. See [Rate limiting](#rate-limiting). |
|
|
159
|
+
| `hooks` | see below | `{}` | |
|
|
160
|
+
|
|
161
|
+
### Hooks
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
hooks: {
|
|
165
|
+
// Gate / annotate dynamic registration. Return { error, description, status } to reject,
|
|
166
|
+
// { metadata, scope } to attach data, or throw an OAuthError.
|
|
167
|
+
onClientRegister?: ({ metadata, request }) => ClientRegisterHookResult | void
|
|
168
|
+
|
|
169
|
+
// After a valid /authorize request is parsed, before handleAuthorize. Throw to deny.
|
|
170
|
+
onAuthorize?: ({ authRequest, client, request }) => void
|
|
171
|
+
|
|
172
|
+
// Every access-token issuance (code exchange or refresh).
|
|
173
|
+
onTokenIssued?: ({ grantType, clientId, userId, grantId, scopes, props }) => void
|
|
174
|
+
|
|
175
|
+
// Every OAuth error response (already spec-shaped; internals never leak).
|
|
176
|
+
onError?: ({ code, description, status, request }) => void
|
|
177
|
+
|
|
178
|
+
// A request was rejected by the rate limiter (429 already sent).
|
|
179
|
+
onRateLimited?: ({ endpoint, key, retryAfterSeconds, request }) => void
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Helpers (`ctx.oauthProvider`, also `plugin.decorator.oauthProvider`)
|
|
184
|
+
|
|
185
|
+
| Method | Purpose |
|
|
186
|
+
| ------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
|
|
187
|
+
| `getAuthRequest(id)` | Load a pending request stashed by `GET /authorize`. |
|
|
188
|
+
| `parseAuthRequest(url \| Request)` | Validate `/authorize` params yourself. |
|
|
189
|
+
| `completeAuthorization({ authRequestId \| authRequest, userId, scopes, props, metadata?, revokeExistingGrants? })` | Issue a code; returns `{ redirectTo }`. Older grants for the same user+client are revoked by default. |
|
|
190
|
+
| `rejectAuthorization({ authRequestId \| authRequest, error?, description? })` | Returns `{ redirectTo }` carrying `access_denied` (or the given error). |
|
|
191
|
+
| `verifyAccessToken(token, requestUrl?)` | Manual bearer check (e.g. WebSockets). |
|
|
192
|
+
| `createClient / lookupClient / updateClient / deleteClient / listClients` | Client admin. `createClient` returns the plaintext secret once. |
|
|
193
|
+
| `listUserGrants(userId)` / `revokeGrant(grantId, userId)` | "Connected apps" UI. |
|
|
194
|
+
| `core` | The framework-agnostic `OAuthProviderCore` engine. |
|
|
195
|
+
|
|
196
|
+
### Protected routes (`oauth` macro)
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
.get('/x', handler, { oauth: true }) // valid token required
|
|
200
|
+
.get('/x', handler, { oauth: { scopes: ['a', 'b'] } }) // …and all listed scopes
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Responses on failure (all with `Cache-Control: no-store` and CORS headers):
|
|
204
|
+
|
|
205
|
+
| Case | Status | `WWW-Authenticate` |
|
|
206
|
+
| ----------------------------- | ------ | ------------------------------------------------------------------------------------------------------------ |
|
|
207
|
+
| no `Authorization` header | 401 | `Bearer realm="OAuth", resource_metadata="<issuer>/.well-known/oauth-protected-resource<path>"[, scope="…"]` |
|
|
208
|
+
| invalid / expired / revoked | 401 | `… error="invalid_token"`, JSON body `{ error: "invalid_token" }` |
|
|
209
|
+
| token bound to other resource | 401 | `… error="invalid_token", error_description="Token audience does not cover this resource"` |
|
|
210
|
+
| missing scope | 403 | `… error="insufficient_scope", scope="<required>"` |
|
|
211
|
+
|
|
212
|
+
`<path>` is the configured `resource`'s path, or the request path when no
|
|
213
|
+
resource is configured. The plugin serves
|
|
214
|
+
`/.well-known/oauth-protected-resource/*` for any suffix, so the pointer always
|
|
215
|
+
resolves.
|
|
216
|
+
|
|
217
|
+
Preflight `OPTIONS` for **your** protected routes is your responsibility
|
|
218
|
+
(e.g. `@elysiajs/cors`); the macro only adds CORS headers to its responses.
|
|
219
|
+
|
|
220
|
+
### Scopes as capabilities (a layout that works)
|
|
221
|
+
|
|
222
|
+
Name scopes after API areas rather than tools — `profile`, `tasks:read`,
|
|
223
|
+
`requests:read`, `requests:write` — and list them all in `scopesSupported` so
|
|
224
|
+
the consent page can describe each one. Two things the plugin leaves to you
|
|
225
|
+
that are worth deciding up front:
|
|
226
|
+
|
|
227
|
+
- **Granted ⊆ requested.** `completeAuthorization` rejects a grant wider than the
|
|
228
|
+
request (`invalid_scope`); a consent page that lets people untick scopes should
|
|
229
|
+
check the same thing first so it can answer in its own error shape.
|
|
230
|
+
- **Your own sessions are not scope-limited.** If the same routes also serve a
|
|
231
|
+
first-party web app (JWT / cookie session), resolve _both_ token kinds in one
|
|
232
|
+
place and carry `oauthScopes: string[] | null` on the user — `null` for a
|
|
233
|
+
first-party session — so a per-route scope check can skip it. Then a single
|
|
234
|
+
route implementation serves the browser and an MCP client identically.
|
|
235
|
+
|
|
236
|
+
### Rate limiting
|
|
237
|
+
|
|
238
|
+
Off by default. Turn it on for anything internet-facing:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
rateLimit: true // defaults below, per client IP, in-process counter
|
|
242
|
+
// or
|
|
243
|
+
rateLimit: {
|
|
244
|
+
token: { max: 30, windowSeconds: 60 },
|
|
245
|
+
register: { max: 10, windowSeconds: 3600 },
|
|
246
|
+
authorize: false, // disable for one endpoint
|
|
247
|
+
trustProxy: true, // read the first X-Forwarded-For entry (only behind your own proxy)
|
|
248
|
+
keyFor: ({ endpoint, ip, request }) => (ip === '10.0.0.1' ? null : `${endpoint}:${ip}`), // null = exempt
|
|
249
|
+
limiter: new RedisRateLimiter(redisClient), // shared across instances (INCR + EXPIRE)
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Blocked requests get `429` with `{ "error": "temporarily_unavailable" }`,
|
|
254
|
+
`Retry-After` and `Cache-Control: no-store`. Implement `RateLimiter`
|
|
255
|
+
(`hit(key, rule) → { allowed, retryAfterSeconds, remaining }`) to plug any
|
|
256
|
+
other backend.
|
|
257
|
+
|
|
258
|
+
Granted scopes are also checked against the request: `completeAuthorization`
|
|
259
|
+
throws `invalid_scope` if the app tries to grant a scope the client did not
|
|
260
|
+
ask for (a request with no `scope` leaves the choice to the app, bounded by
|
|
261
|
+
`scopesSupported`).
|
|
262
|
+
|
|
263
|
+
### Errors
|
|
264
|
+
|
|
265
|
+
`OAuthError(code, description, { status?, headers? })` renders as
|
|
266
|
+
`{ "error": code, "error_description": description }` with RFC-correct status
|
|
267
|
+
codes (`invalid_client` → 401 + `WWW-Authenticate: Basic`, `insufficient_scope`
|
|
268
|
+
→ 403, …). Unexpected exceptions become `server_error` with no details leaked.
|
|
269
|
+
`AuthorizationError` is redirected to the client only after the client and
|
|
270
|
+
redirect URI were validated; before that it is rendered locally as JSON 400.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Storage
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
interface OAuthStorage {
|
|
278
|
+
get<T>(key: string): Promise<T | null>
|
|
279
|
+
set<T>(key: string, value: T, opts?: { ttlSeconds?: number }): Promise<void>
|
|
280
|
+
delete(key: string): Promise<void>
|
|
281
|
+
list(prefix: string): Promise<string[]> // all live keys starting with prefix
|
|
282
|
+
close?(): Promise<void> | void
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Bundled adapters
|
|
287
|
+
|
|
288
|
+
**`MemoryStorage`** – `Map` + expiry timestamps. Lost on restart, **not shared
|
|
289
|
+
across processes/instances**. Dev, tests, single-process only.
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
new MemoryStorage({ sweepIntervalMs: 60_000 })
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**`RedisStorage`** – native key TTLs, `SCAN MATCH` for `list`. Works with
|
|
296
|
+
`ioredis` **or Bun's built-in client**; neither is a hard dependency
|
|
297
|
+
(`ioredis` is an optional peer).
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
import { RedisStorage } from '@20baht/elysia-oauth-provider' // or '@20baht/elysia-oauth-provider/storage/redis'
|
|
301
|
+
|
|
302
|
+
new RedisStorage(new Bun.RedisClient(process.env.REDIS_URL), { keyPrefix: 'oauth:' })
|
|
303
|
+
// or
|
|
304
|
+
import Redis from 'ioredis'
|
|
305
|
+
new RedisStorage(new Redis(process.env.REDIS_URL), { keyPrefix: 'oauth:' })
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Anything else (Postgres, SQLite, Deno KV, …) is a ~40-line adapter you own —
|
|
309
|
+
see [Writing your own adapter](#writing-your-own-adapter). The library deliberately
|
|
310
|
+
ships no SQL driver binding.
|
|
311
|
+
|
|
312
|
+
### Key layout
|
|
313
|
+
|
|
314
|
+
| Key | Value | TTL / persistence |
|
|
315
|
+
| ------------------------------------------ | --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
316
|
+
| `client:{clientId}` | client record, `clientSecretHash` (SHA-256 hex) | `clientRegistrationTTL` for DCR clients; **persistent** for `createClient` |
|
|
317
|
+
| `authreq:{id}` | validated `/authorize` params waiting for login | `authRequestTTL` |
|
|
318
|
+
| `grant:{userId}:{grantId}` | scopes, encrypted props, code hash + PKCE (until exchanged), refresh hashes | `authCodeTTL` until exchanged, then refresh lifetime (or access TTL if refresh disabled) |
|
|
319
|
+
| `token:{userId}:{grantId}:{sha256(token)}` | denormalised access-token record (one read per request) | `accessTokenTTL` |
|
|
320
|
+
| `refresh:{sha256(refreshToken)}` | `{ userId, grantId }` pointer | refresh lifetime |
|
|
321
|
+
|
|
322
|
+
Prefix scans used by the provider: `grant:{userId}:` (list/revoke a user's
|
|
323
|
+
grants), `token:{userId}:{grantId}:` (revoke a grant's tokens), `client:` and
|
|
324
|
+
`grant:` (admin only). `userId` must not contain `:`.
|
|
325
|
+
|
|
326
|
+
Opaque access tokens and authorization codes look like
|
|
327
|
+
`{userId}:{grantId}:{32 random chars}` so they can be located in one read;
|
|
328
|
+
only their SHA-256 is stored.
|
|
329
|
+
|
|
330
|
+
### Writing your own adapter
|
|
331
|
+
|
|
332
|
+
Any store that can do get/set-with-TTL/delete/prefix-list works. Values are
|
|
333
|
+
plain JSON. Example with `bun:sqlite`:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
import { Database } from 'bun:sqlite'
|
|
337
|
+
import type { OAuthStorage } from '@20baht/elysia-oauth-provider'
|
|
338
|
+
|
|
339
|
+
export class SqliteStorage implements OAuthStorage {
|
|
340
|
+
#db: Database
|
|
341
|
+
constructor(path = 'oauth.sqlite') {
|
|
342
|
+
this.#db = new Database(path)
|
|
343
|
+
this.#db.run(
|
|
344
|
+
`CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL, expires_at INTEGER)`,
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
async get<T>(key: string) {
|
|
348
|
+
const row = this.#db
|
|
349
|
+
.query<{ value: string; expires_at: number | null }, [string]>(
|
|
350
|
+
'SELECT value, expires_at FROM kv WHERE key = ?',
|
|
351
|
+
)
|
|
352
|
+
.get(key)
|
|
353
|
+
if (!row) return null
|
|
354
|
+
if (row.expires_at !== null && row.expires_at <= Date.now()) {
|
|
355
|
+
await this.delete(key)
|
|
356
|
+
return null
|
|
357
|
+
}
|
|
358
|
+
return JSON.parse(row.value) as T
|
|
359
|
+
}
|
|
360
|
+
async set<T>(key: string, value: T, opts?: { ttlSeconds?: number }) {
|
|
361
|
+
const exp = opts?.ttlSeconds === undefined ? null : Date.now() + opts.ttlSeconds * 1000
|
|
362
|
+
this.#db.run('INSERT OR REPLACE INTO kv (key, value, expires_at) VALUES (?, ?, ?)', [
|
|
363
|
+
key,
|
|
364
|
+
JSON.stringify(value),
|
|
365
|
+
exp,
|
|
366
|
+
])
|
|
367
|
+
}
|
|
368
|
+
async delete(key: string) {
|
|
369
|
+
this.#db.run('DELETE FROM kv WHERE key = ?', [key])
|
|
370
|
+
}
|
|
371
|
+
async list(prefix: string) {
|
|
372
|
+
const now = Date.now()
|
|
373
|
+
return this.#db
|
|
374
|
+
.query<{ key: string }, [string, number]>(
|
|
375
|
+
`SELECT key FROM kv WHERE key >= ? AND key < ? || X'FF' AND (expires_at IS NULL OR expires_at > ?)`,
|
|
376
|
+
)
|
|
377
|
+
.all(prefix, prefix, now) // ← simplified; see conformance suite for exact expectations
|
|
378
|
+
.map((r) => r.key)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Run the **conformance suite** against it in `bun test`:
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
import { runStorageConformance } from '@20baht/elysia-oauth-provider/storage/conformance'
|
|
387
|
+
runStorageConformance('SqliteStorage', { create: () => new SqliteStorage(':memory:') })
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
It checks JSON round-trips, reference isolation, overwrite, delete, prefix
|
|
391
|
+
listing, TTL expiry (including TTL replacement) and bulk writes.
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## Migrating from `@cloudflare/workers-oauth-provider`
|
|
396
|
+
|
|
397
|
+
| workers-oauth-provider | elysia-oauth-provider |
|
|
398
|
+
| ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
399
|
+
| `new OAuthProvider({ apiRoute, apiHandler, defaultHandler, … })` as the Worker's `fetch` | `app.use(oauthProvider({ … }))`. There is no wrapper: your routes stay yours; mark protected ones with `{ oauth: true }`. |
|
|
400
|
+
| `env.OAUTH_KV` | `storage: new RedisStorage(...)` (or any `OAuthStorage`) |
|
|
401
|
+
| `authorizeEndpoint` handled by _your_ `defaultHandler` | Plugin serves `GET /authorize`, validates, then calls `handleAuthorize`. The request is stashed for you as `authRequestId`. |
|
|
402
|
+
| `env.OAUTH_PROVIDER.parseAuthRequest(request)` | `ctx.oauthProvider.parseAuthRequest(request)` (still available) or just `getAuthRequest(id)` |
|
|
403
|
+
| `completeAuthorization({ request, userId, scope, props, metadata })` | `completeAuthorization({ authRequestId, userId, scopes, props, metadata })` (`scope` → `scopes`) |
|
|
404
|
+
| `ctx.props` in the API handler | `ctx.oauth.props` (+ `userId`, `clientId`, `scopes`, …), typed via `oauthProvider<Props>()` |
|
|
405
|
+
| `tokenEndpoint` doubles as revocation endpoint | Separate `POST /revoke` (path configurable) |
|
|
406
|
+
| `clientRegistrationEndpoint: undefined` disables DCR | `clientRegistration: false` |
|
|
407
|
+
| `clientRegistrationCallback` | `hooks.onClientRegister` |
|
|
408
|
+
| `tokenExchangeCallback` | `hooks.onTokenIssued` (observe only; props are fixed at grant time in v1) |
|
|
409
|
+
| `resourceMetadata.resource` | `resource` (+ `resourceMetadata` for the other fields) |
|
|
410
|
+
| `allowImplicitFlow`, `allowPlainPKCE`, CIMD, token exchange, EMA | not supported (OAuth 2.1 only) |
|
|
411
|
+
| `accessTokenTTL` min 60 s (KV limit) | any positive integer |
|
|
412
|
+
| `purgeExpiredData()` cron | not needed: every key carries a TTL the storage enforces |
|
|
413
|
+
| Token format `userId:grantId:secret` | same for access tokens/codes; refresh tokens are plain random strings with a `refresh:{hash}` pointer |
|
|
414
|
+
| Props encryption (AES-GCM key wrapped by token) | same scheme (`encryptProps: true` by default) |
|
|
415
|
+
|
|
416
|
+
The storage layout is close enough that a migration script from KV is
|
|
417
|
+
mechanical (`client:*` → same shape minus `authMethodExplicit`; grants/tokens
|
|
418
|
+
are short-lived, let them expire).
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## Development
|
|
423
|
+
|
|
424
|
+
```sh
|
|
425
|
+
bun install
|
|
426
|
+
bun test packages # unit + flow tests (Redis live suite runs when REDIS_URL is set)
|
|
427
|
+
bun run --filter @20baht/elysia-oauth-provider build
|
|
428
|
+
bun run example # examples/basic-mcp on :3000
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## License
|
|
432
|
+
|
|
433
|
+
MIT
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { EndpointPaths, OAuthProviderConfig } from './types.js';
|
|
2
|
+
import { type RateLimitConfig, type RateLimitRule, type RateLimitedEndpoint, type RateLimiter } from './core/rate-limit.js';
|
|
3
|
+
export interface ResolvedConfig<Props> extends Required<Pick<OAuthProviderConfig<Props>, 'issuer' | 'storage' | 'handleAuthorize' | 'accessTokenTTL' | 'refreshTokenTTL' | 'authCodeTTL' | 'authRequestTTL' | 'encryptProps' | 'cors' | 'hooks' | 'tokenFormat'>> {
|
|
4
|
+
issuerUrl: URL;
|
|
5
|
+
paths: EndpointPaths;
|
|
6
|
+
/** Absolute URLs for each endpoint. */
|
|
7
|
+
urls: EndpointPaths & {
|
|
8
|
+
metadata: string;
|
|
9
|
+
protectedResource: string;
|
|
10
|
+
};
|
|
11
|
+
resource: string | undefined;
|
|
12
|
+
resourceMetadata: NonNullable<OAuthProviderConfig<Props>['resourceMetadata']>;
|
|
13
|
+
scopesSupported: string[] | undefined;
|
|
14
|
+
clientRegistrationTTL: number | undefined;
|
|
15
|
+
clientRegistration: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
allowPublicClients: boolean;
|
|
18
|
+
maxBodyBytes: number;
|
|
19
|
+
};
|
|
20
|
+
rateLimit: ResolvedRateLimit | null;
|
|
21
|
+
}
|
|
22
|
+
interface ResolvedRateLimit {
|
|
23
|
+
limiter: RateLimiter;
|
|
24
|
+
rules: Record<RateLimitedEndpoint, RateLimitRule | null>;
|
|
25
|
+
keyFor: NonNullable<RateLimitConfig['keyFor']> | null;
|
|
26
|
+
trustProxy: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare const DEFAULT_PATHS: EndpointPaths;
|
|
29
|
+
export declare function resolveConfig<Props>(config: OAuthProviderConfig<Props>): ResolvedConfig<Props>;
|
|
30
|
+
/** RFC 6749 §3.3: scope-token = 1*( %x21 / %x23-5B / %x5D-7E ) */
|
|
31
|
+
export declare function isValidScopeToken(s: string): boolean;
|
|
32
|
+
/** RFC 8707 §2: absolute URI, no fragment. We additionally require http(s). */
|
|
33
|
+
export declare function validateResourceUri(resource: string): URL;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,cAAc,CAAC,KAAK,CAAE,SAAQ,QAAQ,CACrD,IAAI,CACF,mBAAmB,CAAC,KAAK,CAAC,EACxB,QAAQ,GACR,SAAS,GACT,iBAAiB,GACjB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,gBAAgB,GAChB,cAAc,GACd,MAAM,GACN,OAAO,GACP,aAAa,CAChB,CACF;IACC,SAAS,EAAE,GAAG,CAAC;IACf,KAAK,EAAE,aAAa,CAAC;IACrB,uCAAuC;IACvC,IAAI,EAAE,aAAa,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,gBAAgB,EAAE,WAAW,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC9E,eAAe,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACtC,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,kBAAkB,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,kBAAkB,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5F,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACrC;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC,mBAAmB,EAAE,aAAa,GAAG,IAAI,CAAC,CAAC;IACzD,MAAM,EAAE,WAAW,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC;IACtD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,aAM3B,CAAC;AAKF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,mBAAmB,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CA+F9F;AA4BD,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAazD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Extract the bearer token from an Authorization header (RFC 6750 §2.1). */
|
|
2
|
+
export declare function extractBearer(header: string | null | undefined): string | null;
|
|
3
|
+
export interface ChallengeOptions {
|
|
4
|
+
resourceMetadataUrl: string;
|
|
5
|
+
error?: 'invalid_token' | 'insufficient_scope' | 'invalid_request';
|
|
6
|
+
errorDescription?: string;
|
|
7
|
+
scope?: string[];
|
|
8
|
+
}
|
|
9
|
+
/** Build a `WWW-Authenticate: Bearer …` value (RFC 6750 §3, RFC 9728 §5.1). */
|
|
10
|
+
export declare function bearerChallenge(o: ChallengeOptions): string;
|
|
11
|
+
//# sourceMappingURL=bearer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bearer.d.ts","sourceRoot":"","sources":["../../src/core/bearer.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAI9E;AAED,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,eAAe,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;IACnE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAQ3D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** RFC 7636 §4.1: 43–128 chars of [A-Za-z0-9-._~] */
|
|
2
|
+
export declare function isValidCodeVerifier(v: string): boolean;
|
|
3
|
+
/** RFC 7636 §4.2: base64url(sha256) is always 43 chars. */
|
|
4
|
+
export declare function isValidCodeChallenge(c: string): boolean;
|
|
5
|
+
export declare function verifyPkce(verifier: string, challenge: string): Promise<boolean>;
|
|
6
|
+
//# sourceMappingURL=pkce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkce.d.ts","sourceRoot":"","sources":["../../src/core/pkce.ts"],"names":[],"mappings":"AAEA,qDAAqD;AACrD,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGtF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '../config.js';
|
|
2
|
+
import { type JwtSigner } from '../crypto/jwt.js';
|
|
3
|
+
import type { AuthRequest, ClientInfo, CompleteAuthorizationOptions, GrantSummary, PendingAuthRequest, RejectAuthorizationOptions, StoredClient, TokenEndpointAuthMethod, TokenInfo, TokenResponse } from '../types.js';
|
|
4
|
+
export interface ClientCredentials {
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret?: string;
|
|
7
|
+
method: TokenEndpointAuthMethod;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateClientInput {
|
|
10
|
+
clientId?: string;
|
|
11
|
+
redirectUris: string[];
|
|
12
|
+
clientName?: string;
|
|
13
|
+
clientUri?: string;
|
|
14
|
+
logoUri?: string;
|
|
15
|
+
policyUri?: string;
|
|
16
|
+
tosUri?: string;
|
|
17
|
+
jwksUri?: string;
|
|
18
|
+
contacts?: string[];
|
|
19
|
+
grantTypes?: string[];
|
|
20
|
+
responseTypes?: string[];
|
|
21
|
+
scope?: string;
|
|
22
|
+
tokenEndpointAuthMethod?: TokenEndpointAuthMethod;
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
/** Internal: mark as dynamically registered (applies registration TTL). */
|
|
25
|
+
dynamicallyRegistered?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Framework-agnostic OAuth engine. All state goes through `config.storage`.
|
|
29
|
+
* The Elysia plugin is a thin HTTP layer on top of this class.
|
|
30
|
+
*/
|
|
31
|
+
export declare class OAuthProviderCore<Props> {
|
|
32
|
+
#private;
|
|
33
|
+
readonly config: ResolvedConfig<Props>;
|
|
34
|
+
constructor(config: ResolvedConfig<Props>);
|
|
35
|
+
get storage(): import("../index.js").OAuthStorage;
|
|
36
|
+
get jwtSigner(): Promise<JwtSigner> | null;
|
|
37
|
+
createClient(input: CreateClientInput): Promise<ClientInfo>;
|
|
38
|
+
getStoredClient(clientId: string): Promise<StoredClient | null>;
|
|
39
|
+
lookupClient(clientId: string): Promise<ClientInfo | null>;
|
|
40
|
+
updateClient(clientId: string, updates: Partial<Omit<CreateClientInput, 'clientId' | 'dynamicallyRegistered'>>): Promise<ClientInfo | null>;
|
|
41
|
+
/** Delete a client and revoke every grant issued to it. */
|
|
42
|
+
deleteClient(clientId: string): Promise<void>;
|
|
43
|
+
listClients(): Promise<ClientInfo[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Authenticate a client at the token/revocation endpoint.
|
|
46
|
+
* Throws `invalid_client` (401) on failure.
|
|
47
|
+
*/
|
|
48
|
+
authenticateClient(creds: ClientCredentials): Promise<StoredClient>;
|
|
49
|
+
/**
|
|
50
|
+
* Validate `GET /authorize` query parameters. Errors before the client and
|
|
51
|
+
* redirect URI are validated have no `redirectUri` (render locally).
|
|
52
|
+
*/
|
|
53
|
+
parseAuthRequest(url: URL | string): Promise<{
|
|
54
|
+
authRequest: AuthRequest;
|
|
55
|
+
client: ClientInfo;
|
|
56
|
+
}>;
|
|
57
|
+
/** Persist a validated request so the login flow only needs to carry an opaque id. */
|
|
58
|
+
stashAuthRequest(authRequest: AuthRequest): Promise<PendingAuthRequest>;
|
|
59
|
+
getAuthRequest(id: string): Promise<PendingAuthRequest | null>;
|
|
60
|
+
completeAuthorization(o: CompleteAuthorizationOptions<Props>): Promise<{
|
|
61
|
+
redirectTo: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** Send the user back to the client with an error (e.g. they declined consent). */
|
|
64
|
+
rejectAuthorization(o: RejectAuthorizationOptions): Promise<{
|
|
65
|
+
redirectTo: string;
|
|
66
|
+
}>;
|
|
67
|
+
exchangeAuthorizationCode(o: {
|
|
68
|
+
client: StoredClient;
|
|
69
|
+
code: string;
|
|
70
|
+
codeVerifier: string | undefined;
|
|
71
|
+
redirectUri: string | undefined;
|
|
72
|
+
resource: string | undefined;
|
|
73
|
+
requestedScope: string | undefined;
|
|
74
|
+
}): Promise<TokenResponse>;
|
|
75
|
+
refreshAccessToken(o: {
|
|
76
|
+
client: StoredClient;
|
|
77
|
+
refreshToken: string;
|
|
78
|
+
requestedScope: string | undefined;
|
|
79
|
+
resource: string | undefined;
|
|
80
|
+
}): Promise<TokenResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Verify a bearer token. Returns `null` when invalid/expired/revoked.
|
|
83
|
+
* Throws `OAuthError('invalid_token')` when the token is valid but its
|
|
84
|
+
* audience does not cover `requestUrl`.
|
|
85
|
+
*/
|
|
86
|
+
verifyAccessToken(token: string, requestUrl?: string): Promise<TokenInfo<Props> | null>;
|
|
87
|
+
/**
|
|
88
|
+
* RFC 7009 revocation. Never reveals whether the token existed. Only tokens
|
|
89
|
+
* owned by `client` are affected.
|
|
90
|
+
*/
|
|
91
|
+
revokeToken(o: {
|
|
92
|
+
client: StoredClient;
|
|
93
|
+
token: string;
|
|
94
|
+
tokenTypeHint?: string;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
/** Delete a grant, all its access tokens and refresh pointers. */
|
|
97
|
+
revokeGrant(grantId: string, userId: string): Promise<void>;
|
|
98
|
+
listUserGrants(userId: string): Promise<GrantSummary[]>;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/core/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAUnE,OAAO,KAAK,EAEV,WAAW,EACX,UAAU,EACV,4BAA4B,EAE5B,YAAY,EACZ,kBAAkB,EAElB,0BAA0B,EAC1B,YAAY,EACZ,uBAAuB,EACvB,SAAS,EACT,aAAa,EACd,MAAM,aAAa,CAAC;AAQrB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,uBAAuB,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,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