@arcblock/did-connect-service 4.0.4 → 4.0.6
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/assets/fonts/noto-sans-sc-regular.otf +0 -0
- package/dist/embedded.d.ts +32 -0
- package/dist/embedded.d.ts.map +1 -1
- package/dist/embedded.js +3 -0
- package/dist/embedded.js.map +1 -1
- package/dist/handlers/auth-handler.d.ts +5 -0
- package/dist/handlers/auth-handler.d.ts.map +1 -1
- package/dist/handlers/auth-handler.js +33 -0
- package/dist/handlers/auth-handler.js.map +1 -1
- package/dist/handlers/branding-handler.d.ts +17 -0
- package/dist/handlers/branding-handler.d.ts.map +1 -1
- package/dist/handlers/branding-handler.js +107 -5
- package/dist/handlers/branding-handler.js.map +1 -1
- package/dist/identity/csrf.d.ts +17 -0
- package/dist/identity/csrf.d.ts.map +1 -0
- package/dist/identity/csrf.js +56 -0
- package/dist/identity/csrf.js.map +1 -0
- package/dist/og/emoji.d.ts +12 -0
- package/dist/og/emoji.d.ts.map +1 -0
- package/dist/og/emoji.js +71 -0
- package/dist/og/emoji.js.map +1 -0
- package/dist/og/generator.d.ts +3 -0
- package/dist/og/generator.d.ts.map +1 -0
- package/dist/og/generator.js +338 -0
- package/dist/og/generator.js.map +1 -0
- package/dist/og/index.d.ts +6 -0
- package/dist/og/index.d.ts.map +1 -0
- package/dist/og/index.js +4 -0
- package/dist/og/index.js.map +1 -0
- package/dist/og/passport-svg.d.ts +52 -0
- package/dist/og/passport-svg.d.ts.map +1 -0
- package/dist/og/passport-svg.js +157 -0
- package/dist/og/passport-svg.js.map +1 -0
- package/dist/og/ssrf-guard.d.ts +38 -0
- package/dist/og/ssrf-guard.d.ts.map +1 -0
- package/dist/og/ssrf-guard.js +188 -0
- package/dist/og/ssrf-guard.js.map +1 -0
- package/dist/og/templates.d.ts +26 -0
- package/dist/og/templates.d.ts.map +1 -0
- package/dist/og/templates.js +302 -0
- package/dist/og/templates.js.map +1 -0
- package/dist/og/types.d.ts +74 -0
- package/dist/og/types.d.ts.map +1 -0
- package/dist/og/types.js +14 -0
- package/dist/og/types.js.map +1 -0
- package/package.json +18 -4
- package/dist/access-key-handler.d.ts +0 -37
- package/dist/access-key-handler.d.ts.map +0 -1
- package/dist/access-key-handler.js +0 -316
- package/dist/access-key-handler.js.map +0 -1
- package/dist/access-key-util.d.ts +0 -19
- package/dist/access-key-util.d.ts.map +0 -1
- package/dist/access-key-util.js +0 -45
- package/dist/access-key-util.js.map +0 -1
- package/dist/access-policy.d.ts +0 -53
- package/dist/access-policy.d.ts.map +0 -1
- package/dist/access-policy.js +0 -153
- package/dist/access-policy.js.map +0 -1
- package/dist/auth-client.d.ts +0 -20
- package/dist/auth-client.d.ts.map +0 -1
- package/dist/auth-client.js +0 -42
- package/dist/auth-client.js.map +0 -1
- package/dist/auth-entrypoint.d.ts +0 -45
- package/dist/auth-entrypoint.d.ts.map +0 -1
- package/dist/auth-entrypoint.js +0 -31
- package/dist/auth-entrypoint.js.map +0 -1
- package/dist/auth-handler.d.ts +0 -136
- package/dist/auth-handler.d.ts.map +0 -1
- package/dist/auth-handler.js +0 -408
- package/dist/auth-handler.js.map +0 -1
- package/dist/auth-rpc-types.d.ts +0 -139
- package/dist/auth-rpc-types.d.ts.map +0 -1
- package/dist/auth-rpc-types.js +0 -11
- package/dist/auth-rpc-types.js.map +0 -1
- package/dist/auth-rpc.d.ts +0 -80
- package/dist/auth-rpc.d.ts.map +0 -1
- package/dist/auth-rpc.js +0 -257
- package/dist/auth-rpc.js.map +0 -1
- package/dist/auth-worker.d.ts +0 -42
- package/dist/auth-worker.d.ts.map +0 -1
- package/dist/auth-worker.js +0 -120
- package/dist/auth-worker.js.map +0 -1
- package/dist/blocklet-js-handler.d.ts +0 -22
- package/dist/blocklet-js-handler.d.ts.map +0 -1
- package/dist/blocklet-js-handler.js +0 -205
- package/dist/blocklet-js-handler.js.map +0 -1
- package/dist/branding-handler.d.ts +0 -42
- package/dist/branding-handler.d.ts.map +0 -1
- package/dist/branding-handler.js +0 -326
- package/dist/branding-handler.js.map +0 -1
- package/dist/d1-token-storage.d.ts +0 -31
- package/dist/d1-token-storage.d.ts.map +0 -1
- package/dist/d1-token-storage.js +0 -83
- package/dist/d1-token-storage.js.map +0 -1
- package/dist/did-connect-handler.d.ts +0 -57
- package/dist/did-connect-handler.d.ts.map +0 -1
- package/dist/did-connect-handler.js +0 -182
- package/dist/did-connect-handler.js.map +0 -1
- package/dist/did.d.ts +0 -14
- package/dist/did.d.ts.map +0 -1
- package/dist/did.js +0 -17
- package/dist/did.js.map +0 -1
- package/dist/email-login-handler.d.ts +0 -50
- package/dist/email-login-handler.d.ts.map +0 -1
- package/dist/email-login-handler.js +0 -238
- package/dist/email-login-handler.js.map +0 -1
- package/dist/federation-utils.d.ts +0 -23
- package/dist/federation-utils.d.ts.map +0 -1
- package/dist/federation-utils.js +0 -25
- package/dist/federation-utils.js.map +0 -1
- package/dist/handler.d.ts +0 -90
- package/dist/handler.d.ts.map +0 -1
- package/dist/handler.js +0 -591
- package/dist/handler.js.map +0 -1
- package/dist/identity/invitation-util.d.ts +0 -7
- package/dist/identity/invitation-util.d.ts.map +0 -1
- package/dist/identity/invitation-util.js +0 -66
- package/dist/identity/invitation-util.js.map +0 -1
- package/dist/instance-role.d.ts +0 -10
- package/dist/instance-role.d.ts.map +0 -1
- package/dist/instance-role.js +0 -20
- package/dist/instance-role.js.map +0 -1
- package/dist/jwt.d.ts +0 -7
- package/dist/jwt.d.ts.map +0 -1
- package/dist/jwt.js +0 -72
- package/dist/jwt.js.map +0 -1
- package/dist/login-entry.d.ts +0 -9
- package/dist/login-entry.d.ts.map +0 -1
- package/dist/login-entry.js +0 -9
- package/dist/login-entry.js.map +0 -1
- package/dist/membership-handler.d.ts +0 -27
- package/dist/membership-handler.d.ts.map +0 -1
- package/dist/membership-handler.js +0 -111
- package/dist/membership-handler.js.map +0 -1
- package/dist/oauth-callback-page.d.ts +0 -9
- package/dist/oauth-callback-page.d.ts.map +0 -1
- package/dist/oauth-callback-page.js +0 -31
- package/dist/oauth-callback-page.js.map +0 -1
- package/dist/oauth-handler.d.ts +0 -72
- package/dist/oauth-handler.d.ts.map +0 -1
- package/dist/oauth-handler.js +0 -423
- package/dist/oauth-handler.js.map +0 -1
- package/dist/page.d.ts +0 -33
- package/dist/page.d.ts.map +0 -1
- package/dist/page.js +0 -59
- package/dist/page.js.map +0 -1
- package/dist/pages/auth-script.d.ts +0 -18
- package/dist/pages/auth-script.d.ts.map +0 -1
- package/dist/pages/auth-script.js +0 -185
- package/dist/pages/auth-script.js.map +0 -1
- package/dist/pages/design-tokens.d.ts +0 -86
- package/dist/pages/design-tokens.d.ts.map +0 -1
- package/dist/pages/design-tokens.js +0 -159
- package/dist/pages/design-tokens.js.map +0 -1
- package/dist/pages/did-connect-script.d.ts +0 -16
- package/dist/pages/did-connect-script.d.ts.map +0 -1
- package/dist/pages/did-connect-script.js +0 -105
- package/dist/pages/did-connect-script.js.map +0 -1
- package/dist/pages/shared-styles.d.ts +0 -6
- package/dist/pages/shared-styles.d.ts.map +0 -1
- package/dist/pages/shared-styles.js +0 -109
- package/dist/pages/shared-styles.js.map +0 -1
- package/dist/rbac.d.ts +0 -19
- package/dist/rbac.d.ts.map +0 -1
- package/dist/rbac.js +0 -76
- package/dist/rbac.js.map +0 -1
- package/dist/session-context.d.ts +0 -35
- package/dist/session-context.d.ts.map +0 -1
- package/dist/session-context.js +0 -39
- package/dist/session-context.js.map +0 -1
- package/dist/store.d.ts +0 -222
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js +0 -1366
- package/dist/store.js.map +0 -1
- package/dist/team-handler.d.ts +0 -90
- package/dist/team-handler.d.ts.map +0 -1
- package/dist/team-handler.js +0 -1225
- package/dist/team-handler.js.map +0 -1
- package/dist/ticket-handler.d.ts +0 -28
- package/dist/ticket-handler.d.ts.map +0 -1
- package/dist/ticket-handler.js +0 -74
- package/dist/ticket-handler.js.map +0 -1
- package/dist/wallet-identity.d.ts +0 -32
- package/dist/wallet-identity.d.ts.map +0 -1
- package/dist/wallet-identity.js +0 -43
- package/dist/wallet-identity.js.map +0 -1
- package/dist/webauthn.d.ts +0 -65
- package/dist/webauthn.d.ts.map +0 -1
- package/dist/webauthn.js +0 -112
- package/dist/webauthn.js.map +0 -1
package/dist/auth-client.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Consumer-side helper for Auth Worker Service Binding.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* import { createAuthClient, getCookie } from '@arcblock/did-connect-cloudflare/client';
|
|
6
|
-
* const client = createAuthClient(env.AUTH);
|
|
7
|
-
* const caller = await client.verify(request);
|
|
8
|
-
*/
|
|
9
|
-
/** Extract a named cookie value from a Request. */
|
|
10
|
-
export function getCookie(request, name) {
|
|
11
|
-
const cookie = request.headers.get("Cookie");
|
|
12
|
-
if (!cookie)
|
|
13
|
-
return null;
|
|
14
|
-
const match = cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
|
|
15
|
-
return match ? match[1] : null;
|
|
16
|
-
}
|
|
17
|
-
/** Create a typed client wrapper around an AuthRPC binding. */
|
|
18
|
-
export function createAuthClient(binding) {
|
|
19
|
-
return {
|
|
20
|
-
async verify(request) {
|
|
21
|
-
const jwt = getCookie(request, "login_token");
|
|
22
|
-
return jwt ? binding.verify(jwt) : null;
|
|
23
|
-
},
|
|
24
|
-
async verifyFull(request) {
|
|
25
|
-
const jwt = getCookie(request, "login_token");
|
|
26
|
-
return jwt ? binding.verifyFull(jwt) : null;
|
|
27
|
-
},
|
|
28
|
-
async resolveIdentity(request, instanceDid) {
|
|
29
|
-
const jwt = getCookie(request, "login_token");
|
|
30
|
-
const authHeader = request.headers.get("Authorization");
|
|
31
|
-
return binding.resolveIdentity(jwt, authHeader, instanceDid);
|
|
32
|
-
},
|
|
33
|
-
/** Return a redirect-to-login or 401 response for unauthenticated requests. */
|
|
34
|
-
unauthorized(request) {
|
|
35
|
-
if (request.headers.get("Upgrade") === "websocket") {
|
|
36
|
-
return new Response(null, { status: 401 });
|
|
37
|
-
}
|
|
38
|
-
return Response.redirect(new URL("/.well-known/service/login", request.url).href);
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=auth-client.js.map
|
package/dist/auth-client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-client.js","sourceRoot":"","sources":["../src/auth-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,mDAAmD;AACnD,MAAM,UAAU,SAAS,CAAC,OAAgB,EAAE,IAAY;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,cAAc,IAAI,UAAU,CAAC,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,gBAAgB,CAAC,OAAyB;IACxD,OAAO;QACL,KAAK,CAAC,MAAM,CAAC,OAAgB;YAC3B,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1C,CAAC;QAED,KAAK,CAAC,UAAU,CAAC,OAAgB;YAC/B,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9C,CAAC;QAED,KAAK,CAAC,eAAe,CACnB,OAAgB,EAChB,WAAoB;YAEpB,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YACxD,OAAO,OAAO,CAAC,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAED,+EAA+E;QAC/E,YAAY,CAAC,OAAgB;YAC3B,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,WAAW,EAAE,CAAC;gBACnD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7C,CAAC;YACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,4BAA4B,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QACpF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AuthEntrypoint — Master Worker RPC service for federated auth.
|
|
3
|
-
*
|
|
4
|
-
* In a Cloudflare Workers multi-site setup, the master worker exposes
|
|
5
|
-
* this class via WorkerEntrypoint. Member workers call it via Service Bindings
|
|
6
|
-
* for DID derivation (OAuth/Email) and wallet info (DID Connect delegation).
|
|
7
|
-
*
|
|
8
|
-
* Usage in master worker:
|
|
9
|
-
* import { WorkerEntrypoint } from "cloudflare:workers";
|
|
10
|
-
* export class AuthEntrypoint extends WorkerEntrypoint<Env> {
|
|
11
|
-
* deriveDID(sub: string) { return deriveDIDLocal(sub, this.env.APP_SK); }
|
|
12
|
-
* getWalletInfo() { return getWalletInfoLocal(this.env.APP_SK); }
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* This module provides the pure functions that the entrypoint methods delegate to.
|
|
16
|
-
*/
|
|
17
|
-
/** Interface matching what AuthEntrypoint exposes via RPC. */
|
|
18
|
-
export interface AuthEntrypointInterface {
|
|
19
|
-
deriveDID(sub: string): Promise<{
|
|
20
|
-
did: string;
|
|
21
|
-
pk: string;
|
|
22
|
-
}> | {
|
|
23
|
-
did: string;
|
|
24
|
-
pk: string;
|
|
25
|
-
};
|
|
26
|
-
getWalletInfo(): Promise<{
|
|
27
|
-
address: string;
|
|
28
|
-
pk: string;
|
|
29
|
-
}> | {
|
|
30
|
-
address: string;
|
|
31
|
-
pk: string;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/** Derive DID locally using the app's secret key. */
|
|
35
|
-
export declare function deriveDIDLocal(sub: string, appSk: string): {
|
|
36
|
-
did: string;
|
|
37
|
-
pk: string;
|
|
38
|
-
};
|
|
39
|
-
/** Get the app wallet's public info (address, not DID — for WalletAuthenticator.delegator).
|
|
40
|
-
* When appPsk is provided, returns the permanent wallet info (for delegation). */
|
|
41
|
-
export declare function getWalletInfoLocal(appSk: string, appPsk?: string): {
|
|
42
|
-
address: string;
|
|
43
|
-
pk: string;
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=auth-entrypoint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-entrypoint.d.ts","sourceRoot":"","sources":["../src/auth-entrypoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,8DAA8D;AAC9D,MAAM,WAAW,uBAAuB;IACtC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3F,aAAa,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7F;AAED,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAGtF;AAED;mFACmF;AACnF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAIlG"}
|
package/dist/auth-entrypoint.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AuthEntrypoint — Master Worker RPC service for federated auth.
|
|
3
|
-
*
|
|
4
|
-
* In a Cloudflare Workers multi-site setup, the master worker exposes
|
|
5
|
-
* this class via WorkerEntrypoint. Member workers call it via Service Bindings
|
|
6
|
-
* for DID derivation (OAuth/Email) and wallet info (DID Connect delegation).
|
|
7
|
-
*
|
|
8
|
-
* Usage in master worker:
|
|
9
|
-
* import { WorkerEntrypoint } from "cloudflare:workers";
|
|
10
|
-
* export class AuthEntrypoint extends WorkerEntrypoint<Env> {
|
|
11
|
-
* deriveDID(sub: string) { return deriveDIDLocal(sub, this.env.APP_SK); }
|
|
12
|
-
* getWalletInfo() { return getWalletInfoLocal(this.env.APP_SK); }
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* This module provides the pure functions that the entrypoint methods delegate to.
|
|
16
|
-
*/
|
|
17
|
-
import { fromAppDid } from "@arcblock/did-ext";
|
|
18
|
-
import { fromSecretKey } from "@ocap/wallet";
|
|
19
|
-
/** Derive DID locally using the app's secret key. */
|
|
20
|
-
export function deriveDIDLocal(sub, appSk) {
|
|
21
|
-
const wallet = fromAppDid(sub, appSk);
|
|
22
|
-
return { did: wallet.address, pk: wallet.publicKey };
|
|
23
|
-
}
|
|
24
|
-
/** Get the app wallet's public info (address, not DID — for WalletAuthenticator.delegator).
|
|
25
|
-
* When appPsk is provided, returns the permanent wallet info (for delegation). */
|
|
26
|
-
export function getWalletInfoLocal(appSk, appPsk) {
|
|
27
|
-
const sk = appPsk || appSk;
|
|
28
|
-
const wallet = fromSecretKey(sk);
|
|
29
|
-
return { address: wallet.address, pk: wallet.publicKey };
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=auth-entrypoint.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-entrypoint.js","sourceRoot":"","sources":["../src/auth-entrypoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAQ7C,qDAAqD;AACrD,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,KAAa;IACvD,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;AACvD,CAAC;AAED;mFACmF;AACnF,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,MAAe;IAC/D,MAAM,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC;IAC3B,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IACjC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;AAC3D,CAAC"}
|
package/dist/auth-handler.d.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AuthHandler — Unified auth entry point for Cloudflare Workers.
|
|
3
|
-
*
|
|
4
|
-
* Combines Auth (passkey) + TeamHandler into a single, easy-to-integrate handler.
|
|
5
|
-
* Internally creates D1Store — callers never need to touch it.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* const auth = createAuthHandler({ db: env.BLOCKLET_SERVICE_DB, jwtSecret: env.JWT_SECRET, rpName: "My App" });
|
|
9
|
-
* const r = await auth.route(req); // handles passkey/team/logout routes
|
|
10
|
-
* if (r) return r;
|
|
11
|
-
* const caller = await auth.verifyFull(req); // auth gate
|
|
12
|
-
* if (!caller) return auth.unauthorized(req);
|
|
13
|
-
*/
|
|
14
|
-
import type { AuthEntrypointInterface } from "./identity/auth-entrypoint.js";
|
|
15
|
-
import type { CallerIdentity } from "./types.js";
|
|
16
|
-
export interface AuthHandlerOptions {
|
|
17
|
-
/** D1 database binding. */
|
|
18
|
-
db: D1Database;
|
|
19
|
-
/** Secret used to sign/verify JWTs (HMAC-SHA256). */
|
|
20
|
-
jwtSecret: string;
|
|
21
|
-
/** Relying Party name shown in WebAuthn prompts. */
|
|
22
|
-
rpName: string;
|
|
23
|
-
/** Relying Party ID — defaults to hostname from request.
|
|
24
|
-
* Use a string for static rpID (e.g. "example.com" for cross-subdomain passkeys),
|
|
25
|
-
* or a function for dynamic resolution based on the request. */
|
|
26
|
-
rpID?: string | ((request: Request) => string);
|
|
27
|
-
/** JWT expiration in seconds (default: 7 days). */
|
|
28
|
-
jwtExpiresIn?: number;
|
|
29
|
-
/** Cookie name for the auth JWT (default: "login_token"). */
|
|
30
|
-
cookieName?: string;
|
|
31
|
-
/** KV namespace for DID Connect token storage. When provided with appSk, enables DID Wallet login. */
|
|
32
|
-
kv?: KVNamespace;
|
|
33
|
-
/** Application secret key for DID Connect wallet authentication. */
|
|
34
|
-
appSk?: string;
|
|
35
|
-
/** Application info shown to the wallet during DID Connect. */
|
|
36
|
-
appInfo?: {
|
|
37
|
-
name: string;
|
|
38
|
-
description?: string;
|
|
39
|
-
icon?: string;
|
|
40
|
-
};
|
|
41
|
-
/** Resend API key for email verification. Optional — can also be configured via Admin Settings (D1 email:config). */
|
|
42
|
-
resendApiKey?: string;
|
|
43
|
-
/** From address for verification emails. Optional — can also be configured via Admin Settings (D1 email:config). */
|
|
44
|
-
emailFrom?: string;
|
|
45
|
-
/** Service Binding to master Worker (federated mode). */
|
|
46
|
-
authMaster?: AuthEntrypointInterface;
|
|
47
|
-
/** Master site OAuth callback origin (federated mode). */
|
|
48
|
-
masterOAuthOrigin?: string;
|
|
49
|
-
/** Explicit app DID, otherwise derived from appSk. */
|
|
50
|
-
appDid?: string;
|
|
51
|
-
/** Server version reported in __blocklet__.js (default: '1.0.0'). */
|
|
52
|
-
serverVersion?: string;
|
|
53
|
-
/** Permanent secret key (PSK) — first SK before rotation.
|
|
54
|
-
* When set and different from appSk, enables DID Connect delegation
|
|
55
|
-
* and correct appPid in __blocklet__.js. */
|
|
56
|
-
appPsk?: string;
|
|
57
|
-
/** R2 bucket for logo/media storage. */
|
|
58
|
-
r2?: R2Bucket;
|
|
59
|
-
}
|
|
60
|
-
/** Membership record from the memberships table. */
|
|
61
|
-
export interface StoredMembership {
|
|
62
|
-
user_did: string;
|
|
63
|
-
instance_did: string;
|
|
64
|
-
role: string;
|
|
65
|
-
invited_by: string | null;
|
|
66
|
-
joined_at: string;
|
|
67
|
-
}
|
|
68
|
-
/** Rule with inlined policy data for access evaluation. */
|
|
69
|
-
export interface RuleWithPolicyForInstance {
|
|
70
|
-
id: string;
|
|
71
|
-
pathPattern: string;
|
|
72
|
-
priority: number;
|
|
73
|
-
roles: string | null;
|
|
74
|
-
reverse: number;
|
|
75
|
-
enabled: number;
|
|
76
|
-
}
|
|
77
|
-
export interface AuthHandler {
|
|
78
|
-
/**
|
|
79
|
-
* Handle auth-related routes: passkey API, team API, admin/invite pages, logout.
|
|
80
|
-
* Returns a Response if the route matched, or null to let the caller continue.
|
|
81
|
-
* @param context Optional instance context — instanceDid is passed to team/access key handlers.
|
|
82
|
-
*/
|
|
83
|
-
route(request: Request, context?: {
|
|
84
|
-
instanceDid?: string;
|
|
85
|
-
}): Promise<Response | null>;
|
|
86
|
-
/** Verify JWT from cookie — lightweight, no DB query. */
|
|
87
|
-
verify(request: Request): Promise<CallerIdentity | null>;
|
|
88
|
-
/** Full verification: JWT + DB user existence + approval check. */
|
|
89
|
-
verifyFull(request: Request): Promise<CallerIdentity | null>;
|
|
90
|
-
/** Return the login page HTML response. */
|
|
91
|
-
loginPage(): Promise<Response>;
|
|
92
|
-
/**
|
|
93
|
-
* Return an appropriate unauthorized response:
|
|
94
|
-
* - WebSocket upgrade requests → 401
|
|
95
|
-
* - Normal HTTP requests → login page
|
|
96
|
-
*/
|
|
97
|
-
unauthorized(request: Request): Promise<Response>;
|
|
98
|
-
/**
|
|
99
|
-
* Resolve caller identity from request (access key or JWT), without enforcing access.
|
|
100
|
-
* Returns the identity if found, null otherwise.
|
|
101
|
-
* @param context Optional instance context for access key instance validation.
|
|
102
|
-
*/
|
|
103
|
-
resolveIdentity(request: Request, context?: {
|
|
104
|
-
instanceDid?: string;
|
|
105
|
-
}): Promise<CallerIdentity | null>;
|
|
106
|
-
/**
|
|
107
|
-
* Enforce access policy for a request path.
|
|
108
|
-
* Evaluates rules from D1, checks caller identity + role + blocked status.
|
|
109
|
-
*
|
|
110
|
-
* When `opts.caller` is provided, uses it instead of resolving from the request.
|
|
111
|
-
* This enables the authenticate → resolve blocklet → authorize pipeline.
|
|
112
|
-
*/
|
|
113
|
-
enforceAccess(request: Request, opts?: {
|
|
114
|
-
caller?: CallerIdentity | null;
|
|
115
|
-
}): Promise<{
|
|
116
|
-
response: Response;
|
|
117
|
-
} | {
|
|
118
|
-
caller: CallerIdentity | null;
|
|
119
|
-
}>;
|
|
120
|
-
/**
|
|
121
|
-
* Get membership record for a user in an instance (D16).
|
|
122
|
-
* Returns null if no membership exists.
|
|
123
|
-
*/
|
|
124
|
-
getMembership(userDid: string, instanceDid: string): Promise<StoredMembership | null>;
|
|
125
|
-
/**
|
|
126
|
-
* Get active security rules for an instance, merged with global rules (D16).
|
|
127
|
-
* Instance-specific rules take priority over global rules.
|
|
128
|
-
*/
|
|
129
|
-
getActiveRulesForInstance(instanceDid: string): Promise<RuleWithPolicyForInstance[]>;
|
|
130
|
-
/**
|
|
131
|
-
* Seed a default security rule for a newly launched instance (Phase 3).
|
|
132
|
-
*/
|
|
133
|
-
seedInstanceDefaults(instanceDid: string): Promise<void>;
|
|
134
|
-
}
|
|
135
|
-
export declare function createAuthHandler(options: AuthHandlerOptions): AuthHandler;
|
|
136
|
-
//# sourceMappingURL=auth-handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-handler.d.ts","sourceRoot":"","sources":["../src/auth-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAU7E,OAAO,KAAK,EAAE,cAAc,EAAQ,MAAM,YAAY,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,2BAA2B;IAC3B,EAAE,EAAE,UAAU,CAAC;IACf,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf;;qEAEiE;IACjE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC;IAC/C,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,sGAAsG;IACtG,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAA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