@authfn/oauth-provider 0.0.0 → 0.2.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 +97 -1
- package/dist/authorize/index.d.ts +5 -0
- package/dist/authorize/index.d.ts.map +1 -0
- package/dist/authorize/index.js +247 -0
- package/dist/authorize/index.js.map +1 -0
- package/dist/http.d.ts +35 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +161 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/introspection/index.d.ts +13 -0
- package/dist/introspection/index.d.ts.map +1 -0
- package/dist/introspection/index.js +47 -0
- package/dist/introspection/index.js.map +1 -0
- package/dist/metadata/index.d.ts +10 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +41 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/pkce.d.ts +4 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +17 -0
- package/dist/pkce.js.map +1 -0
- package/dist/registration/document.d.ts +49 -0
- package/dist/registration/document.d.ts.map +1 -0
- package/dist/registration/document.js +167 -0
- package/dist/registration/document.js.map +1 -0
- package/dist/registration/index.d.ts +38 -0
- package/dist/registration/index.d.ts.map +1 -0
- package/dist/registration/index.js +264 -0
- package/dist/registration/index.js.map +1 -0
- package/dist/registration/metadata.d.ts +27 -0
- package/dist/registration/metadata.d.ts.map +1 -0
- package/dist/registration/metadata.js +74 -0
- package/dist/registration/metadata.js.map +1 -0
- package/dist/registration/store.d.ts +82 -0
- package/dist/registration/store.d.ts.map +1 -0
- package/dist/registration/store.js +187 -0
- package/dist/registration/store.js.map +1 -0
- package/dist/revocation/index.d.ts +12 -0
- package/dist/revocation/index.d.ts.map +1 -0
- package/dist/revocation/index.js +34 -0
- package/dist/revocation/index.js.map +1 -0
- package/dist/runtime.d.ts +64 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +228 -0
- package/dist/runtime.js.map +1 -0
- package/dist/store.d.ts +155 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +467 -0
- package/dist/store.js.map +1 -0
- package/dist/token/code.d.ts +11 -0
- package/dist/token/code.d.ts.map +1 -0
- package/dist/token/code.js +64 -0
- package/dist/token/code.js.map +1 -0
- package/dist/token/index.d.ts +5 -0
- package/dist/token/index.d.ts.map +1 -0
- package/dist/token/index.js +39 -0
- package/dist/token/index.js.map +1 -0
- package/dist/token/refresh.d.ts +10 -0
- package/dist/token/refresh.d.ts.map +1 -0
- package/dist/token/refresh.js +47 -0
- package/dist/token/refresh.js.map +1 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createAuthorizeRoutes } from './authorize/index.js';
|
|
2
|
+
import { createIntrospectionRoute } from './introspection/index.js';
|
|
3
|
+
import { createMetadataRoute } from './metadata/index.js';
|
|
4
|
+
import { createRegistrationRoutes, createRegistrationSchema, validateRegistrationConfig, withClientRegistration } from './registration/index.js';
|
|
5
|
+
import { createRevocationRoute } from './revocation/index.js';
|
|
6
|
+
import { createOAuthProviderRuntime, OAUTH_PROVIDER_PLUGIN_NAME, readOAuthProviderRuntimeConfig } from './runtime.js';
|
|
7
|
+
import { createOAuthProviderSchema } from './store.js';
|
|
8
|
+
import { createTokenRoute } from './token/index.js';
|
|
9
|
+
export { OAUTH_AUTHORIZE_PATH } from './authorize/index.js';
|
|
10
|
+
export { OAUTH_INTROSPECTION_PATH } from './introspection/index.js';
|
|
11
|
+
export { OAUTH_METADATA_PATH } from './metadata/index.js';
|
|
12
|
+
export { OAUTH_REGISTRATION_PATH } from './registration/index.js';
|
|
13
|
+
export { OAUTH_REVOCATION_PATH } from './revocation/index.js';
|
|
14
|
+
export { OAUTH_TOKEN_PATH } from './token/index.js';
|
|
15
|
+
export { disconnectOAuthClient, revokeOAuthGrant, verifyOAuthAccessToken } from './store.js';
|
|
16
|
+
export * from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* OAuth 2.1 authorization server for AuthFn: RFC 8414 metadata, the
|
|
19
|
+
* authorization endpoint (authorization code with PKCE S256 only), the token
|
|
20
|
+
* endpoint (code exchange; refresh with rotation and reuse detection),
|
|
21
|
+
* revocation (RFC 7009) and introspection (RFC 7662). Every token is bound to
|
|
22
|
+
* one resource (RFC 8707) and carries the granted AuthFn scopes. Public
|
|
23
|
+
* clients such as MCP hosts can register themselves (RFC 7591) or use a
|
|
24
|
+
* Client ID Metadata Document URL as their `client_id` when `registration`
|
|
25
|
+
* enables it.
|
|
26
|
+
*/
|
|
27
|
+
export function authFnOAuthProviderPlugin(config = {}) {
|
|
28
|
+
return {
|
|
29
|
+
name: OAUTH_PROVIDER_PLUGIN_NAME,
|
|
30
|
+
// A custom schema predating client registration still gets its tables,
|
|
31
|
+
// which `resolveClient` reads; a table it defines itself is kept.
|
|
32
|
+
schema: () => config.schema ? [
|
|
33
|
+
...config.schema,
|
|
34
|
+
...createRegistrationSchema().filter((table) => !config.schema.some((own) => own.modelName === table.modelName))
|
|
35
|
+
] : createOAuthProviderSchema(),
|
|
36
|
+
validateConfig: (runtimeConfig) => {
|
|
37
|
+
validateRegistrationConfig(readOAuthProviderRuntimeConfig(runtimeConfig).registration);
|
|
38
|
+
},
|
|
39
|
+
routes: (ctx) => {
|
|
40
|
+
const runtime = withClientRegistration(createOAuthProviderRuntime(ctx));
|
|
41
|
+
return [
|
|
42
|
+
createMetadataRoute(runtime),
|
|
43
|
+
...createAuthorizeRoutes(runtime),
|
|
44
|
+
createTokenRoute(runtime),
|
|
45
|
+
createRevocationRoute(runtime),
|
|
46
|
+
createIntrospectionRoute(runtime),
|
|
47
|
+
...createRegistrationRoutes(runtime)
|
|
48
|
+
];
|
|
49
|
+
}
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AG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YAC5B,GAAG,MAAM,CAAC,MAAM;YAChB,GAAG,wBAAwB,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;SAClH,CAAC,CAAC,CAAC,yBAAyB,EAAE;QAC/B,cAAc,EAAE,CAAC,aAAa,EAAE,EAAE;YAChC,0BAA0B,CAAC,8BAA8B,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC;QACzF,CAAC;QACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;YACd,MAAM,OAAO,GAAG,sBAAsB,CAAC,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC;YACxE,OAAO;gBACL,mBAAmB,CAAC,OAAO,CAAC;gBAC5B,GAAG,qBAAqB,CAAC,OAAO,CAAC;gBACjC,gBAAgB,CAAC,OAAO,CAAC;gBACzB,qBAAqB,CAAC,OAAO,CAAC;gBAC9B,wBAAwB,CAAC,OAAO,CAAC;gBACjC,GAAG,wBAAwB,CAAC,OAAO,CAAC;aACrC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Route } from '@superfunctions/http';
|
|
2
|
+
import type { OAuthProviderRuntime } from '../runtime.js';
|
|
3
|
+
export declare const OAUTH_INTROSPECTION_PATH = "/oauth/introspect";
|
|
4
|
+
/**
|
|
5
|
+
* Token introspection (RFC 7662) for resource servers. The caller
|
|
6
|
+
* authenticates with its resource's introspection secret, and a token is
|
|
7
|
+
* reported active only when it is an active access token issued for that
|
|
8
|
+
* resource: a token presented at the wrong audience is inactive. The optional
|
|
9
|
+
* `iss` is omitted: tokens do not record the issuer they were issued under,
|
|
10
|
+
* and a request-dependent environment could resolve a different one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createIntrospectionRoute(runtime: OAuthProviderRuntime): Route;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/introspection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAWlD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,oBAAoB,GAAG,KAAK,CAmC7E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createAuthFnRouteMeta } from 'authfn/http/router';
|
|
2
|
+
import { handleOAuth, OAuthError, oauthJson, readBearerToken, readFormBody, requireParam, secretsEqual } from '../http.js';
|
|
3
|
+
import { loadActiveToken } from '../store.js';
|
|
4
|
+
export const OAUTH_INTROSPECTION_PATH = '/oauth/introspect';
|
|
5
|
+
/**
|
|
6
|
+
* Token introspection (RFC 7662) for resource servers. The caller
|
|
7
|
+
* authenticates with its resource's introspection secret, and a token is
|
|
8
|
+
* reported active only when it is an active access token issued for that
|
|
9
|
+
* resource: a token presented at the wrong audience is inactive. The optional
|
|
10
|
+
* `iss` is omitted: tokens do not record the issuer they were issued under,
|
|
11
|
+
* and a request-dependent environment could resolve a different one.
|
|
12
|
+
*/
|
|
13
|
+
export function createIntrospectionRoute(runtime) {
|
|
14
|
+
return {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
path: OAUTH_INTROSPECTION_PATH,
|
|
17
|
+
meta: createAuthFnRouteMeta('oauthIntrospect', 'OAuth 2.0 token introspection', { mode: 'bearer' }),
|
|
18
|
+
handler: (request) => handleOAuth(async () => {
|
|
19
|
+
const secret = readBearerToken(request);
|
|
20
|
+
const caller = secret === null
|
|
21
|
+
? undefined
|
|
22
|
+
: runtime.config.resources.find((resource) => resource.introspectionSecret !== undefined && secretsEqual(secret, resource.introspectionSecret));
|
|
23
|
+
if (!caller) {
|
|
24
|
+
throw new OAuthError('invalid_token', 'Resource server authentication failed', 401, {
|
|
25
|
+
'www-authenticate': 'Bearer error="invalid_token"'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const params = await readFormBody(request);
|
|
29
|
+
const active = await loadActiveToken(runtime.store, requireParam(params, 'token'), 'access', runtime.now());
|
|
30
|
+
if (!active || active.record.resource !== caller.resource) {
|
|
31
|
+
return oauthJson({ active: false });
|
|
32
|
+
}
|
|
33
|
+
const { record } = active;
|
|
34
|
+
return oauthJson({
|
|
35
|
+
active: true,
|
|
36
|
+
scope: record.scopes.join(' '),
|
|
37
|
+
client_id: record.clientId,
|
|
38
|
+
sub: record.userId,
|
|
39
|
+
aud: record.resource,
|
|
40
|
+
token_type: 'Bearer',
|
|
41
|
+
iat: Math.floor(record.createdAt.getTime() / 1000),
|
|
42
|
+
exp: Math.floor(record.expiresAt.getTime() / 1000)
|
|
43
|
+
});
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/introspection/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAA6B;IACpE,OAAO;QACL,MAAM,EAAE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M,CAAC,IAAI,CAAC,GAAG,CAAC;gBAC9B,SAAS,EAAE,MAAM,CAAC,QAAQ;gBAC1B,GAAG,EAAE,MAAM,CAAC,MAAM;gBAClB,GAAG,EAAE,MAAM,CAAC,QAAQ;gBACpB,UAAU,EAAE,QAAQ;gBACpB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;gBAClD,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;aACnD,CAAC,CAAC;QACL,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Route } from '@superfunctions/http';
|
|
2
|
+
import { type OAuthProviderRuntime } from '../runtime.js';
|
|
3
|
+
export declare const OAUTH_METADATA_PATH = "/.well-known/oauth-authorization-server";
|
|
4
|
+
/**
|
|
5
|
+
* RFC 8414 authorization server metadata. Served under the AuthFn base path;
|
|
6
|
+
* hosts route `/.well-known/oauth-authorization-server` (with the issuer's
|
|
7
|
+
* path appended, if any) to this route.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMetadataRoute(runtime: OAuthProviderRuntime): Route;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAoB,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE5E,eAAO,MAAM,mBAAmB,4CAA4C,CAAC;AAE7E;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,KAAK,CA+BxE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createAuthFnRouteMeta } from 'authfn/http/router';
|
|
2
|
+
import { resolveEndpoints } from '../runtime.js';
|
|
3
|
+
export const OAUTH_METADATA_PATH = '/.well-known/oauth-authorization-server';
|
|
4
|
+
/**
|
|
5
|
+
* RFC 8414 authorization server metadata. Served under the AuthFn base path;
|
|
6
|
+
* hosts route `/.well-known/oauth-authorization-server` (with the issuer's
|
|
7
|
+
* path appended, if any) to this route.
|
|
8
|
+
*/
|
|
9
|
+
export function createMetadataRoute(runtime) {
|
|
10
|
+
return {
|
|
11
|
+
method: 'GET',
|
|
12
|
+
path: OAUTH_METADATA_PATH,
|
|
13
|
+
meta: createAuthFnRouteMeta('oauthAuthorizationServerMetadata', 'OAuth 2.1 authorization server metadata', {
|
|
14
|
+
mode: 'none'
|
|
15
|
+
}),
|
|
16
|
+
handler: async (request) => {
|
|
17
|
+
const endpoints = await resolveEndpoints(runtime, request);
|
|
18
|
+
const registration = runtime.config.registration;
|
|
19
|
+
const scopes = [...new Set(runtime.config.resources.flatMap((resource) => resource.scopes))];
|
|
20
|
+
return Response.json({
|
|
21
|
+
issuer: endpoints.issuer,
|
|
22
|
+
authorization_endpoint: endpoints.authorization,
|
|
23
|
+
token_endpoint: endpoints.token,
|
|
24
|
+
revocation_endpoint: endpoints.revocation,
|
|
25
|
+
introspection_endpoint: endpoints.introspection,
|
|
26
|
+
...(registration?.dynamic ? { registration_endpoint: endpoints.registration } : {}),
|
|
27
|
+
...(registration?.metadataDocuments ? { client_id_metadata_document_supported: true } : {}),
|
|
28
|
+
scopes_supported: scopes,
|
|
29
|
+
response_types_supported: ['code'],
|
|
30
|
+
response_modes_supported: ['query'],
|
|
31
|
+
grant_types_supported: ['authorization_code', 'refresh_token'],
|
|
32
|
+
code_challenge_methods_supported: ['S256'],
|
|
33
|
+
token_endpoint_auth_methods_supported: ['none', 'client_secret_basic', 'client_secret_post'],
|
|
34
|
+
revocation_endpoint_auth_methods_supported: ['none', 'client_secret_basic', 'client_secret_post'],
|
|
35
|
+
introspection_endpoint_auth_methods_supported: ['bearer'],
|
|
36
|
+
authorization_response_iss_parameter_supported: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAA6B,MAAM,eAAe,CAAC;AAE5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,yCAAyC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,OAAO;QACL,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,qBAAqB,CAAC,kCAAkC,EAAE,yCAAyC,EAAE;YACzG,IAAI,EAAE,MAAM;SACb,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACzB,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;YACjD,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC7F,OAAO,QAAQ,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,SAAS,CAAC,MAAM;gBACxB,sBAAsB,EAAE,SAAS,CAAC,aAAa;gBAC/C,cAAc,EAAE,SAAS,CAAC,KAAK;gBAC/B,mBAAmB,EAAE,SAAS,CAAC,UAAU;gBACzC,sBAAsB,EAAE,SAAS,CAAC,aAAa;gBAC/C,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnF,GAAG,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,qCAAqC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3F,gBAAgB,EAAE,MAAM;gBACxB,wBAAwB,EAAE,CAAC,MAAM,CAAC;gBAClC,wBAAwB,EAAE,CAAC,OAAO,CAAC;gBACnC,qBAAqB,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;gBAC9D,gCAAgC,EAAE,CAAC,MAAM,CAAC;gBAC1C,qCAAqC,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,oBAAoB,CAAC;gBAC5F,0CAA0C,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,oBAAoB,CAAC;gBACjG,6CAA6C,EAAE,CAAC,QAAQ,CAAC;gBACzD,8CAA8C,EAAE,IAAI;aACrD,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/pkce.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isS256Challenge(value: string): boolean;
|
|
2
|
+
/** RFC 7636 4.6: BASE64URL-ENCODE(SHA256(ASCII(code_verifier))) == code_challenge. */
|
|
3
|
+
export declare function verifyS256(verifier: string, challenge: string): boolean;
|
|
4
|
+
//# sourceMappingURL=pkce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkce.d.ts","sourceRoot":"","sources":["../src/pkce.ts"],"names":[],"mappings":"AAQA,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAKvE"}
|
package/dist/pkce.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { secretsEqual } from './http.js';
|
|
3
|
+
// RFC 7636 4.1: code_verifier = 43*128unreserved.
|
|
4
|
+
const CODE_VERIFIER = /^[A-Za-z0-9\-._~]{43,128}$/;
|
|
5
|
+
// BASE64URL(SHA256(verifier)) is always 43 characters without padding.
|
|
6
|
+
const S256_CHALLENGE = /^[A-Za-z0-9\-_]{43}$/;
|
|
7
|
+
export function isS256Challenge(value) {
|
|
8
|
+
return S256_CHALLENGE.test(value);
|
|
9
|
+
}
|
|
10
|
+
/** RFC 7636 4.6: BASE64URL-ENCODE(SHA256(ASCII(code_verifier))) == code_challenge. */
|
|
11
|
+
export function verifyS256(verifier, challenge) {
|
|
12
|
+
if (!CODE_VERIFIER.test(verifier)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return secretsEqual(createHash('sha256').update(verifier, 'ascii').digest('base64url'), challenge);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=pkce.js.map
|
package/dist/pkce.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkce.js","sourceRoot":"","sources":["../src/pkce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,kDAAkD;AAClD,MAAM,aAAa,GAAG,4BAA4B,CAAC;AACnD,uEAAuE;AACvE,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAE9C,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,SAAiB;IAC5D,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** A metadata document fetch, headers and body together, must finish within 5 seconds. */
|
|
2
|
+
export declare const METADATA_DOCUMENT_TIMEOUT_MS = 5000;
|
|
3
|
+
/** A metadata document may be at most 64 KB. */
|
|
4
|
+
export declare const METADATA_DOCUMENT_MAX_BYTES: number;
|
|
5
|
+
/**
|
|
6
|
+
* A `client_id` that names a Client ID Metadata Document: an `https` URL with
|
|
7
|
+
* a path, no query, fragment or credentials (not even an empty `?` or `#`),
|
|
8
|
+
* written in its normalized form (so no dot segments, default port or
|
|
9
|
+
* uppercase host), at most 255 characters. The host must be a public DNS
|
|
10
|
+
* name of at least two valid labels: IP literals, single-label names, empty
|
|
11
|
+
* labels and internal suffixes such as `localhost` and `.internal` are
|
|
12
|
+
* refused before any request is made.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isMetadataDocumentClientId(value: string): boolean;
|
|
15
|
+
/** The whole stream did not arrive before the deadline of {@link readCappedJson}. */
|
|
16
|
+
export declare class BodyTimeoutError extends Error {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads at most `maxBytes` of JSON from `reader` within `timeoutMs`; null
|
|
20
|
+
* when the stream is longer, after cancelling it. When the stream has not
|
|
21
|
+
* ended by the deadline, the reader is cancelled and it throws
|
|
22
|
+
* {@link BodyTimeoutError}. Invalid UTF-8 or JSON throws.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readCappedJson(reader: ReadableStreamDefaultReader<Uint8Array>, maxBytes: number, timeoutMs: number): Promise<{
|
|
25
|
+
value: unknown;
|
|
26
|
+
} | null>;
|
|
27
|
+
/** A declared `content-length` over `maxBytes`, or one that is not a number. */
|
|
28
|
+
export declare function declaresMoreThan(headers: Headers, maxBytes: number): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The outcome of a metadata document fetch: the parsed document; `invalid`
|
|
31
|
+
* when the host answered with something that is not a document (a redirect,
|
|
32
|
+
* a status other than 200, more than 64 KB, declared or streamed, or not
|
|
33
|
+
* UTF-8 JSON); or `unavailable` when it gave no usable answer (a network error, no
|
|
34
|
+
* complete answer within 5 seconds, a 5xx, 408 or 429).
|
|
35
|
+
*/
|
|
36
|
+
export type MetadataDocumentFetch = {
|
|
37
|
+
status: 'ok';
|
|
38
|
+
document: unknown;
|
|
39
|
+
} | {
|
|
40
|
+
status: 'invalid' | 'unavailable';
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Fetches and parses the metadata document at `url` without following
|
|
44
|
+
* redirects. The 5-second deadline covers the body as well as the headers and
|
|
45
|
+
* holds even if `fetchImpl` ignores the abort signal; the request and body are
|
|
46
|
+
* cancelled when it passes.
|
|
47
|
+
*/
|
|
48
|
+
export declare function fetchMetadataDocument(fetchImpl: typeof fetch, url: string): Promise<MetadataDocumentFetch>;
|
|
49
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/registration/document.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,gDAAgD;AAChD,eAAO,MAAM,2BAA2B,QAAY,CAAC;AASrD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAiBjE;AAsCD,qFAAqF;AACrF,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,EAC/C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC,CAgBpC;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO5E;AAED;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,SAAS,GAAG,aAAa,CAAA;CAAE,CAAC;AAIhH;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAkDhH"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** A metadata document fetch, headers and body together, must finish within 5 seconds. */
|
|
2
|
+
export const METADATA_DOCUMENT_TIMEOUT_MS = 5000;
|
|
3
|
+
/** A metadata document may be at most 64 KB. */
|
|
4
|
+
export const METADATA_DOCUMENT_MAX_BYTES = 64 * 1024;
|
|
5
|
+
/** Stored `client_id` values are at most 255 characters. */
|
|
6
|
+
const MAX_CLIENT_ID_LENGTH = 255;
|
|
7
|
+
/** Names that only resolve inside a host or private network. */
|
|
8
|
+
const INTERNAL_SUFFIXES = ['localhost', 'local', 'internal', 'localdomain', 'home.arpa'];
|
|
9
|
+
/** One DNS label: 1 to 63 letters, digits or inner hyphens (lowercase, as normalized). */
|
|
10
|
+
const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
11
|
+
/**
|
|
12
|
+
* A `client_id` that names a Client ID Metadata Document: an `https` URL with
|
|
13
|
+
* a path, no query, fragment or credentials (not even an empty `?` or `#`),
|
|
14
|
+
* written in its normalized form (so no dot segments, default port or
|
|
15
|
+
* uppercase host), at most 255 characters. The host must be a public DNS
|
|
16
|
+
* name of at least two valid labels: IP literals, single-label names, empty
|
|
17
|
+
* labels and internal suffixes such as `localhost` and `.internal` are
|
|
18
|
+
* refused before any request is made.
|
|
19
|
+
*/
|
|
20
|
+
export function isMetadataDocumentClientId(value) {
|
|
21
|
+
if (value.length > MAX_CLIENT_ID_LENGTH || !value.startsWith('https://')) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(value);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const host = url.hostname;
|
|
32
|
+
const labels = host.split('.');
|
|
33
|
+
return url.href === value && url.pathname !== '/' && !value.includes('?') && !value.includes('#') &&
|
|
34
|
+
url.username === '' && url.password === '' &&
|
|
35
|
+
labels.length >= 2 && host.length <= 253 && labels.every((label) => DNS_LABEL.test(label)) &&
|
|
36
|
+
!/^[\d.]+$/.test(host) &&
|
|
37
|
+
!INTERNAL_SUFFIXES.some((suffix) => host === suffix || host.endsWith(`.${suffix}`));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reads at most `maxBytes` from `reader`; null when the stream is longer,
|
|
41
|
+
* after cancelling it.
|
|
42
|
+
*/
|
|
43
|
+
async function readCappedBytes(reader, maxBytes) {
|
|
44
|
+
const chunks = [];
|
|
45
|
+
let size = 0;
|
|
46
|
+
for (;;) {
|
|
47
|
+
const { done, value } = await reader.read();
|
|
48
|
+
if (done) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
size += value.byteLength;
|
|
52
|
+
if (size > maxBytes) {
|
|
53
|
+
await reader.cancel().catch(() => undefined);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
chunks.push(value);
|
|
57
|
+
}
|
|
58
|
+
const bytes = new Uint8Array(size);
|
|
59
|
+
let offset = 0;
|
|
60
|
+
for (const chunk of chunks) {
|
|
61
|
+
bytes.set(chunk, offset);
|
|
62
|
+
offset += chunk.byteLength;
|
|
63
|
+
}
|
|
64
|
+
return bytes;
|
|
65
|
+
}
|
|
66
|
+
/** Parses UTF-8 JSON; invalid UTF-8 or JSON throws. */
|
|
67
|
+
function parseJson(bytes) {
|
|
68
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
69
|
+
}
|
|
70
|
+
/** The whole stream did not arrive before the deadline of {@link readCappedJson}. */
|
|
71
|
+
export class BodyTimeoutError extends Error {
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Reads at most `maxBytes` of JSON from `reader` within `timeoutMs`; null
|
|
75
|
+
* when the stream is longer, after cancelling it. When the stream has not
|
|
76
|
+
* ended by the deadline, the reader is cancelled and it throws
|
|
77
|
+
* {@link BodyTimeoutError}. Invalid UTF-8 or JSON throws.
|
|
78
|
+
*/
|
|
79
|
+
export async function readCappedJson(reader, maxBytes, timeoutMs) {
|
|
80
|
+
let timer;
|
|
81
|
+
const deadline = new Promise((_, reject) => {
|
|
82
|
+
timer = setTimeout(() => {
|
|
83
|
+
reject(new BodyTimeoutError('Request body timed out'));
|
|
84
|
+
reader.cancel().catch(() => undefined);
|
|
85
|
+
}, timeoutMs);
|
|
86
|
+
});
|
|
87
|
+
const read = readCappedBytes(reader, maxBytes);
|
|
88
|
+
try {
|
|
89
|
+
const bytes = await Promise.race([read, deadline]);
|
|
90
|
+
return bytes && { value: parseJson(bytes) };
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
read.catch(() => undefined);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** A declared `content-length` over `maxBytes`, or one that is not a number. */
|
|
98
|
+
export function declaresMoreThan(headers, maxBytes) {
|
|
99
|
+
const declared = headers.get('content-length');
|
|
100
|
+
if (declared === null) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const length = Number(declared);
|
|
104
|
+
return Number.isNaN(length) || length > maxBytes;
|
|
105
|
+
}
|
|
106
|
+
const TRANSIENT_STATUSES = new Set([408, 429]);
|
|
107
|
+
/**
|
|
108
|
+
* Fetches and parses the metadata document at `url` without following
|
|
109
|
+
* redirects. The 5-second deadline covers the body as well as the headers and
|
|
110
|
+
* holds even if `fetchImpl` ignores the abort signal; the request and body are
|
|
111
|
+
* cancelled when it passes.
|
|
112
|
+
*/
|
|
113
|
+
export async function fetchMetadataDocument(fetchImpl, url) {
|
|
114
|
+
const controller = new AbortController();
|
|
115
|
+
let reader;
|
|
116
|
+
let timer;
|
|
117
|
+
const deadline = new Promise((_, reject) => {
|
|
118
|
+
timer = setTimeout(() => {
|
|
119
|
+
controller.abort();
|
|
120
|
+
reader?.cancel().catch(() => undefined);
|
|
121
|
+
reject(new Error('Client metadata document timed out'));
|
|
122
|
+
}, METADATA_DOCUMENT_TIMEOUT_MS);
|
|
123
|
+
});
|
|
124
|
+
const work = (async () => {
|
|
125
|
+
const response = await fetchImpl(url, {
|
|
126
|
+
method: 'GET',
|
|
127
|
+
headers: { accept: 'application/json' },
|
|
128
|
+
// Not 'error', which Cloudflare Workers reject; a 3xx answer is refused below.
|
|
129
|
+
redirect: 'manual',
|
|
130
|
+
signal: controller.signal
|
|
131
|
+
});
|
|
132
|
+
if (controller.signal.aborted || response.status !== 200 || response.redirected || !response.body ||
|
|
133
|
+
declaresMoreThan(response.headers, METADATA_DOCUMENT_MAX_BYTES)) {
|
|
134
|
+
await response.body?.cancel().catch(() => undefined);
|
|
135
|
+
const transient = controller.signal.aborted || response.status >= 500 || TRANSIENT_STATUSES.has(response.status);
|
|
136
|
+
return { status: transient ? 'unavailable' : 'invalid' };
|
|
137
|
+
}
|
|
138
|
+
reader = response.body.getReader();
|
|
139
|
+
const bytes = await readCappedBytes(reader, METADATA_DOCUMENT_MAX_BYTES);
|
|
140
|
+
return bytes ?? { status: 'invalid' };
|
|
141
|
+
})();
|
|
142
|
+
let outcome;
|
|
143
|
+
try {
|
|
144
|
+
outcome = await Promise.race([work, deadline]);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return { status: 'unavailable' };
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
// Settle the abandoned branch quietly and release the connection.
|
|
152
|
+
work.catch(() => undefined);
|
|
153
|
+
controller.abort();
|
|
154
|
+
}
|
|
155
|
+
if (!(outcome instanceof Uint8Array)) {
|
|
156
|
+
return outcome;
|
|
157
|
+
}
|
|
158
|
+
// Decoded here, not in the race: a complete body that is not UTF-8 JSON is
|
|
159
|
+
// the host's answer, while a failure reading it leaves the host unavailable.
|
|
160
|
+
try {
|
|
161
|
+
return { status: 'ok', document: parseJson(outcome) };
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return { status: 'invalid' };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/registration/document.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,gDAAgD;AAChD,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,CAAC;AACrD,4DAA4D;AAC5D,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,gEAAgE;AAChE,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AACzF,0FAA0F;AAC1F,MAAM,SAAS,GAAG,wCAAwC,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAa;IACtD,IAAI,KAAK,CAAC,MAAM,GAAG,oBAAoB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,I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CAAC;IAChD,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IACnC,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,kEAAkE;QAClE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,UAAU,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IACD,IAAI,CAAC,CAAC,OAAO,YAAY,UAAU,CAAC,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,2EAA2E;IAC3E,6EAA6E;IAC7E,IAAI,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Route } from '@superfunctions/http';
|
|
2
|
+
import type { OAuthProviderRuntime } from '../runtime.js';
|
|
3
|
+
export { createRegistrationSchema } from './store.js';
|
|
4
|
+
export declare const OAUTH_REGISTRATION_PATH = "/oauth/register";
|
|
5
|
+
/** A registration request body must arrive within 5 seconds. */
|
|
6
|
+
export declare const REGISTRATION_BODY_TIMEOUT_MS = 5000;
|
|
7
|
+
/** Rejects a malformed `pluginRuntime.oauthProvider.registration` at startup. */
|
|
8
|
+
export declare function validateRegistrationConfig(registration: unknown): void;
|
|
9
|
+
/**
|
|
10
|
+
* Extends `resolveClient` with self-registered clients. A configured client
|
|
11
|
+
* always wins. A `client_id` with the registration prefix is looked up in
|
|
12
|
+
* storage (also after `dynamic` is turned off, which only stops new
|
|
13
|
+
* registrations). With `metadataDocuments`, an `https` URL `client_id` is
|
|
14
|
+
* resolved from the document it serves: the document must name that exact
|
|
15
|
+
* URL as its `client_id` and pass the same public client rules as a
|
|
16
|
+
* registration.
|
|
17
|
+
*
|
|
18
|
+
* The first fetch of an unknown `client_id` counts toward the registration
|
|
19
|
+
* rate limit, and its usable document is stored. A known client is refetched
|
|
20
|
+
* at most once per 5 minutes across all instances, outside that limit, so
|
|
21
|
+
* flooding refuses only new clients and known clients still pick up changed
|
|
22
|
+
* documents. When its host gives no usable answer (network error, timeout,
|
|
23
|
+
* 5xx, 408 or 429), a known client keeps its stored document; any other
|
|
24
|
+
* answer that is not a usable document makes it unknown and drops the row.
|
|
25
|
+
* Only the request holding the current refetch claim stores or drops a
|
|
26
|
+
* result: one that stalled past its claim changes nothing and serves what
|
|
27
|
+
* the newer claim stored.
|
|
28
|
+
*/
|
|
29
|
+
export declare function withClientRegistration(runtime: OAuthProviderRuntime): OAuthProviderRuntime;
|
|
30
|
+
/**
|
|
31
|
+
* RFC 7591 dynamic client registration, when `registration.dynamic` is on.
|
|
32
|
+
* Registers a public client (`token_endpoint_auth_method: none`, no secret)
|
|
33
|
+
* and answers 201 with its metadata. Rate-limited per IP and overall; the
|
|
34
|
+
* body must arrive within 5 seconds.
|
|
35
|
+
* RFC 7592 client management is not offered.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createRegistrationRoutes(runtime: OAuthProviderRuntime): Route[];
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registration/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAIlD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AA2B1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,uBAAuB,oBAAoB,CAAC;AAGzD,gEAAgE;AAChE,eAAO,MAAM,4BAA4B,OAAO,CAAC;AASjD,iFAAiF;AACjF,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,CA4BtE;AA2CD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,oBAAoB,CA2G1F;AA8BD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,oBAAoB,GAAG,KAAK,EAAE,CAwB/E"}
|