@dokebi/oauth 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/AI.md +469 -0
- package/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/bounded.d.ts +9 -0
- package/dist/bounded.js +36 -0
- package/dist/cimd.d.ts +97 -0
- package/dist/cimd.js +384 -0
- package/dist/clients.d.ts +85 -0
- package/dist/clients.js +303 -0
- package/dist/dependency.d.ts +4 -0
- package/dist/dependency.js +14 -0
- package/dist/errors.d.ts +87 -0
- package/dist/errors.js +34 -0
- package/dist/extension.d.ts +161 -0
- package/dist/extension.js +108 -0
- package/dist/grants.d.ts +126 -0
- package/dist/grants.js +280 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +28 -0
- package/dist/install.d.ts +33 -0
- package/dist/install.js +112 -0
- package/dist/live.d.ts +47 -0
- package/dist/live.js +105 -0
- package/dist/options.d.ts +173 -0
- package/dist/options.js +521 -0
- package/dist/plugin.d.ts +113 -0
- package/dist/plugin.js +766 -0
- package/dist/protocol.d.ts +81 -0
- package/dist/protocol.js +249 -0
- package/dist/server.d.ts +148 -0
- package/dist/server.js +1516 -0
- package/dist/signin.d.ts +40 -0
- package/dist/signin.js +86 -0
- package/dist/store-redis.d.ts +38 -0
- package/dist/store-redis.js +173 -0
- package/dist/store-sql.d.ts +46 -0
- package/dist/store-sql.js +363 -0
- package/dist/store.d.ts +126 -0
- package/dist/store.js +266 -0
- package/options.schema.json +633 -0
- package/package.json +143 -4
- package/templates/extension.ts +45 -0
- package/templates/migrations/dokebi_oauth.ts +117 -0
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { addExtensionDependencies, createExtension, definePlugin, definePoint, optionalDependency, providerDependency, readExtensionEntry, } from '@dokebi/core';
|
|
3
|
+
import { diagnostics } from '@dokebi/core/libraries';
|
|
4
|
+
import { appUrlMatch, pluginRouteIds } from '@dokebi/web/points';
|
|
5
|
+
import { httpsFetch } from './cimd.js';
|
|
6
|
+
import { ClientDirectory, DYNAMIC_ID } from './clients.js';
|
|
7
|
+
import { OAuthError } from './errors.js';
|
|
8
|
+
import { EXTENSION_FILE, OAuthExtension, oauthHooks, REQUIRED_HOOKS, } from './extension.js';
|
|
9
|
+
import { GrantService } from './grants.js';
|
|
10
|
+
import { CIMD_DEFAULT, options as declaration, GRANT_MAX_DAYS, LIMITS_DEFAULT, LIVE_DEFAULT, OAUTH_ROUTE_KEYS, PATHS_DEFAULT, STORE_DEFAULT, } from './options.js';
|
|
11
|
+
import { metadataLocation, redirectProblem, resourceKey } from './protocol.js';
|
|
12
|
+
import { BAD_JSON, challengeOf, formBody, NO_SCOPE, OAuthServer, } from './server.js';
|
|
13
|
+
import { RESERVED } from './signin.js';
|
|
14
|
+
import { MemoryOAuthStore } from './store.js';
|
|
15
|
+
import { RedisOAuthStore } from './store-redis.js';
|
|
16
|
+
import { openSqlStore } from './store-sql.js';
|
|
17
|
+
/**
|
|
18
|
+
* The `core:describe` point of @dokebi/core 0.4.2 (D-0077 B), declared by name (its identity) so
|
|
19
|
+
* this package keeps working with older cores, which never describe.
|
|
20
|
+
*/
|
|
21
|
+
const describePoint = definePoint('core:describe');
|
|
22
|
+
/** dokebi-web 0.4.3 or later: `routeConfig` and `routeHook` (D-0076 §5). */
|
|
23
|
+
const web = providerDependency({
|
|
24
|
+
name: 'dokebi-web',
|
|
25
|
+
version: '^0.4.3',
|
|
26
|
+
packageName: '@dokebi/web',
|
|
27
|
+
load: () => import('@dokebi/web'),
|
|
28
|
+
});
|
|
29
|
+
/** dokebi-auth 0.4.1 or later: pair families, audiences, `peek`, `api.of(request, { audience })`. */
|
|
30
|
+
const auth = providerDependency({
|
|
31
|
+
name: 'dokebi-auth',
|
|
32
|
+
version: '^0.4.1',
|
|
33
|
+
packageName: '@dokebi/auth',
|
|
34
|
+
load: () => import('@dokebi/auth'),
|
|
35
|
+
});
|
|
36
|
+
const session = providerDependency({
|
|
37
|
+
name: 'dokebi-session',
|
|
38
|
+
version: '^0.4.4',
|
|
39
|
+
packageName: '@dokebi/session',
|
|
40
|
+
load: () => import('@dokebi/session'),
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Only to learn whether @dokebi/csrf is registered (the consent POST needs it): optional, never
|
|
44
|
+
* created, never imported; declared so that csrf, when present, sets up first.
|
|
45
|
+
*/
|
|
46
|
+
const csrf = Object.freeze({
|
|
47
|
+
name: 'dokebi-csrf',
|
|
48
|
+
version: '^0.4.0',
|
|
49
|
+
optional: true,
|
|
50
|
+
});
|
|
51
|
+
const db = providerDependency({
|
|
52
|
+
name: 'dokebi-db',
|
|
53
|
+
version: '^0.4.0',
|
|
54
|
+
packageName: '@dokebi/db',
|
|
55
|
+
load: () => import('@dokebi/db'),
|
|
56
|
+
});
|
|
57
|
+
const redis = providerDependency({
|
|
58
|
+
name: 'dokebi-redis',
|
|
59
|
+
version: '^0.4.0',
|
|
60
|
+
packageName: '@dokebi/redis',
|
|
61
|
+
load: () => import('@dokebi/redis'),
|
|
62
|
+
});
|
|
63
|
+
const rateLimit = optionalDependency({
|
|
64
|
+
name: 'dokebi-rate-limit',
|
|
65
|
+
version: '^0.1.1',
|
|
66
|
+
});
|
|
67
|
+
const OAUTH = Symbol('dokebi.oauth.request');
|
|
68
|
+
const NONE = Object.freeze({
|
|
69
|
+
grant: undefined,
|
|
70
|
+
resource: undefined,
|
|
71
|
+
scopes: Object.freeze([]),
|
|
72
|
+
has: () => false,
|
|
73
|
+
authTime: null,
|
|
74
|
+
});
|
|
75
|
+
/** The slot of the route check, for `live()`. */
|
|
76
|
+
const SLOTS = new WeakMap();
|
|
77
|
+
function requestOAuth(slot) {
|
|
78
|
+
const scopes = new Set(slot.scopes);
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
grant: slot.grant,
|
|
81
|
+
resource: slot.resource,
|
|
82
|
+
scopes: slot.scopes,
|
|
83
|
+
has: (scope) => scopes.has(scope),
|
|
84
|
+
authTime: slot.authTime,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function required() {
|
|
88
|
+
return new OAuthError('EXTENSION_REQUIRED', 'dokebi-oauth needs renderConsent(): the application draws the consent page', {
|
|
89
|
+
fix: `Implement protected override renderConsent(request, reply, consent, context) in the OAuthExtension subclass of ${EXTENSION_FILE} (render your consent view with consent.client, consent.redirectHost, consent.warning and consent.scopes; post request and decision to consent.action).`,
|
|
90
|
+
data: { hooks: [...REQUIRED_HOOKS] },
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** How this plugin reads its entry module (core readExtensionEntry, D-0111 §7). */
|
|
94
|
+
const ENTRY = {
|
|
95
|
+
plugin: 'dokebi-oauth',
|
|
96
|
+
error: OAuthError,
|
|
97
|
+
file: EXTENSION_FILE,
|
|
98
|
+
base: 'OAuthExtension',
|
|
99
|
+
entry: 'OAuth entry',
|
|
100
|
+
noun: 'OAuth',
|
|
101
|
+
};
|
|
102
|
+
/** The entry as given: resolved once, when the factory derives dependencies. */
|
|
103
|
+
class OAuthEntryInput {
|
|
104
|
+
#extension;
|
|
105
|
+
#resolved;
|
|
106
|
+
constructor(input) {
|
|
107
|
+
this.#extension = readExtensionEntry(input, ENTRY).extension;
|
|
108
|
+
}
|
|
109
|
+
resolve(options) {
|
|
110
|
+
this.#resolved ??= this.#resolve(options);
|
|
111
|
+
return this.#resolved;
|
|
112
|
+
}
|
|
113
|
+
#resolve(options) {
|
|
114
|
+
if (this.#extension === undefined)
|
|
115
|
+
throw required();
|
|
116
|
+
const created = createExtension(this.#extension, OAuthExtension);
|
|
117
|
+
const overridden = new Set(created.overridden);
|
|
118
|
+
if (!overridden.has('renderConsent'))
|
|
119
|
+
throw required();
|
|
120
|
+
const hooks = oauthHooks(created.instance);
|
|
121
|
+
const dependencies = new Map([
|
|
122
|
+
[web.name, web],
|
|
123
|
+
[auth.name, auth],
|
|
124
|
+
[session.name, session],
|
|
125
|
+
[csrf.name, csrf],
|
|
126
|
+
[rateLimit.name, rateLimit],
|
|
127
|
+
]);
|
|
128
|
+
const driver = (options.store ?? STORE_DEFAULT).driver;
|
|
129
|
+
if (driver === 'sql')
|
|
130
|
+
dependencies.set(db.name, db);
|
|
131
|
+
if (driver === 'redis')
|
|
132
|
+
dependencies.set(redis.name, redis);
|
|
133
|
+
if (overridden.has('dependencies')) {
|
|
134
|
+
const declared = hooks.dependencies();
|
|
135
|
+
addExtensionDependencies(dependencies, declared, {
|
|
136
|
+
error: OAuthError,
|
|
137
|
+
code: 'INVALID_HOOK_RESULT',
|
|
138
|
+
file: EXTENSION_FILE,
|
|
139
|
+
data: { hook: 'dependencies' },
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return Object.freeze({
|
|
143
|
+
hooks,
|
|
144
|
+
overridden,
|
|
145
|
+
dependencies: Object.freeze([...dependencies.values()]),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** The largest `maxAge` of a route (whole seconds, like the max_age of an authorization request). */
|
|
150
|
+
const MAX_AGE_LIMIT = 999_999_999;
|
|
151
|
+
const LOCAL_HOST = (host) => host === 'localhost' || host.endsWith('.localhost') || host === '127.0.0.1' || host === '[::1]';
|
|
152
|
+
function invalidOptions(message, fix) {
|
|
153
|
+
return new OAuthError('INVALID_OPTIONS', message, { fix });
|
|
154
|
+
}
|
|
155
|
+
/** The checks the schema cannot make; the resources with their metadata locations. */
|
|
156
|
+
function resolveResources(options) {
|
|
157
|
+
const issuer = new URL(options.issuer);
|
|
158
|
+
if (issuer.protocol === 'http:' && !LOCAL_HOST(issuer.hostname))
|
|
159
|
+
throw invalidOptions('dokebi-oauth.issuer must use https (http only on localhost and *.localhost)', 'Set options.dokebi-oauth.issuer to the public https origin of this app (https://example.com).');
|
|
160
|
+
const resources = new Map();
|
|
161
|
+
const keys = new Map();
|
|
162
|
+
const paths = new Map();
|
|
163
|
+
for (const [id, settings] of Object.entries(options.resources)) {
|
|
164
|
+
const key = resourceKey(settings.uri);
|
|
165
|
+
const where = `dokebi-oauth.resources.${id}`;
|
|
166
|
+
if (key === undefined)
|
|
167
|
+
throw invalidOptions(`${where}.uri is not an absolute http(s) URI without a fragment`, `Set ${where}.uri to the URI clients use, for example https://example.com/mcp.`);
|
|
168
|
+
const url = new URL(settings.uri);
|
|
169
|
+
if (url.protocol === 'http:' && !LOCAL_HOST(url.hostname))
|
|
170
|
+
throw invalidOptions(`${where}.uri must use https (http only on localhost)`, `Set ${where}.uri to an https URI.`);
|
|
171
|
+
const same = keys.get(key);
|
|
172
|
+
if (same)
|
|
173
|
+
throw invalidOptions(`${where}.uri names the same resource as resources.${same}`, 'Give each resource its own URI (one resource, one id).');
|
|
174
|
+
keys.set(key, id);
|
|
175
|
+
const location = metadataLocation(settings.uri);
|
|
176
|
+
const taken = paths.get(location.path);
|
|
177
|
+
if (taken)
|
|
178
|
+
throw invalidOptions(`${where}.uri has the same metadata path as resources.${taken}`, 'Give the resources different paths (their metadata lives at /.well-known/oauth-protected-resource<path>).');
|
|
179
|
+
paths.set(location.path, id);
|
|
180
|
+
const reserved = Object.keys(settings.scopes).filter((scope) => scope.startsWith(RESERVED));
|
|
181
|
+
if (reserved.length)
|
|
182
|
+
throw invalidOptions(`${where}.scopes may not declare ${reserved.join(' ')}: names under ${RESERVED} are this plugin's`, `${NO_SCOPE} and ${RESERVED}auth_time:… are abilities of this plugin's tokens (D-0122); rename that scope.`);
|
|
183
|
+
const unknown = settings.defaultScopes.filter((scope) => !Object.hasOwn(settings.scopes, scope));
|
|
184
|
+
if (unknown.length)
|
|
185
|
+
throw invalidOptions(`${where}.defaultScopes names undeclared scopes: ${unknown.join(' ')}`, `List only scopes of ${where}.scopes in defaultScopes.`);
|
|
186
|
+
resources.set(id, Object.freeze({
|
|
187
|
+
id,
|
|
188
|
+
uri: settings.uri,
|
|
189
|
+
key,
|
|
190
|
+
name: settings.name ?? id,
|
|
191
|
+
scopes: Object.freeze({ ...settings.scopes }),
|
|
192
|
+
defaultScopes: Object.freeze([...settings.defaultScopes]),
|
|
193
|
+
metadataUrl: location.url,
|
|
194
|
+
metadataPath: location.path,
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
for (const [id, client] of Object.entries(options.clients)) {
|
|
198
|
+
if (DYNAMIC_ID.test(id))
|
|
199
|
+
throw invalidOptions(`dokebi-oauth.clients.${id}: client ids starting with dcr_ belong to dynamic registration`, 'Rename the pre-registered client.');
|
|
200
|
+
for (const uri of client.redirectUris) {
|
|
201
|
+
const problem = redirectProblem(uri);
|
|
202
|
+
if (problem)
|
|
203
|
+
throw invalidOptions(`dokebi-oauth.clients.${id}.redirectUris: ${problem}`, 'Use exact https redirect URIs (or http on 127.0.0.1, [::1] or localhost).');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return resources;
|
|
207
|
+
}
|
|
208
|
+
/** web.routeConfig check of `config.oauth`: a sentence when wrong. */
|
|
209
|
+
function checkRouteSetting(value, resources) {
|
|
210
|
+
if (value === undefined)
|
|
211
|
+
return undefined;
|
|
212
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
213
|
+
return `must be { resource, scopes?, maxAge? }, not ${JSON.stringify(value) ?? String(value)}`;
|
|
214
|
+
const setting = value;
|
|
215
|
+
const unknownKeys = Object.keys(setting).filter((key) => key !== 'resource' && key !== 'scopes' && key !== 'maxAge');
|
|
216
|
+
if (unknownKeys.length)
|
|
217
|
+
return `unknown key ${unknownKeys.join(', ')} (resource, scopes, maxAge)`;
|
|
218
|
+
const maxAge = setting.maxAge;
|
|
219
|
+
if (maxAge !== undefined &&
|
|
220
|
+
(typeof maxAge !== 'number' ||
|
|
221
|
+
!Number.isInteger(maxAge) ||
|
|
222
|
+
maxAge < 0 ||
|
|
223
|
+
maxAge > MAX_AGE_LIMIT))
|
|
224
|
+
return `maxAge must be whole seconds from 0 to ${MAX_AGE_LIMIT}`;
|
|
225
|
+
const resource = typeof setting.resource === 'string' ? resources.get(setting.resource) : undefined;
|
|
226
|
+
if (!resource)
|
|
227
|
+
return `resource ${JSON.stringify(setting.resource)} is not one of options.dokebi-oauth.resources (${[...resources.keys()].join(', ')})`;
|
|
228
|
+
const scopes = setting.scopes;
|
|
229
|
+
if (scopes === undefined)
|
|
230
|
+
return undefined;
|
|
231
|
+
if (!Array.isArray(scopes) || scopes.some((scope) => typeof scope !== 'string'))
|
|
232
|
+
return 'scopes must be a list of scope names';
|
|
233
|
+
const undeclared = scopes.filter((scope) => !Object.hasOwn(resource.scopes, scope));
|
|
234
|
+
if (undeclared.length)
|
|
235
|
+
return `scopes ${undeclared.join(' ')} are not declared by resources.${resource.id}.scopes`;
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
class OAuthRuntime {
|
|
239
|
+
#options;
|
|
240
|
+
#resolved;
|
|
241
|
+
#settings;
|
|
242
|
+
#protected = 0;
|
|
243
|
+
constructor(options, resolved, settings) {
|
|
244
|
+
this.#options = options;
|
|
245
|
+
this.#resolved = resolved;
|
|
246
|
+
this.#settings = settings;
|
|
247
|
+
}
|
|
248
|
+
#declared(dependency) {
|
|
249
|
+
const declared = this.#resolved.dependencies.find((item) => item.name === dependency?.name);
|
|
250
|
+
return declared ?? dependency;
|
|
251
|
+
}
|
|
252
|
+
async #store(context) {
|
|
253
|
+
const settings = this.#options.store ?? STORE_DEFAULT;
|
|
254
|
+
const logger = context.logger.child({ store: settings.driver });
|
|
255
|
+
if (settings.driver === 'memory') {
|
|
256
|
+
// D-0161: grants and tokens would be known to one process only and lost on restart.
|
|
257
|
+
const where = context.runtime.describing
|
|
258
|
+
? undefined
|
|
259
|
+
: context.runtime.role === 'worker'
|
|
260
|
+
? 'a cluster worker'
|
|
261
|
+
: process.env.NODE_ENV === 'production' && process.env.DOKEBI_LOCAL_RUN !== '1'
|
|
262
|
+
? 'production'
|
|
263
|
+
: undefined;
|
|
264
|
+
if (where)
|
|
265
|
+
throw new OAuthError('INVALID_OPTIONS', `dokebi-oauth.store is memory in ${where}: a code or token issued by one process would be unknown to the others and lost on restart`, {
|
|
266
|
+
fix: 'Set options.dokebi-oauth.store: { driver: redis, connection: <a dokebi-redis connection> } (npx dokebi add @dokebi/redis) or { driver: sql, connection: <a dokebi-db connection> }.',
|
|
267
|
+
data: { store: 'memory', where },
|
|
268
|
+
});
|
|
269
|
+
return new MemoryOAuthStore(settings.maxGrants, settings.maxGrantsPerUser, settings.maxClients, {
|
|
270
|
+
maxCodes: settings.maxCodes,
|
|
271
|
+
fullRetryAfterMs: this.#options.storeFullRetryAfterMs,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (settings.driver === 'sql') {
|
|
275
|
+
const sql = settings;
|
|
276
|
+
let resource;
|
|
277
|
+
try {
|
|
278
|
+
resource = context.getDependency(this.#declared(db)).resource(sql.connection);
|
|
279
|
+
}
|
|
280
|
+
catch (cause) {
|
|
281
|
+
throw new OAuthError('INVALID_OPTIONS', 'The OAuth SQL connection is not configured', {
|
|
282
|
+
cause,
|
|
283
|
+
fix: 'Name a connection of options.dokebi-db.connections in options.dokebi-oauth.store.connection.',
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return openSqlStore(resource, sql, logger, context.runtime.describing === true);
|
|
287
|
+
}
|
|
288
|
+
const options = settings;
|
|
289
|
+
let connection;
|
|
290
|
+
try {
|
|
291
|
+
connection = context.getDependency(this.#declared(redis)).connection(options.connection);
|
|
292
|
+
}
|
|
293
|
+
catch (cause) {
|
|
294
|
+
throw new OAuthError('INVALID_OPTIONS', 'The OAuth Redis connection is not configured', {
|
|
295
|
+
cause,
|
|
296
|
+
fix: 'Name a connection of options.dokebi-redis.connections in options.dokebi-oauth.store.connection.',
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
logger.log('debug', 'OAuth Redis store ready', {
|
|
300
|
+
connection: options.connection,
|
|
301
|
+
namespace: options.namespace,
|
|
302
|
+
});
|
|
303
|
+
return new RedisOAuthStore(connection, options.namespace, {
|
|
304
|
+
codeGraceMs: this.#options.codeGraceMs,
|
|
305
|
+
clientUnusedMs: this.#options.clientUnusedMs,
|
|
306
|
+
refreshMs: this.#options.refreshMs,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
#limiter(context) {
|
|
310
|
+
const policy = this.#options.rateLimit?.policy;
|
|
311
|
+
if (policy === undefined)
|
|
312
|
+
return undefined;
|
|
313
|
+
const api = context.getOptionalDependency(rateLimit);
|
|
314
|
+
if (api === undefined)
|
|
315
|
+
throw new OAuthError('RATE_LIMIT_REQUIRED', 'dokebi-oauth.rateLimit is set but @dokebi/rate-limit is not registered', {
|
|
316
|
+
fix: 'npx dokebi add @dokebi/rate-limit (and give it the policy), or remove options.dokebi-oauth.rateLimit.',
|
|
317
|
+
});
|
|
318
|
+
if (!api.names.includes(policy))
|
|
319
|
+
throw new OAuthError('RATE_LIMIT_REQUIRED', `dokebi-oauth.rateLimit.policy ${policy} is not a policy of @dokebi/rate-limit`, {
|
|
320
|
+
fix: `Add policies.${policy} to options.dokebi-rate-limit, or use one of: ${api.names.join(', ')}.`,
|
|
321
|
+
data: { policy },
|
|
322
|
+
});
|
|
323
|
+
return api.limiter(policy);
|
|
324
|
+
}
|
|
325
|
+
async setup(context) {
|
|
326
|
+
const started = performance.now();
|
|
327
|
+
const options = this.#options;
|
|
328
|
+
const logger = context.logger;
|
|
329
|
+
const resources = resolveResources(options);
|
|
330
|
+
const server = context.getDependency(web);
|
|
331
|
+
const authApi = context.getDependency(auth);
|
|
332
|
+
const sessionApi = context.getDependency(session);
|
|
333
|
+
if (!authApi.realms.includes(options.realm))
|
|
334
|
+
throw new OAuthError('INVALID_OPTIONS', `dokebi-oauth.realm ${options.realm} is not a realm of dokebi-auth`, {
|
|
335
|
+
fix: `Use one of: ${authApi.realms.join(', ')}.`,
|
|
336
|
+
});
|
|
337
|
+
const realmApi = authApi.realm(options.realm);
|
|
338
|
+
const store = await this.#store(context);
|
|
339
|
+
if (store.close)
|
|
340
|
+
context.defer(async () => {
|
|
341
|
+
try {
|
|
342
|
+
await store.close?.();
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
diagnostics.logError(logger, 'OAuth store did not close cleanly', 'OAUTH_STORE_CLOSE_FAILED', error, {
|
|
346
|
+
store: store.name,
|
|
347
|
+
});
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
const grants = new GrantService({
|
|
352
|
+
store,
|
|
353
|
+
realm: options.realm,
|
|
354
|
+
auth: realmApi,
|
|
355
|
+
logger,
|
|
356
|
+
cacheMs: options.grantCacheMs,
|
|
357
|
+
limits: {
|
|
358
|
+
grantTouchMs: options.grantTouchMs,
|
|
359
|
+
maxCachedGrants: options.maxCachedGrants,
|
|
360
|
+
codeGraceMs: options.codeGraceMs,
|
|
361
|
+
clientUnusedMs: options.clientUnusedMs,
|
|
362
|
+
refreshMs: options.refreshMs,
|
|
363
|
+
storeRetryAfterMs: options.storeRetryAfterMs,
|
|
364
|
+
storeFullRetryAfterMs: options.storeFullRetryAfterMs,
|
|
365
|
+
logRepeatWindowMs: options.logRepeatWindowMs,
|
|
366
|
+
maxPerClient: options.grant?.maxPerClient ?? LIMITS_DEFAULT.maxPerClient,
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
context.defer(() => grants.flush());
|
|
370
|
+
const cimd = options.cimd ?? CIMD_DEFAULT;
|
|
371
|
+
const clients = new ClientDirectory({
|
|
372
|
+
registered: options.clients,
|
|
373
|
+
cimd,
|
|
374
|
+
fetch: this.#settings.cimdFetch ?? httpsFetch({ maxHeaderBytes: cimd.maxHeaderBytes }),
|
|
375
|
+
findDynamic: (id) => grants.call('findClient', () => store.findClient(id)),
|
|
376
|
+
maxTrackedAddresses: options.maxTrackedAddresses,
|
|
377
|
+
});
|
|
378
|
+
const hookContext = Object.freeze({
|
|
379
|
+
realm: options.realm,
|
|
380
|
+
app: context.app,
|
|
381
|
+
getDependency: (dependency) => context.getDependency(this.#declared(dependency)),
|
|
382
|
+
logger,
|
|
383
|
+
signal: context.signal,
|
|
384
|
+
});
|
|
385
|
+
const paths = options.paths ?? PATHS_DEFAULT;
|
|
386
|
+
const oauth = new OAuthServer({
|
|
387
|
+
issuer: options.issuer,
|
|
388
|
+
realm: options.realm,
|
|
389
|
+
paths,
|
|
390
|
+
resources,
|
|
391
|
+
clients,
|
|
392
|
+
grants,
|
|
393
|
+
auth: authApi,
|
|
394
|
+
realmApi,
|
|
395
|
+
session: (request) => sessionApi.of(request),
|
|
396
|
+
hooks: this.#resolved.hooks,
|
|
397
|
+
overridden: this.#resolved.overridden,
|
|
398
|
+
hookContext,
|
|
399
|
+
accessMs: options.accessMs,
|
|
400
|
+
refreshMs: options.refreshMs,
|
|
401
|
+
grantMs: (options.grant?.maxDays ?? GRANT_MAX_DAYS) * 86_400_000,
|
|
402
|
+
clientGrantMs: new Map(Object.entries(options.clients).flatMap(([id, client]) => client.grant === undefined ? [] : [[id, client.grant.maxDays * 86_400_000]])),
|
|
403
|
+
liveTiming: options.live ?? LIVE_DEFAULT,
|
|
404
|
+
codeMs: options.codeMs,
|
|
405
|
+
grantCacheMs: options.grantCacheMs,
|
|
406
|
+
registration: options.registration,
|
|
407
|
+
cimd: cimd.enabled,
|
|
408
|
+
limiter: this.#limiter(context),
|
|
409
|
+
logger,
|
|
410
|
+
limits: {
|
|
411
|
+
pendingMs: options.pendingMs,
|
|
412
|
+
maxPending: options.maxPending,
|
|
413
|
+
registrationLimit: options.registrationLimit,
|
|
414
|
+
registrationWindowMs: options.registrationWindowMs,
|
|
415
|
+
maxTrackedAddresses: options.maxTrackedAddresses,
|
|
416
|
+
maxCachedGrants: options.maxCachedGrants,
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
this.#routes(server, oauth, paths, options, resources, logger);
|
|
420
|
+
// config.oauth: the route's resource and scopes (checked at start by dokebi-web).
|
|
421
|
+
server.routeConfig({
|
|
422
|
+
key: 'oauth',
|
|
423
|
+
plugin: 'dokebi-oauth',
|
|
424
|
+
check: (value) => checkRouteSetting(value, resources),
|
|
425
|
+
});
|
|
426
|
+
const protectedRoutes = [];
|
|
427
|
+
server.routeHook({
|
|
428
|
+
plugin: 'dokebi-oauth',
|
|
429
|
+
route: (route) => {
|
|
430
|
+
const setting = route.config.oauth;
|
|
431
|
+
if (setting === undefined)
|
|
432
|
+
return undefined;
|
|
433
|
+
if (route.method !== 'HEAD')
|
|
434
|
+
this.#protected++;
|
|
435
|
+
const problem = checkRouteSetting(setting, resources);
|
|
436
|
+
if (problem !== undefined)
|
|
437
|
+
// Fail closed until the start fails on dokebi-web's check of the same value.
|
|
438
|
+
return {
|
|
439
|
+
preValidation: async () => {
|
|
440
|
+
throw new OAuthError('INVALID_ROUTE_CONFIG', `config.oauth of this route: ${problem}`);
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
const { resource, scopes = [], maxAge } = setting;
|
|
444
|
+
const needed = Object.freeze([...scopes]);
|
|
445
|
+
// The HEAD twin of a GET is protected too, but listed once.
|
|
446
|
+
if (route.method !== 'HEAD')
|
|
447
|
+
protectedRoutes.push({
|
|
448
|
+
method: route.method,
|
|
449
|
+
url: route.url,
|
|
450
|
+
resource,
|
|
451
|
+
scopes: [...needed],
|
|
452
|
+
...(maxAge === undefined ? {} : { maxAge }),
|
|
453
|
+
});
|
|
454
|
+
return {
|
|
455
|
+
preValidation: async (request) => {
|
|
456
|
+
const slot = await oauth.authenticate(request, resource, needed, maxAge ?? null);
|
|
457
|
+
request[OAUTH] = requestOAuth(slot);
|
|
458
|
+
SLOTS.set(request, slot);
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
// request.oauth (created by the route check) and the challenge header of its errors.
|
|
464
|
+
const attach = async (scope) => {
|
|
465
|
+
scope.decorateRequest(OAUTH, null);
|
|
466
|
+
scope.decorateRequest('oauth', {
|
|
467
|
+
getter() {
|
|
468
|
+
return this[OAUTH] ?? NONE;
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
scope.addHook('onError', (_request, reply, error, done) => {
|
|
472
|
+
const challenge = challengeOf(error);
|
|
473
|
+
if (challenge && !reply.sent)
|
|
474
|
+
reply.header('www-authenticate', challenge);
|
|
475
|
+
done();
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
attach[Symbol.for('skip-override')] = true;
|
|
479
|
+
server.register(attach, {});
|
|
480
|
+
if (context.getOptionalDependency(csrf) === undefined)
|
|
481
|
+
logger.log('warn', 'The OAuth consent form has no CSRF protection: install @dokebi/csrf', {
|
|
482
|
+
code: 'OAUTH_CSRF_MISSING',
|
|
483
|
+
fix: 'npx dokebi add @dokebi/csrf',
|
|
484
|
+
});
|
|
485
|
+
const known = (resource) => {
|
|
486
|
+
const found = typeof resource === 'string' ? resources.get(resource) : undefined;
|
|
487
|
+
if (!found)
|
|
488
|
+
throw new OAuthError('INVALID_ARGUMENT', `There is no resource ${String(resource)}`, {
|
|
489
|
+
fix: `Use one of: ${[...resources.keys()].join(', ')}.`,
|
|
490
|
+
});
|
|
491
|
+
return found;
|
|
492
|
+
};
|
|
493
|
+
const api = Object.freeze({
|
|
494
|
+
issuer: options.issuer,
|
|
495
|
+
realm: options.realm,
|
|
496
|
+
resources: Object.freeze([...resources.keys()]),
|
|
497
|
+
grants,
|
|
498
|
+
async authenticate(request, settings) {
|
|
499
|
+
const maxAge = settings?.maxAge;
|
|
500
|
+
if (maxAge !== undefined &&
|
|
501
|
+
(!Number.isInteger(maxAge) || maxAge < 0 || maxAge > MAX_AGE_LIMIT))
|
|
502
|
+
throw new OAuthError('INVALID_ARGUMENT', `maxAge must be whole seconds from 0 to ${MAX_AGE_LIMIT}`);
|
|
503
|
+
const slot = await oauth.authenticate(request, settings?.resource, settings?.scopes ?? [], maxAge ?? null);
|
|
504
|
+
request[OAUTH] = requestOAuth(slot);
|
|
505
|
+
SLOTS.set(request, slot);
|
|
506
|
+
return slot.grant;
|
|
507
|
+
},
|
|
508
|
+
live: (request) => oauth.live(request, SLOTS.get(request)),
|
|
509
|
+
of: (request) => request[OAUTH] ?? NONE,
|
|
510
|
+
metadataUrl: (resource) => known(resource).metadataUrl,
|
|
511
|
+
resourceInfo: (resource) => {
|
|
512
|
+
const found = known(resource);
|
|
513
|
+
return Object.freeze({
|
|
514
|
+
id: found.id,
|
|
515
|
+
uri: found.uri,
|
|
516
|
+
name: found.name,
|
|
517
|
+
scopes: found.scopes,
|
|
518
|
+
defaultScopes: found.defaultScopes,
|
|
519
|
+
metadataUrl: found.metadataUrl,
|
|
520
|
+
});
|
|
521
|
+
},
|
|
522
|
+
});
|
|
523
|
+
logger.log('debug', 'OAuth setup finished', {
|
|
524
|
+
issuer: options.issuer,
|
|
525
|
+
app: appList(options.app) ?? null,
|
|
526
|
+
realm: options.realm,
|
|
527
|
+
resources: [...resources.keys()],
|
|
528
|
+
clients: Object.keys(options.clients).length,
|
|
529
|
+
cimd: { enabled: cimd.enabled, allowHosts: [...cimd.allowHosts] },
|
|
530
|
+
registration: options.registration,
|
|
531
|
+
store: store.name,
|
|
532
|
+
accessMs: options.accessMs,
|
|
533
|
+
refreshMs: options.refreshMs,
|
|
534
|
+
grantMaxDays: options.grant?.maxDays ?? GRANT_MAX_DAYS,
|
|
535
|
+
grantMaxPerClient: options.grant?.maxPerClient ?? LIMITS_DEFAULT.maxPerClient,
|
|
536
|
+
clientGrantMaxDays: Object.fromEntries(Object.entries(options.clients).flatMap(([id, client]) => client.grant === undefined ? [] : [[id, client.grant.maxDays]])),
|
|
537
|
+
live: options.live ?? LIVE_DEFAULT,
|
|
538
|
+
codeMs: options.codeMs,
|
|
539
|
+
grantCacheMs: options.grantCacheMs,
|
|
540
|
+
rateLimit: options.rateLimit?.policy ?? false,
|
|
541
|
+
extension: [...this.#resolved.overridden],
|
|
542
|
+
ms: Math.round(performance.now() - started),
|
|
543
|
+
});
|
|
544
|
+
// D-0077 B: only `dokebi describe` asks. Names and paths, never a secret.
|
|
545
|
+
if (context.runtime.describing)
|
|
546
|
+
context.contribute(describePoint, {
|
|
547
|
+
section: 'oauth',
|
|
548
|
+
describe: () => ({
|
|
549
|
+
issuer: options.issuer,
|
|
550
|
+
realm: options.realm,
|
|
551
|
+
resources: Object.fromEntries([...resources.values()].map((resource) => [
|
|
552
|
+
resource.id,
|
|
553
|
+
{
|
|
554
|
+
uri: resource.uri,
|
|
555
|
+
name: resource.name,
|
|
556
|
+
scopes: Object.keys(resource.scopes),
|
|
557
|
+
defaultScopes: [...resource.defaultScopes],
|
|
558
|
+
metadata: resource.metadataPath,
|
|
559
|
+
app: appList(options.resources[resource.id]?.app) ?? appList(options.app) ?? null,
|
|
560
|
+
},
|
|
561
|
+
])),
|
|
562
|
+
app: appList(options.app) ?? null,
|
|
563
|
+
endpoints: {
|
|
564
|
+
metadata: '/.well-known/oauth-authorization-server',
|
|
565
|
+
authorize: paths.authorize,
|
|
566
|
+
token: paths.token,
|
|
567
|
+
revoke: paths.revoke,
|
|
568
|
+
register: options.registration === 'open' ? paths.register : null,
|
|
569
|
+
},
|
|
570
|
+
clients: Object.keys(options.clients),
|
|
571
|
+
cimd: { enabled: cimd.enabled, allowHosts: [...cimd.allowHosts] },
|
|
572
|
+
registration: options.registration,
|
|
573
|
+
store: store.name,
|
|
574
|
+
routes: protectedRoutes,
|
|
575
|
+
}),
|
|
576
|
+
});
|
|
577
|
+
return api;
|
|
578
|
+
}
|
|
579
|
+
/** The endpoints, in one scope with this plugin's strict form and JSON parsers. */
|
|
580
|
+
#routes(server, oauth, paths, options, resources, logger) {
|
|
581
|
+
const bodyLimit = options.maxBodyBytes;
|
|
582
|
+
// D-0142: each route's config carries its id (`oauth.<key>` or options.routeIds.<key>).
|
|
583
|
+
const ids = pluginRouteIds('dokebi-oauth', OAUTH_ROUTE_KEYS, options.routeIds);
|
|
584
|
+
const off = (key) => ids.config(key, { auth: false });
|
|
585
|
+
const noCsrf = (key) => ids.config(key, { auth: false, csrf: false });
|
|
586
|
+
// D-0132: the authorization server answers on the hosts of dokebi-oauth.app, the metadata
|
|
587
|
+
// of each resource on those of resources.<id>.app (default dokebi-oauth.app); unset, every host.
|
|
588
|
+
const issuerApps = appList(options.app);
|
|
589
|
+
const resourceApps = new Map([...resources.keys()].map((id) => [id, appList(options.resources[id]?.app) ?? issuerApps]));
|
|
590
|
+
const issuerBinding = issuerApps === undefined ? {} : { app: issuerApps };
|
|
591
|
+
const routes = async (scope) => {
|
|
592
|
+
// At boot the app routing is final: the issuer and each resource URI must be hosts of the
|
|
593
|
+
// apps that serve them, or the metadata would send clients to a 404.
|
|
594
|
+
checkHost(server, logger, 'dokebi-oauth.issuer', options.issuer, issuerApps, 'dokebi-oauth.app');
|
|
595
|
+
for (const [id, apps] of resourceApps)
|
|
596
|
+
checkHost(server, logger, `dokebi-oauth.resources.${id}.uri`, resources.get(id).uri, apps, `dokebi-oauth.resources.${id}.app`);
|
|
597
|
+
// Repeated parameters must stay visible (the strict check refuses them), so this scope
|
|
598
|
+
// parses urlencoded bodies itself; it also does not need dokebi-web's formBody option.
|
|
599
|
+
scope.removeContentTypeParser('application/x-www-form-urlencoded');
|
|
600
|
+
scope.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'string', bodyLimit }, (_request, body, done) => done(null, formBody(body)));
|
|
601
|
+
// A body that is not JSON is answered by the handlers in their own format (RFC 7591).
|
|
602
|
+
scope.removeContentTypeParser('application/json');
|
|
603
|
+
scope.addContentTypeParser('application/json', { parseAs: 'string', bodyLimit }, (_request, body, done) => {
|
|
604
|
+
let value;
|
|
605
|
+
try {
|
|
606
|
+
value = JSON.parse(body);
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
// The answer to a broken body is the handler's (invalid_client_metadata, a 400 of
|
|
610
|
+
// the consent decision): the marker carries it there, nothing is lost.
|
|
611
|
+
if (!(error instanceof SyntaxError))
|
|
612
|
+
throw error;
|
|
613
|
+
value = BAD_JSON;
|
|
614
|
+
}
|
|
615
|
+
done(null, value);
|
|
616
|
+
});
|
|
617
|
+
/** The protected resource metadata among `served` (the resources of this host). */
|
|
618
|
+
const metadata = (served, request, reply) => {
|
|
619
|
+
const path = request.url.split('?', 1)[0];
|
|
620
|
+
const resource = served.find((one) => one.metadataPath === path);
|
|
621
|
+
reply.header('access-control-allow-origin', '*');
|
|
622
|
+
if (!resource)
|
|
623
|
+
return reply.code(404).send(oauth.metadataNotFound());
|
|
624
|
+
return reply.send(oauth.resourceMetadata(resource));
|
|
625
|
+
};
|
|
626
|
+
const common = { seal: false };
|
|
627
|
+
const answer = { ...common, ...issuerBinding };
|
|
628
|
+
scope.route({
|
|
629
|
+
method: 'GET',
|
|
630
|
+
url: '/.well-known/oauth-authorization-server',
|
|
631
|
+
config: off('serverMetadata'),
|
|
632
|
+
...answer,
|
|
633
|
+
handler: async (_request, reply) => reply.header('access-control-allow-origin', '*').send(oauth.serverMetadata()),
|
|
634
|
+
});
|
|
635
|
+
// One pair of metadata routes per app that serves some (each with that app's resources and
|
|
636
|
+
// those on every host), and one unbound pair when some resource answers every host.
|
|
637
|
+
for (const [app, served] of metadataHosts(resources, resourceApps))
|
|
638
|
+
for (const url of [
|
|
639
|
+
'/.well-known/oauth-protected-resource',
|
|
640
|
+
'/.well-known/oauth-protected-resource/*',
|
|
641
|
+
])
|
|
642
|
+
scope.route({
|
|
643
|
+
method: 'GET',
|
|
644
|
+
url,
|
|
645
|
+
config: off('resourceMetadata'),
|
|
646
|
+
...common,
|
|
647
|
+
...(app === undefined ? {} : { app }),
|
|
648
|
+
handler: async (request, reply) => metadata(served, request, reply),
|
|
649
|
+
});
|
|
650
|
+
scope.route({
|
|
651
|
+
method: 'GET',
|
|
652
|
+
url: paths.authorize,
|
|
653
|
+
config: off('authorize'),
|
|
654
|
+
...answer,
|
|
655
|
+
handler: (request, reply) => oauth.authorize(request, reply),
|
|
656
|
+
});
|
|
657
|
+
scope.route({
|
|
658
|
+
method: 'POST',
|
|
659
|
+
url: paths.authorize,
|
|
660
|
+
// The consent decision is a form of this app: @dokebi/csrf checks it, and on a seal host
|
|
661
|
+
// it is sealed like every form (R6 Claude T3 review: seal: false let a plain decision in
|
|
662
|
+
// where the seal guidance says every POST form is sealed). Its host decides.
|
|
663
|
+
config: off('authorize'),
|
|
664
|
+
...issuerBinding,
|
|
665
|
+
handler: (request, reply) => oauth.decide(request, reply),
|
|
666
|
+
});
|
|
667
|
+
scope.route({
|
|
668
|
+
method: 'POST',
|
|
669
|
+
url: paths.token,
|
|
670
|
+
config: noCsrf('token'),
|
|
671
|
+
...answer,
|
|
672
|
+
handler: (request, reply) => oauth.token(request, reply),
|
|
673
|
+
});
|
|
674
|
+
scope.route({
|
|
675
|
+
method: 'POST',
|
|
676
|
+
url: paths.revoke,
|
|
677
|
+
config: noCsrf('revoke'),
|
|
678
|
+
...answer,
|
|
679
|
+
handler: (request, reply) => oauth.revoke(request, reply),
|
|
680
|
+
});
|
|
681
|
+
scope.route({
|
|
682
|
+
method: 'POST',
|
|
683
|
+
url: paths.register,
|
|
684
|
+
config: noCsrf('register'),
|
|
685
|
+
...answer,
|
|
686
|
+
handler: (request, reply) => oauth.register(request, reply),
|
|
687
|
+
});
|
|
688
|
+
};
|
|
689
|
+
server.register(routes, {});
|
|
690
|
+
}
|
|
691
|
+
start(context) {
|
|
692
|
+
context.logger.log('debug', 'OAuth routes checked', { protected: this.#protected });
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
/** One app name or several as a list; undefined stays undefined (every host). */
|
|
696
|
+
function appList(value) {
|
|
697
|
+
return value === undefined ? undefined : typeof value === 'string' ? [value] : [...value];
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* The resources whose metadata each host group serves (D-0132): app name → its resources and
|
|
701
|
+
* the unbound ones; `undefined` → the unbound resources (every host), only when there are some.
|
|
702
|
+
* A host with no group answers the 404 of an unknown route, the issuer's too: metadata lives at
|
|
703
|
+
* the origin of the resource URI (RFC 9728 §3), never on another host.
|
|
704
|
+
*/
|
|
705
|
+
function metadataHosts(resources, apps) {
|
|
706
|
+
const everywhere = [];
|
|
707
|
+
const byApp = new Map();
|
|
708
|
+
for (const [id, resource] of resources) {
|
|
709
|
+
const list = apps.get(id);
|
|
710
|
+
if (list === undefined) {
|
|
711
|
+
everywhere.push(resource);
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
for (const app of list)
|
|
715
|
+
byApp.set(app, [...(byApp.get(app) ?? []), resource]);
|
|
716
|
+
}
|
|
717
|
+
const groups = new Map();
|
|
718
|
+
for (const [app, list] of byApp)
|
|
719
|
+
groups.set(app, [...list, ...everywhere]);
|
|
720
|
+
if (everywhere.length)
|
|
721
|
+
groups.set(undefined, everywhere);
|
|
722
|
+
return groups;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* A URL this plugin publishes (the issuer, a resource URI) against the apps that serve it, at
|
|
726
|
+
* boot (D-0132): a domain of another app fails the start, a host that is no domain is warned.
|
|
727
|
+
*/
|
|
728
|
+
function checkHost(server, logger, where, url, apps, option) {
|
|
729
|
+
const match = appUrlMatch(server.apps, url, apps);
|
|
730
|
+
if (match.kind === 'other-app')
|
|
731
|
+
throw new OAuthError('INVALID_OPTIONS', `${where} ${url} is on ${match.host}, a domain of app ${match.app}, but ${option} is ${apps?.join(', ')}: clients would reach a 404 there`, {
|
|
732
|
+
fix: `Set options.${option} to ${match.app} (the app of ${match.host}), or move ${where} to a host of ${apps?.join(' or ')}.`,
|
|
733
|
+
});
|
|
734
|
+
if (match.kind === 'unconfigured')
|
|
735
|
+
logger.log('warn', 'An OAuth URL host is no domain of dokebi-app', {
|
|
736
|
+
code: 'OAUTH_HOST_UNMAPPED',
|
|
737
|
+
where,
|
|
738
|
+
url,
|
|
739
|
+
host: match.host,
|
|
740
|
+
apps,
|
|
741
|
+
unknownDomain: match.fallback ?? null,
|
|
742
|
+
fix: `Point ${match.host} at ${apps?.[0]} in options.dokebi-app.domains (npx dokebi app link ${apps?.[0]} ${match.host}), unless a proxy sends another Host.`,
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* The dokebi-oauth plugin factory with settings: `defineOAuthPlugin({ cimdFetch })`.
|
|
747
|
+
* `createPlugin` is `defineOAuthPlugin()`.
|
|
748
|
+
*/
|
|
749
|
+
export function defineOAuthPlugin(settings = {}) {
|
|
750
|
+
return definePlugin({
|
|
751
|
+
name: 'dokebi-oauth',
|
|
752
|
+
version: '0.1.0',
|
|
753
|
+
core: '^0.4.2',
|
|
754
|
+
options: declaration,
|
|
755
|
+
contributes: [describePoint],
|
|
756
|
+
entry: (input) => new OAuthEntryInput(input),
|
|
757
|
+
dependencies: ({ options, entry }) => entry.resolve(options).dependencies,
|
|
758
|
+
instance: ({ options, entry }) => new OAuthRuntime(options, entry.resolve(options), settings),
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Factory input: `{ app, options?, entry }`. Options default to `app.config['dokebi-oauth']`;
|
|
763
|
+
* `entry` is the module of src/infra/oauth/extension.ts (D-0064), required: without
|
|
764
|
+
* `renderConsent` the plugin refuses to start (EXTENSION_REQUIRED).
|
|
765
|
+
*/
|
|
766
|
+
export const createPlugin = defineOAuthPlugin();
|