@plitzi/sdk-server 0.38.24 → 0.39.1
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/CHANGELOG.md +162 -1
- package/README.md +55 -9
- package/dist/actions.d.ts +4 -1
- package/dist/actions.js +3 -2
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +5 -4
- package/dist/core/auth/api/accounts.d.ts +11 -0
- package/dist/core/auth/api/accounts.js +175 -0
- package/dist/core/auth/api/admin.d.ts +41 -0
- package/dist/core/auth/api/admin.js +146 -0
- package/dist/core/auth/api/context.d.ts +119 -0
- package/dist/core/auth/api/context.js +262 -0
- package/dist/core/auth/api/factors.d.ts +31 -0
- package/dist/core/auth/api/factors.js +209 -0
- package/dist/core/auth/api/index.d.ts +94 -0
- package/dist/core/auth/api/index.js +43 -0
- package/dist/core/auth/api/profile.d.ts +43 -0
- package/dist/core/auth/api/profile.js +243 -0
- package/dist/core/auth/api/session.d.ts +62 -0
- package/dist/core/auth/api/session.js +312 -0
- package/dist/core/auth/{api.d.ts → api/types.d.ts} +41 -195
- package/dist/core/auth/api/values.d.ts +67 -0
- package/dist/core/auth/api/values.js +90 -0
- package/dist/core/auth/createAuth.d.ts +49 -39
- package/dist/core/auth/createAuth.js +21 -1
- package/dist/core/auth/oauth/client.d.ts +2 -2
- package/dist/core/auth/oauth/client.js +6 -1
- package/dist/core/auth/oauth/index.d.ts +30 -7
- package/dist/core/auth/oauth/index.js +33 -14
- package/dist/core/auth/oauth/providers/github.js +1 -1
- package/dist/core/auth/oauth/providers/google.js +1 -1
- package/dist/core/auth/oauth/providers/oidc.d.ts +40 -0
- package/dist/core/auth/oauth/providers/oidc.js +197 -0
- package/dist/core/auth/oauth/state.d.ts +2 -0
- package/dist/core/auth/oauth/state.js +2 -0
- package/dist/core/auth/oauth/types.d.ts +21 -3
- package/dist/core/auth/oauth/types.js +4 -1
- package/dist/core/auth/routes.js +1 -1
- package/dist/core/auth/tokens.d.ts +3 -1
- package/dist/core/auth/tokens.js +2 -1
- package/dist/core/configSeam.d.ts +0 -4
- package/dist/core/configSeam.js +12 -1
- package/dist/core/createServer.js +16 -4
- package/dist/core/freePort.d.ts +10 -0
- package/dist/core/freePort.js +39 -1
- package/dist/core/handlers/socialRouteHandlers.d.ts +9 -1
- package/dist/core/handlers/socialRouteHandlers.js +46 -12
- package/dist/core/health.d.ts +1 -0
- package/dist/core/health.js +2 -1
- package/dist/core/http/stages/authRoutes.d.ts +6 -0
- package/dist/core/http/stages/authRoutes.js +42 -1
- package/dist/core/http/stages/images.js +5 -3
- package/dist/core/http/stages/livePages.js +1 -1
- package/dist/core/server/fleet/relay.js +9 -1
- package/dist/core/server/fleet/stores.d.ts +7 -0
- package/dist/core/server/fleet/stores.js +15 -2
- package/dist/core/server/pageServer.js +5 -1
- package/dist/core/services/realtime.js +4 -2
- package/dist/core/services/registry.js +7 -1
- package/dist/core/services/robotsTxt.d.ts +16 -0
- package/dist/core/services/robotsTxt.js +50 -0
- package/dist/core/services/servedSpace.d.ts +8 -0
- package/dist/core/services/servedSpace.js +16 -0
- package/dist/core/services/sitemapXml.d.ts +7 -0
- package/dist/core/services/sitemapXml.js +37 -0
- package/dist/functions-api.d.ts +69 -2
- package/dist/helpers/fileStore.d.ts +60 -0
- package/dist/helpers/fileStore.js +127 -0
- package/dist/helpers/outboundGuard.d.ts +32 -3
- package/dist/helpers/outboundGuard.js +50 -5
- package/dist/hosts/project/agentRuns.d.ts +24 -0
- package/dist/hosts/project/agentRuns.js +107 -0
- package/dist/hosts/project/laterAsks.d.ts +41 -0
- package/dist/hosts/project/laterAsks.js +117 -0
- package/dist/hosts/project/plugins.js +11 -4
- package/dist/hosts/project/serveProject.d.ts +18 -1
- package/dist/hosts/project/serveProject.js +89 -25
- package/dist/hosts/project/spaceFailure.d.ts +4 -0
- package/dist/hosts/project/spaceFailure.js +10 -0
- package/dist/hosts/project/watchSpace.d.ts +5 -5
- package/dist/hosts/project/watchSpace.js +15 -6
- package/dist/index.js +2 -2
- package/dist/kernel.js +1 -1
- package/dist/modules/actions/connectorWrite.js +3 -1
- package/dist/modules/actions/index.js +1 -1
- package/dist/modules/actions/jobs/fileQueue.d.ts +34 -0
- package/dist/modules/actions/jobs/fileQueue.js +72 -0
- package/dist/modules/actions/jobs/index.js +3 -3
- package/dist/modules/actions/jobs/memoryQueue.js +6 -215
- package/dist/modules/actions/jobs/queueDocument.d.ts +14 -0
- package/dist/modules/actions/jobs/queueDocument.js +22 -0
- package/dist/modules/actions/jobs/queueRules.d.ts +39 -0
- package/dist/modules/actions/jobs/queueRules.js +270 -0
- package/dist/modules/actions/moduleFor.js +2 -0
- package/dist/modules/actions/runtime/fileKv.d.ts +3 -1
- package/dist/modules/actions/runtime/fileKv.js +12 -98
- package/dist/modules/actions/runtime/guards.d.ts +19 -1
- package/dist/modules/actions/runtime/guards.js +10 -1
- package/dist/modules/actions/runtime/kvChange.d.ts +40 -0
- package/dist/modules/actions/runtime/kvChange.js +23 -1
- package/dist/modules/actions/runtime/kvList.d.ts +4 -0
- package/dist/modules/actions/runtime/kvList.js +5 -1
- package/dist/modules/actions/runtime/kvStore.js +15 -1
- package/dist/modules/actions/runtime/namespaceKv.js +2 -0
- package/dist/modules/actions/runtime/renderResolver.js +31 -5
- package/dist/modules/actions/runtime/runAction.js +16 -6
- package/dist/modules/actions/runtime/scope.js +11 -0
- package/dist/modules/actions/runtime/taskContext.js +11 -32
- package/dist/modules/actions/tasks/auth.js +2 -0
- package/dist/modules/actions/tasks/connector.js +6 -2
- package/dist/modules/actions/tasks/flow.js +5 -0
- package/dist/modules/actions/tasks/http.js +2 -1
- package/dist/modules/actions/tasks/kv.js +5 -0
- package/dist/modules/actions/tasks/list.js +11 -2
- package/dist/modules/actions/tasks/transform.js +2 -0
- package/dist/modules/actions/transport/callHandler.js +25 -4
- package/dist/modules/actions/types.d.ts +46 -1
- package/dist/modules/connectors/engine.d.ts +7 -2
- package/dist/modules/connectors/engine.js +4 -4
- package/dist/modules/connectors/resolver.d.ts +2 -1
- package/dist/modules/connectors/resolver.js +3 -2
- package/dist/modules/functions/build.d.ts +7 -2
- package/dist/modules/functions/build.js +90 -6
- package/dist/modules/functions/capabilities.js +16 -0
- package/dist/modules/functions/context.js +6 -2
- package/dist/modules/functions/contract.d.ts +39 -1
- package/dist/modules/functions/driver.d.ts +2 -1
- package/dist/modules/functions/driver.js +35 -0
- package/dist/modules/functions/load.d.ts +1 -1
- package/dist/modules/functions/load.js +2 -2
- package/dist/modules/functions/manifest.js +7 -1
- package/dist/modules/functions/oauth.d.ts +1 -1
- package/dist/modules/functions/oauth.js +4 -4
- package/dist/modules/functions/protocol.d.ts +6 -0
- package/dist/modules/functions/sandbox/guest/bytes.d.ts +27 -0
- package/dist/modules/functions/sandbox/guest/bytes.js +108 -0
- package/dist/modules/functions/sandbox/guest/crypto.d.ts +47 -0
- package/dist/modules/functions/sandbox/guest/crypto.js +144 -0
- package/dist/modules/functions/sandbox/guest/events.d.ts +152 -0
- package/dist/modules/functions/sandbox/guest/events.js +143 -0
- package/dist/modules/functions/sandbox/guest/fetch.d.ts +305 -0
- package/dist/modules/functions/sandbox/guest/fetch.js +237 -0
- package/dist/modules/functions/sandbox/guest/index.d.ts +28 -0
- package/dist/modules/functions/sandbox/guest/index.js +130 -0
- package/dist/modules/functions/sandbox/{guest.d.ts → guest/types.d.ts} +5 -12
- package/dist/modules/functions/sandbox/isolate.js +20 -6
- package/dist/modules/functions/space.js +2 -8
- package/dist/modules/images/imageProxy.d.ts +3 -2
- package/dist/modules/images/imageProxy.js +2 -2
- package/dist/modules/mongo/jobQueue.js +0 -19
- package/dist/modules/mysql/accounts.js +12 -5
- package/dist/modules/mysql/jobs/index.d.ts +1 -1
- package/dist/modules/mysql/jobs/schema.d.ts +0 -6
- package/dist/modules/mysql/jobs/schema.js +2 -46
- package/dist/modules/mysql/schema.js +26 -1
- package/dist/modules/mysql/sessions.js +2 -1
- package/dist/modules/realtime/handlers.d.ts +9 -4
- package/dist/modules/realtime/handlers.js +20 -3
- package/dist/modules/realtime/hub.d.ts +4 -2
- package/dist/modules/realtime/hub.js +36 -4
- package/dist/modules/realtime/index.d.ts +14 -0
- package/dist/modules/realtime/index.js +14 -1
- package/dist/modules/realtime/presence.d.ts +33 -0
- package/dist/modules/realtime/presence.js +56 -0
- package/dist/modules/realtime/socket.d.ts +3 -1
- package/dist/modules/realtime/socket.js +2 -2
- package/dist/modules/rsc/connectorRscData.d.ts +6 -1
- package/dist/modules/rsc/connectorRscData.js +27 -6
- package/dist/modules/rsc/externalQueryReader.d.ts +28 -0
- package/dist/modules/rsc/externalQueryReader.js +43 -0
- package/dist/modules/rsc/handler.js +1 -1
- package/dist/modules/rsc/resolveRscData.d.ts +11 -1
- package/dist/modules/rsc/resolveRscData.js +86 -16
- package/dist/modules/runtime/inside.js +1 -1
- package/dist/modules/runtime/runner.js +2 -1
- package/dist/modules/sqlite/jobQueue.d.ts +35 -0
- package/dist/modules/sqlite/jobQueue.js +56 -0
- package/dist/modules/sqlite/kv.d.ts +1 -1
- package/dist/modules/sqlite/kv.js +2 -10
- package/dist/modules/sqlite/open.d.ts +3 -0
- package/dist/modules/sqlite/open.js +13 -0
- package/dist/modules/ssr/Component.d.ts +5 -1
- package/dist/modules/ssr/Component.js +3 -1
- package/dist/modules/ssr/applySSRResult.d.ts +8 -1
- package/dist/modules/ssr/applySSRResult.js +23 -3
- package/dist/modules/ssr/handler.js +30 -5
- package/dist/modules/ssr/prepareRender.js +31 -8
- package/dist/modules/ssr/preview.d.ts +2 -0
- package/dist/modules/ssr/preview.js +6 -3
- package/dist/modules/ssr/registerExternalPlugins.d.ts +2 -6
- package/dist/modules/ssr/registerExternalPlugins.js +2 -2
- package/dist/modules/ssr/resolvePageSeo.d.ts +11 -0
- package/dist/modules/ssr/resolvePageSeo.js +13 -2
- package/dist/modules/ssr/streamBody.js +2 -2
- package/dist/modules/ssr/views/template.ejs +21 -17
- package/dist/mysql.d.ts +1 -1
- package/dist/mysql.js +2 -2
- package/dist/plugins/manager.d.ts +5 -0
- package/dist/plugins/manager.js +9 -0
- package/dist/sqlite.d.ts +8 -1
- package/dist/sqlite.js +3 -1
- package/package.json +5 -5
- package/skills/plitzi-authoring/CHEATSHEET.md +6 -6
- package/skills/plitzi-authoring/SKILL.md +4 -2
- package/skills/plitzi-authoring/recipes/accordion.ts +2 -1
- package/skills/plitzi-authoring/recipes/carousel.ts +24 -3
- package/skills/plitzi-authoring/recipes/detail-page.ts +0 -1
- package/skills/plitzi-authoring/recipes/embed-and-svg.ts +3 -1
- package/skills/plitzi-authoring/recipes/filter-a-list.ts +0 -1
- package/skills/plitzi-authoring/recipes/show-data.ts +0 -1
- package/skills/plitzi-authoring/recipes/typed-data.ts +0 -1
- package/skills/plitzi-authoring/reference/accessibility.md +10 -2
- package/skills/plitzi-authoring/reference/auth.md +15 -4
- package/skills/plitzi-authoring/reference/authoring-errors.md +55 -12
- package/skills/plitzi-authoring/reference/colours-and-motion.md +7 -1
- package/skills/plitzi-authoring/reference/components.md +4 -1
- package/skills/plitzi-authoring/reference/data-and-visibility.md +31 -22
- package/skills/plitzi-authoring/reference/efficiency.md +2 -1
- package/skills/plitzi-authoring/reference/elements-and-styles.md +16 -15
- package/skills/plitzi-authoring/reference/flows.md +29 -17
- package/skills/plitzi-authoring/reference/kept-state.md +20 -0
- package/skills/plitzi-authoring/reference/layouts.md +18 -2
- package/skills/plitzi-authoring/reference/lists.md +20 -4
- package/skills/plitzi-authoring/reference/plugin-reach.md +12 -0
- package/skills/plitzi-authoring/reference/plugins.md +17 -3
- package/skills/plitzi-authoring/reference/realtime.md +8 -5
- package/skills/plitzi-authoring/reference/structure.md +17 -1
- package/skills/plitzi-authoring/reference/templates.md +11 -3
- package/skills/plitzi-authoring/reference/testing.md +82 -5
- package/skills/plitzi-authoring/reference/typed-sources.md +6 -0
- package/skills/plitzi-authoring/reference/validation.md +1 -1
- package/dist/core/auth/api.js +0 -1323
- package/dist/modules/functions/sandbox/guest.js +0 -662
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CredentialCarrier } from '../credentials';
|
|
2
|
+
import { Actor } from '../identity';
|
|
3
|
+
import { AuthContext } from './context';
|
|
4
|
+
import { AccountStatus, AccountQuery, AuthOutcome } from './types';
|
|
5
|
+
/** What an admin does to other accounts. */
|
|
6
|
+
export declare const adminFlows: ({ adapters, impersonationPermission, record, capabilities, requireAdmin, issue, grantBody }: AuthContext) => {
|
|
7
|
+
admin: {
|
|
8
|
+
list: (actor: Actor | undefined, query: AccountQuery) => Promise<AuthOutcome>;
|
|
9
|
+
get: (actor: Actor | undefined, userId: number) => Promise<AuthOutcome>;
|
|
10
|
+
/**
|
|
11
|
+
* Suspend, block or restore an account — and **end its sessions when it stops being active**.
|
|
12
|
+
*
|
|
13
|
+
* That second half is the whole point. A ban that leaves the credential working is not a ban, it is a note
|
|
14
|
+
* in a database; the person stays signed in until their token happens to lapse.
|
|
15
|
+
*/
|
|
16
|
+
setStatus: (actor: Actor | undefined, userId: number, status: AccountStatus) => Promise<AuthOutcome>;
|
|
17
|
+
setRoles: (actor: Actor | undefined, userId: number, roles: unknown) => Promise<AuthOutcome>;
|
|
18
|
+
remove: (actor: Actor | undefined, userId: number) => Promise<AuthOutcome>;
|
|
19
|
+
/**
|
|
20
|
+
* A session AS somebody else, for support that has to see what they see.
|
|
21
|
+
*
|
|
22
|
+
* Three properties make it something a deployment can live with, and all three are deliberate:
|
|
23
|
+
*
|
|
24
|
+
* - **It says so.** The credential carries `act` (RFC 8693), so every request made with it can be told from
|
|
25
|
+
* one the account holder made — `Actor.impersonatedBy` is that claim, read back. A borrowed session that
|
|
26
|
+
* is indistinguishable from a real one turns an audit log into fiction.
|
|
27
|
+
* - **It is short and cannot renew.** Fifteen minutes by default and no refresh token, so it expires rather
|
|
28
|
+
* than becoming a permanent second key to somebody's account.
|
|
29
|
+
* - **It is off unless asked for**, behind its own permission — see `impersonationPermission`.
|
|
30
|
+
*
|
|
31
|
+
* The session is answered in the BODY and no cookie is written. Swapping the administrator's own session
|
|
32
|
+
* cookie for this one would sign them out of the account they administer from, and getting back would mean
|
|
33
|
+
* signing in again; whoever asked decides where to put a credential they were handed.
|
|
34
|
+
*
|
|
35
|
+
* One caveat a deployment has to know: a store that keeps a single session per account — no `session` table —
|
|
36
|
+
* will overwrite the subject's own session with this one, signing them out. Anything with per-session rows,
|
|
37
|
+
* which is what `createMysqlStore` builds, does not.
|
|
38
|
+
*/
|
|
39
|
+
impersonate: (actor: Actor | undefined, userId: number, carrier?: CredentialCarrier) => Promise<AuthOutcome>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { LIFETIME, NOT_OFFERED, STATUSES, clientOf, profileOf, refuse } from "./values.js";
|
|
2
|
+
import { checkPermission } from "../authorize.js";
|
|
3
|
+
//#region src/core/auth/api/admin.ts
|
|
4
|
+
/** What an admin does to other accounts. */
|
|
5
|
+
var adminFlows = ({ adapters, impersonationPermission, record, capabilities, requireAdmin, issue, grantBody }) => ({ admin: {
|
|
6
|
+
list: async (actor, query) => {
|
|
7
|
+
const denial = requireAdmin(actor);
|
|
8
|
+
if (denial) return denial;
|
|
9
|
+
if (!adapters.listAccounts) return NOT_OFFERED;
|
|
10
|
+
const { accounts, total } = await adapters.listAccounts(query);
|
|
11
|
+
return {
|
|
12
|
+
ok: true,
|
|
13
|
+
body: {
|
|
14
|
+
accounts: accounts.map(profileOf),
|
|
15
|
+
total
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
get: async (actor, userId) => {
|
|
20
|
+
const denial = requireAdmin(actor);
|
|
21
|
+
if (denial) return denial;
|
|
22
|
+
const account = await adapters.findById?.(userId);
|
|
23
|
+
if (!account) return refuse(404, "No such account");
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
body: {
|
|
27
|
+
account: profileOf(account),
|
|
28
|
+
access: await adapters.loadAccess(userId)
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Suspend, block or restore an account — and **end its sessions when it stops being active**.
|
|
34
|
+
*
|
|
35
|
+
* That second half is the whole point. A ban that leaves the credential working is not a ban, it is a note
|
|
36
|
+
* in a database; the person stays signed in until their token happens to lapse.
|
|
37
|
+
*/
|
|
38
|
+
setStatus: async (actor, userId, status) => {
|
|
39
|
+
const denial = requireAdmin(actor, userId);
|
|
40
|
+
if (denial) return denial;
|
|
41
|
+
if (!adapters.setStatus) return NOT_OFFERED;
|
|
42
|
+
if (!STATUSES.includes(status)) return refuse(400, `Status must be one of ${STATUSES.join(", ")}`);
|
|
43
|
+
if (!await adapters.findById?.(userId)) return refuse(404, "No such account");
|
|
44
|
+
await adapters.setStatus(userId, status);
|
|
45
|
+
if (status !== "active") await adapters.clearSession({ userId });
|
|
46
|
+
record({
|
|
47
|
+
type: "admin.status-changed",
|
|
48
|
+
userId,
|
|
49
|
+
actorId: actor?.id,
|
|
50
|
+
detail: { status }
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
ok: true,
|
|
54
|
+
body: {
|
|
55
|
+
success: true,
|
|
56
|
+
status
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
setRoles: async (actor, userId, roles) => {
|
|
61
|
+
const denial = requireAdmin(actor);
|
|
62
|
+
if (denial) return denial;
|
|
63
|
+
if (!adapters.setRoles) return NOT_OFFERED;
|
|
64
|
+
if (!Array.isArray(roles) || roles.some((role) => typeof role !== "string")) return refuse(400, "Roles must be a list of names");
|
|
65
|
+
const names = roles;
|
|
66
|
+
if (!await adapters.findById?.(userId)) return refuse(404, "No such account");
|
|
67
|
+
await adapters.setRoles(userId, names);
|
|
68
|
+
record({
|
|
69
|
+
type: "admin.roles-changed",
|
|
70
|
+
userId,
|
|
71
|
+
actorId: actor?.id,
|
|
72
|
+
detail: { roles: names }
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
body: {
|
|
77
|
+
success: true,
|
|
78
|
+
roles: names
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
remove: async (actor, userId) => {
|
|
83
|
+
const denial = requireAdmin(actor, userId);
|
|
84
|
+
if (denial) return denial;
|
|
85
|
+
if (!adapters.deleteAccount) return NOT_OFFERED;
|
|
86
|
+
if (!await adapters.findById?.(userId)) return refuse(404, "No such account");
|
|
87
|
+
await adapters.deleteAccount(userId);
|
|
88
|
+
record({
|
|
89
|
+
type: "admin.account-deleted",
|
|
90
|
+
userId,
|
|
91
|
+
actorId: actor?.id
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
ok: true,
|
|
95
|
+
body: { success: true }
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* A session AS somebody else, for support that has to see what they see.
|
|
100
|
+
*
|
|
101
|
+
* Three properties make it something a deployment can live with, and all three are deliberate:
|
|
102
|
+
*
|
|
103
|
+
* - **It says so.** The credential carries `act` (RFC 8693), so every request made with it can be told from
|
|
104
|
+
* one the account holder made — `Actor.impersonatedBy` is that claim, read back. A borrowed session that
|
|
105
|
+
* is indistinguishable from a real one turns an audit log into fiction.
|
|
106
|
+
* - **It is short and cannot renew.** Fifteen minutes by default and no refresh token, so it expires rather
|
|
107
|
+
* than becoming a permanent second key to somebody's account.
|
|
108
|
+
* - **It is off unless asked for**, behind its own permission — see `impersonationPermission`.
|
|
109
|
+
*
|
|
110
|
+
* The session is answered in the BODY and no cookie is written. Swapping the administrator's own session
|
|
111
|
+
* cookie for this one would sign them out of the account they administer from, and getting back would mean
|
|
112
|
+
* signing in again; whoever asked decides where to put a credential they were handed.
|
|
113
|
+
*
|
|
114
|
+
* One caveat a deployment has to know: a store that keeps a single session per account — no `session` table —
|
|
115
|
+
* will overwrite the subject's own session with this one, signing them out. Anything with per-session rows,
|
|
116
|
+
* which is what `createMysqlStore` builds, does not.
|
|
117
|
+
*/
|
|
118
|
+
impersonate: async (actor, userId, carrier) => {
|
|
119
|
+
if (!capabilities.impersonation || !impersonationPermission || !adapters.findById) return NOT_OFFERED;
|
|
120
|
+
const check = checkPermission(actor, impersonationPermission);
|
|
121
|
+
if (!check.ok) return refuse(check.status, check.error, check.status === 401 ? "missing" : void 0);
|
|
122
|
+
if (!actor || userId === actor.id) return refuse(400, "You are already signed in as yourself");
|
|
123
|
+
const account = await adapters.findById(userId);
|
|
124
|
+
if (!account) return refuse(404, "No such account");
|
|
125
|
+
if (!account.active) return refuse(403, "That account is not active");
|
|
126
|
+
const session = await issue(userId, { client: clientOf(carrier) }, {
|
|
127
|
+
actingAs: actor.id,
|
|
128
|
+
ttlSeconds: LIFETIME.impersonation,
|
|
129
|
+
renewable: false
|
|
130
|
+
});
|
|
131
|
+
record({
|
|
132
|
+
type: "admin.impersonated",
|
|
133
|
+
userId,
|
|
134
|
+
actorId: actor.id
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
ok: true,
|
|
138
|
+
body: {
|
|
139
|
+
...await grantBody(account, session),
|
|
140
|
+
impersonatedBy: actor.id
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
} });
|
|
145
|
+
//#endregion
|
|
146
|
+
export { adminFlows };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { CredentialCarrier } from '../credentials';
|
|
2
|
+
import { Actor, Identity } from '../identity';
|
|
3
|
+
import { Tokens } from '../tokens';
|
|
4
|
+
import { AccountRecord, AccountAccess, SecurityEvent, SessionContext, AccountAdapters, ThrottleAttempt, AuthApiConfig, ExchangeResult, AuthOutcome } from './types';
|
|
5
|
+
import { SSRSession } from '@plitzi/sdk-shared';
|
|
6
|
+
/** What every flow of the auth API shares: the adapters and the settings, read once, and the steps they take alike. */
|
|
7
|
+
export declare const createAuthContext: ({ tokens, identity, adapters, config }: {
|
|
8
|
+
tokens: Tokens;
|
|
9
|
+
identity: Identity;
|
|
10
|
+
adapters: AccountAdapters;
|
|
11
|
+
config?: AuthApiConfig;
|
|
12
|
+
}) => {
|
|
13
|
+
tokens: {
|
|
14
|
+
lifetimes: Record<"session" | "refresh" | "access" | "widget" | "agent" | "mfaChallenge", number>;
|
|
15
|
+
issuer: string;
|
|
16
|
+
generateUserToken: (userId: number | string, { actingAs, ttlSeconds }?: import('../tokens').UserTokenOptions) => string;
|
|
17
|
+
generateRefreshToken: (userId: number | string) => string;
|
|
18
|
+
generateWidgetToken: () => string;
|
|
19
|
+
generateMfaChallenge: (userId: number | string) => string;
|
|
20
|
+
generateSpaceToken: (spaceId: number | string, origins: string[], scope?: import('../tokens').SpaceScope, { expiresAt }?: import('../tokens').SpaceTokenOptions) => string;
|
|
21
|
+
verifyUserToken: (token: string) => import('../tokens').VerifyResult<import('../tokens').UserTokenPayload>;
|
|
22
|
+
verifyRefreshToken: (token: string) => import('../tokens').VerifyResult<import('../tokens').RefreshTokenPayload>;
|
|
23
|
+
verifyMfaChallenge: (token: string) => import('../tokens').VerifyResult<import('../tokens').MfaChallengePayload>;
|
|
24
|
+
verifyWidgetToken: (token: string) => import('../tokens').VerifyResult<import('../tokens').WidgetTokenPayload>;
|
|
25
|
+
verifySpaceToken: (token: string) => import('../tokens').VerifyResult<import('../tokens').SpaceTokenPayload & {
|
|
26
|
+
spaceId: number;
|
|
27
|
+
spaceScope: import('../tokens').SpaceScope;
|
|
28
|
+
}>;
|
|
29
|
+
needsRotation: (token: string) => boolean;
|
|
30
|
+
expiresInSeconds: (token: string) => number | undefined;
|
|
31
|
+
};
|
|
32
|
+
identity: {
|
|
33
|
+
resolveActor: (carrier: CredentialCarrier) => Promise<import('../identity').ActorResult>;
|
|
34
|
+
resolveActorFromToken: (token: string) => Promise<import('../identity').ActorResult>;
|
|
35
|
+
resolveGrant: (carrier: CredentialCarrier, options?: import('../identity').GrantOptions) => Promise<import('../identity').GrantResult>;
|
|
36
|
+
resolveGrantFromToken: (token: string, origin: string, { skipOrigin, host }?: import('../identity').GrantOptions) => Promise<import('../identity').GrantResult>;
|
|
37
|
+
can: (actor: Actor, spaceId: number, permission: string) => Promise<boolean>;
|
|
38
|
+
grantCan: (grant: import('../identity').Grant, permission: string) => Promise<boolean>;
|
|
39
|
+
};
|
|
40
|
+
adapters: AccountAdapters;
|
|
41
|
+
verifyPassword: (plain: string, hash: string) => Promise<boolean>;
|
|
42
|
+
hashPassword: (plain: string) => Promise<string>;
|
|
43
|
+
generateToken: () => string;
|
|
44
|
+
verifyOnSignup: boolean;
|
|
45
|
+
terms: {
|
|
46
|
+
version: string;
|
|
47
|
+
} | undefined;
|
|
48
|
+
adminPermission: string;
|
|
49
|
+
impersonationPermission: string | undefined;
|
|
50
|
+
policy: import('./types').PasswordPolicy;
|
|
51
|
+
rateLimit: (attempt: ThrottleAttempt) => Promise<boolean | {
|
|
52
|
+
allowed: boolean;
|
|
53
|
+
retryAfter?: number;
|
|
54
|
+
}>;
|
|
55
|
+
onMailError: ((error: unknown, message: {
|
|
56
|
+
to: string;
|
|
57
|
+
template: string;
|
|
58
|
+
}) => void) | undefined;
|
|
59
|
+
onEvent: ((event: SecurityEvent) => void) | undefined;
|
|
60
|
+
mfaIssuer: string | undefined;
|
|
61
|
+
csrf: {
|
|
62
|
+
issue: (sessionToken?: string) => string;
|
|
63
|
+
cookieName: (hostname: string) => string;
|
|
64
|
+
headerName: string;
|
|
65
|
+
write: (req: {
|
|
66
|
+
hostname: string;
|
|
67
|
+
}, res: import('../session').CookieSink, token: string) => void;
|
|
68
|
+
clear: (req: {
|
|
69
|
+
hostname: string;
|
|
70
|
+
}, res: import('../session').CookieSink) => void;
|
|
71
|
+
read: (carrier: import('../csrf').CsrfCarrier) => string | undefined;
|
|
72
|
+
required: (carrier: import('../csrf').CsrfCarrier, subject?: import('../csrf').CsrfSubject) => boolean;
|
|
73
|
+
crossSite: (carrier: import('../csrf').CsrfCarrier, alsoAllowed?: readonly string[]) => boolean;
|
|
74
|
+
verify: (carrier: import('../csrf').CsrfCarrier, sessionToken?: string) => import('../csrf').CsrfResult;
|
|
75
|
+
} | undefined;
|
|
76
|
+
record: (event: Omit<SecurityEvent, "at">) => void;
|
|
77
|
+
mintLink: (random: string, lifetime: number) => string;
|
|
78
|
+
linkExpired: (token: string) => boolean;
|
|
79
|
+
digestRecoveryCode: (code: string) => string;
|
|
80
|
+
deliver: (message: {
|
|
81
|
+
to: string;
|
|
82
|
+
template: string;
|
|
83
|
+
data: Record<string, string>;
|
|
84
|
+
}) => Promise<void>;
|
|
85
|
+
throttleSucceeded: (attempt: Omit<ThrottleAttempt, "succeeded">) => void;
|
|
86
|
+
throttled: (attempt: ThrottleAttempt) => Promise<AuthOutcome | undefined>;
|
|
87
|
+
rejectPassword: (value: string, context?: {
|
|
88
|
+
username?: string;
|
|
89
|
+
email?: string;
|
|
90
|
+
}) => Promise<AuthOutcome | undefined>;
|
|
91
|
+
capabilities: {
|
|
92
|
+
passwordLogin: boolean;
|
|
93
|
+
refresh: boolean;
|
|
94
|
+
signup: boolean;
|
|
95
|
+
passwordReset: boolean;
|
|
96
|
+
emailVerification: boolean;
|
|
97
|
+
exchange: boolean;
|
|
98
|
+
mfa: boolean;
|
|
99
|
+
passwordless: boolean;
|
|
100
|
+
profile: boolean;
|
|
101
|
+
passwordChange: boolean;
|
|
102
|
+
accountDeletion: boolean;
|
|
103
|
+
sessionList: boolean;
|
|
104
|
+
administration: boolean;
|
|
105
|
+
/** Changing an address by confirming it, rather than on the spot. Needs somewhere to park it and a way to write. */
|
|
106
|
+
emailChange: boolean;
|
|
107
|
+
/** Off unless the deployment named the capability it takes — see `impersonationPermission`. */
|
|
108
|
+
impersonation: boolean;
|
|
109
|
+
};
|
|
110
|
+
requireAdmin: (actor: Actor | undefined, subject?: number) => AuthOutcome | undefined;
|
|
111
|
+
issue: (userId: number, context?: SessionContext, options?: {
|
|
112
|
+
actingAs?: number;
|
|
113
|
+
ttlSeconds?: number;
|
|
114
|
+
renewable?: boolean;
|
|
115
|
+
}) => Promise<SSRSession>;
|
|
116
|
+
grantBody: (account: AccountRecord, session: SSRSession, loaded?: AccountAccess) => Promise<object>;
|
|
117
|
+
exchangeAccount: (provider: string, token: string, carrier: CredentialCarrier) => Promise<ExchangeResult>;
|
|
118
|
+
};
|
|
119
|
+
export type AuthContext = ReturnType<typeof createAuthContext>;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { serverLog } from "../../../helpers/serverLog.js";
|
|
2
|
+
import { createMemoryRateLimit, fleetRateLimit } from "../throttle.js";
|
|
3
|
+
import { clientOf, now, refuse } from "./values.js";
|
|
4
|
+
import { checkPermission } from "../authorize.js";
|
|
5
|
+
import { generateToken, hashPassword, verifyPassword } from "../passwords.js";
|
|
6
|
+
import { normalizeRecoveryCode } from "../totp.js";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
//#region src/core/auth/api/context.ts
|
|
9
|
+
/** What every flow of the auth API shares: the adapters and the settings, read once, and the steps they take alike. */
|
|
10
|
+
var createAuthContext = ({ tokens, identity, adapters, config = {} }) => {
|
|
11
|
+
const { verifyPassword: verifyPassword$1 = verifyPassword, hashPassword: hashPassword$1 = hashPassword, generateToken: generateToken$1 = generateToken, verifyOnSignup = false, terms, adminPermission = "userManage", impersonationPermission, password: policy = {}, rateLimit = fleetRateLimit() ?? createMemoryRateLimit(), onMailError, onEvent, mfaIssuer, csrf } = config;
|
|
12
|
+
/** Never awaited, never able to throw: a logging outage must not become an authentication outage. */
|
|
13
|
+
const record = (event) => {
|
|
14
|
+
if (!onEvent) return;
|
|
15
|
+
try {
|
|
16
|
+
onEvent({
|
|
17
|
+
...event,
|
|
18
|
+
at: Math.floor(Date.now() / 1e3)
|
|
19
|
+
});
|
|
20
|
+
} catch (error) {
|
|
21
|
+
serverLog.error("auth", "security event handler threw", error);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A single-use link token that stops working.
|
|
26
|
+
*
|
|
27
|
+
* The deadline is carried **inside the token**, after a `~`, and that is what makes this cost nothing: no column,
|
|
28
|
+
* no adapter argument, and nothing a deployment with its own store has to remember to enforce — which is the
|
|
29
|
+
* failure mode of putting the check in the adapters, where forgetting it is silent and looks like everything
|
|
30
|
+
* working. It is not a secret and does not need to be: the token is compared against the stored copy, so editing
|
|
31
|
+
* the deadline just produces a string that matches no row.
|
|
32
|
+
*
|
|
33
|
+
* A token issued before this existed has no `~`, reads as no deadline, and keeps working — the links already in
|
|
34
|
+
* people's inboxes when a deployment upgrades.
|
|
35
|
+
*/
|
|
36
|
+
const mintLink = (random, lifetime) => `${random}~${now() + lifetime}`;
|
|
37
|
+
const linkExpired = (token) => {
|
|
38
|
+
const deadline = Number(token.slice(token.lastIndexOf("~") + 1));
|
|
39
|
+
return Number.isFinite(deadline) && token.includes("~") && deadline < now();
|
|
40
|
+
};
|
|
41
|
+
/** Recovery codes are high-entropy, so a fast digest is right — scrypt ten times per sign-in would not be. */
|
|
42
|
+
const digestRecoveryCode = (code) => createHash("sha256").update(normalizeRecoveryCode(code)).digest("hex");
|
|
43
|
+
/**
|
|
44
|
+
* Sends, and never fails the flow if it cannot.
|
|
45
|
+
*
|
|
46
|
+
* Every one of these goes out AFTER something has already been committed — an account created, an address
|
|
47
|
+
* changed, a reset token stored. Letting the mail provider decide whether that request succeeded turns an
|
|
48
|
+
* outage at Brevo into a 500 on a change that did happen, which is the worst of both: the caller is told it
|
|
49
|
+
* failed and retries against the new state. Reported instead, and the person can ask for another.
|
|
50
|
+
*/
|
|
51
|
+
const deliver = async (message) => {
|
|
52
|
+
try {
|
|
53
|
+
await adapters.sendMail?.(message);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
(onMailError ?? ((cause) => serverLog.error("auth", "could not send mail", cause)))(error, {
|
|
56
|
+
to: message.to,
|
|
57
|
+
template: message.template
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Checked before the password is, so a throttled attempt costs no hash — which is the difference between a rate
|
|
63
|
+
* limit and a slightly slower way to be brute-forced.
|
|
64
|
+
*/
|
|
65
|
+
/** Whatever was counted against this key is forgiven: the attempt it was guarding against succeeded. */
|
|
66
|
+
const throttleSucceeded = (attempt) => {
|
|
67
|
+
Promise.resolve(rateLimit({
|
|
68
|
+
...attempt,
|
|
69
|
+
succeeded: true
|
|
70
|
+
})).catch(() => void 0);
|
|
71
|
+
};
|
|
72
|
+
const throttled = async (attempt) => {
|
|
73
|
+
const verdict = await rateLimit(attempt);
|
|
74
|
+
if (typeof verdict === "boolean" ? verdict : verdict.allowed) return;
|
|
75
|
+
const retryAfter = typeof verdict === "boolean" ? void 0 : verdict.retryAfter;
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
status: 429,
|
|
79
|
+
body: {
|
|
80
|
+
error: "Too many attempts",
|
|
81
|
+
...retryAfter !== void 0 ? { retryAfter } : {}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/** The one place a new password is judged, so signing up, resetting and changing cannot disagree about it. */
|
|
86
|
+
const rejectPassword = async (value, context = {}) => {
|
|
87
|
+
const minLength = policy.minLength ?? 8;
|
|
88
|
+
if (value.length < minLength) return refuse(400, `The password must be at least ${minLength} characters`);
|
|
89
|
+
const reason = await policy.validate?.(value, context);
|
|
90
|
+
return reason ? refuse(400, reason) : void 0;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* What this deployment offers, decided by what it supplied and nothing else.
|
|
94
|
+
*
|
|
95
|
+
* There used to be a parallel set of `features` switches. They were redundant in every case — each flow reads
|
|
96
|
+
* adapters that no other flow reads, so leaving one out is already how you decline it — and two ways of saying
|
|
97
|
+
* the same thing invite the state where they disagree: an adapter wired up, the flag forgotten, and an endpoint
|
|
98
|
+
* that answers 404 for no reason anyone can see. Declining a flow is now one act: do not implement it.
|
|
99
|
+
*/
|
|
100
|
+
const capabilities = {
|
|
101
|
+
passwordLogin: !!adapters.findByUsername,
|
|
102
|
+
refresh: !!adapters.findByRefreshToken,
|
|
103
|
+
signup: !!adapters.createAccount,
|
|
104
|
+
passwordReset: !!adapters.findByEmail && !!adapters.setResetToken,
|
|
105
|
+
emailVerification: !!adapters.findByValidationToken && !!adapters.setVerified,
|
|
106
|
+
exchange: !!adapters.exchangeCredential,
|
|
107
|
+
mfa: !!adapters.loadMfa && !!adapters.saveMfa,
|
|
108
|
+
passwordless: !!adapters.saveOtp && !!adapters.findOtp && !!adapters.findByEmail && !!adapters.sendMail,
|
|
109
|
+
profile: !!adapters.updateAccount,
|
|
110
|
+
passwordChange: !!adapters.findById && !!adapters.setPassword,
|
|
111
|
+
accountDeletion: !!adapters.deleteAccount,
|
|
112
|
+
sessionList: !!adapters.listSessions,
|
|
113
|
+
administration: !!adapters.listAccounts && !!adapters.findById,
|
|
114
|
+
/** Changing an address by confirming it, rather than on the spot. Needs somewhere to park it and a way to write. */
|
|
115
|
+
emailChange: !!adapters.setPendingEmail && !!adapters.findByPendingEmail && !!adapters.clearPendingEmail && !!adapters.updateAccount && !!adapters.sendMail,
|
|
116
|
+
/** Off unless the deployment named the capability it takes — see `impersonationPermission`. */
|
|
117
|
+
impersonation: !!impersonationPermission && !!adapters.findById
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* An administrator acting on somebody else.
|
|
121
|
+
*
|
|
122
|
+
* `subject` refuses the case where that somebody is themselves. Banning or deleting your own account through the
|
|
123
|
+
* admin surface is how a deployment loses its last administrator, and it is never what was meant: closing your
|
|
124
|
+
* own account is the self-service flow, which asks for a password precisely because it is irreversible.
|
|
125
|
+
*/
|
|
126
|
+
const requireAdmin = (actor, subject) => {
|
|
127
|
+
const check = checkPermission(actor, adminPermission);
|
|
128
|
+
if (!check.ok) return refuse(check.status, check.error, check.status === 401 ? "missing" : void 0);
|
|
129
|
+
if (subject !== void 0 && subject === actor?.id) return refuse(400, "Use the self-service route to act on your own account");
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* A session for this account. `options` is only for the one that is not an ordinary sign-in: a borrowed session
|
|
133
|
+
* carries who borrowed it and cannot renew itself, so it dies at its deadline instead of quietly living for a
|
|
134
|
+
* month behind a refresh token.
|
|
135
|
+
*/
|
|
136
|
+
const issue = async (userId, context, options = {}) => {
|
|
137
|
+
const { actingAs, ttlSeconds, renewable = true } = options;
|
|
138
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
139
|
+
const session = {
|
|
140
|
+
token: tokens.generateUserToken(userId, {
|
|
141
|
+
actingAs,
|
|
142
|
+
ttlSeconds
|
|
143
|
+
}),
|
|
144
|
+
expiresAt: now + (ttlSeconds ?? tokens.lifetimes.access),
|
|
145
|
+
...renewable ? {
|
|
146
|
+
refreshToken: tokens.generateRefreshToken(userId),
|
|
147
|
+
refreshExpiresAt: now + tokens.lifetimes.refresh
|
|
148
|
+
} : {}
|
|
149
|
+
};
|
|
150
|
+
await adapters.saveSession(userId, session, context);
|
|
151
|
+
return session;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* The body a grant answers with. `details` is the same object the session endpoint returns, deliberately: it makes
|
|
155
|
+
* a grant an identity, so a client that has just signed in or renewed knows who it is without a second request.
|
|
156
|
+
*/
|
|
157
|
+
const grantBody = async (account, session, loaded) => {
|
|
158
|
+
const access = loaded ?? await adapters.loadAccess(account.id);
|
|
159
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
160
|
+
return {
|
|
161
|
+
success: true,
|
|
162
|
+
details: {
|
|
163
|
+
id: account.id,
|
|
164
|
+
username: account.username,
|
|
165
|
+
email: account.email,
|
|
166
|
+
verified: account.verified,
|
|
167
|
+
roles: access.roles,
|
|
168
|
+
permissions: access.permissions
|
|
169
|
+
},
|
|
170
|
+
access_token: session.token,
|
|
171
|
+
expire_in: Math.max(0, session.expiresAt - now),
|
|
172
|
+
expire_at: session.expiresAt,
|
|
173
|
+
refresh_token: session.refreshToken,
|
|
174
|
+
refresh_expire_in: Math.max(0, (session.refreshExpiresAt ?? 0) - now),
|
|
175
|
+
refresh_expire_at: session.refreshExpiresAt
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Turning a credential from an external identity provider into a session here, answered in accounts.
|
|
180
|
+
*
|
|
181
|
+
* `offered` separates "this deployment does not do exchanges" from "that credential was refused" — a 404 and a
|
|
182
|
+
* 401 respectively, and a caller that cannot tell them apart reports a misconfiguration as a bad password.
|
|
183
|
+
*/
|
|
184
|
+
const exchangeAccount = async (provider, token, carrier) => {
|
|
185
|
+
if (!capabilities.exchange) return {
|
|
186
|
+
ok: false,
|
|
187
|
+
offered: false,
|
|
188
|
+
status: 404,
|
|
189
|
+
error: "Not found"
|
|
190
|
+
};
|
|
191
|
+
if (!provider || !token) return {
|
|
192
|
+
ok: false,
|
|
193
|
+
offered: true,
|
|
194
|
+
status: 400,
|
|
195
|
+
error: "A provider and a token are required"
|
|
196
|
+
};
|
|
197
|
+
if (await throttled({
|
|
198
|
+
action: "exchange",
|
|
199
|
+
key: provider,
|
|
200
|
+
carrier
|
|
201
|
+
})) return {
|
|
202
|
+
ok: false,
|
|
203
|
+
offered: true,
|
|
204
|
+
status: 429,
|
|
205
|
+
error: "Too many attempts"
|
|
206
|
+
};
|
|
207
|
+
const result = await adapters.exchangeCredential?.(provider, token, carrier);
|
|
208
|
+
if (!result) return {
|
|
209
|
+
ok: false,
|
|
210
|
+
offered: true,
|
|
211
|
+
status: 401,
|
|
212
|
+
error: "Token Invalid",
|
|
213
|
+
reason: "revoked"
|
|
214
|
+
};
|
|
215
|
+
if ("error" in result) return {
|
|
216
|
+
ok: false,
|
|
217
|
+
offered: true,
|
|
218
|
+
status: result.status ?? 400,
|
|
219
|
+
error: result.error,
|
|
220
|
+
reason: "revoked"
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
ok: true,
|
|
224
|
+
account: result,
|
|
225
|
+
access: await adapters.loadAccess(result.id),
|
|
226
|
+
session: await issue(result.id, { client: clientOf(carrier) })
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
return {
|
|
230
|
+
tokens,
|
|
231
|
+
identity,
|
|
232
|
+
adapters,
|
|
233
|
+
verifyPassword: verifyPassword$1,
|
|
234
|
+
hashPassword: hashPassword$1,
|
|
235
|
+
generateToken: generateToken$1,
|
|
236
|
+
verifyOnSignup,
|
|
237
|
+
terms,
|
|
238
|
+
adminPermission,
|
|
239
|
+
impersonationPermission,
|
|
240
|
+
policy,
|
|
241
|
+
rateLimit,
|
|
242
|
+
onMailError,
|
|
243
|
+
onEvent,
|
|
244
|
+
mfaIssuer,
|
|
245
|
+
csrf,
|
|
246
|
+
record,
|
|
247
|
+
mintLink,
|
|
248
|
+
linkExpired,
|
|
249
|
+
digestRecoveryCode,
|
|
250
|
+
deliver,
|
|
251
|
+
throttleSucceeded,
|
|
252
|
+
throttled,
|
|
253
|
+
rejectPassword,
|
|
254
|
+
capabilities,
|
|
255
|
+
requireAdmin,
|
|
256
|
+
issue,
|
|
257
|
+
grantBody,
|
|
258
|
+
exchangeAccount
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
//#endregion
|
|
262
|
+
export { createAuthContext };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CredentialCarrier } from '../credentials';
|
|
2
|
+
import { Actor } from '../identity';
|
|
3
|
+
import { AuthContext } from './context';
|
|
4
|
+
import { AuthOutcome } from './types';
|
|
5
|
+
/** The ways in besides a password: a code or a link by email (`passwordless`), and the second factor (`mfa`). */
|
|
6
|
+
export declare const factorsFlows: ({ tokens, adapters, verifyPassword, mfaIssuer, record, digestRecoveryCode, deliver, throttleSucceeded, throttled, capabilities, issue, grantBody }: AuthContext) => {
|
|
7
|
+
/**
|
|
8
|
+
* Signing in with a code sent to an email address, and no password at all.
|
|
9
|
+
*
|
|
10
|
+
* Two decisions worth stating. **The request answers the same whether the address exists or not** — anything
|
|
11
|
+
* else turns this endpoint into a way to ask which addresses have accounts. And **it never creates an
|
|
12
|
+
* account**: a sign-in flow that silently registers whoever asks is a different feature, and one a deployment
|
|
13
|
+
* should choose deliberately rather than inherit.
|
|
14
|
+
*/
|
|
15
|
+
passwordless: {
|
|
16
|
+
request: (email: string, carrier?: CredentialCarrier) => Promise<AuthOutcome>;
|
|
17
|
+
complete: (email: string, code: string, carrier?: CredentialCarrier) => Promise<AuthOutcome>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Everything about this account's second factor. `begin` hands back a secret and the URI an app scans; nothing
|
|
21
|
+
* is in force until `confirm` proves a code from it.
|
|
22
|
+
*/
|
|
23
|
+
mfa: {
|
|
24
|
+
status: (actor: Actor | undefined) => Promise<AuthOutcome>;
|
|
25
|
+
begin: (actor: Actor | undefined) => Promise<AuthOutcome>;
|
|
26
|
+
/** Proves the app was actually set up, and only then does the factor start being required. */
|
|
27
|
+
confirm: (actor: Actor | undefined, code: string) => Promise<AuthOutcome>;
|
|
28
|
+
/** Removing a factor is a security downgrade, so it asks for the password the way deleting an account does. */
|
|
29
|
+
disable: (actor: Actor | undefined, password?: string) => Promise<AuthOutcome>;
|
|
30
|
+
};
|
|
31
|
+
};
|