@plitzi/sdk-auth 0.38.24 → 0.39.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/CHANGELOG.md +152 -1
- package/dist/AuthContextProvider.mjs +83 -76
- package/dist/AuthManager.d.ts +3 -1
- package/dist/AuthManager.mjs +3 -0
- package/dist/AuthProvider.d.ts +8 -1
- package/dist/AuthProvider.mjs +4 -1
- package/dist/helpers/resolveAuthSettings.mjs +1 -0
- package/dist/helpers/sessionViews.d.ts +12 -0
- package/dist/helpers/sessionViews.mjs +31 -0
- package/dist/hooks/useAuth/useAuth.mjs +44 -37
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +8 -7
- package/dist/providers/BasicAuthProvider.d.ts +9 -2
- package/dist/providers/BasicAuthProvider.mjs +25 -11
- package/dist/providers/ServerAuthProvider.d.ts +10 -2
- package/dist/providers/ServerAuthProvider.mjs +13 -3
- package/dist/types.d.ts +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,156 @@
|
|
|
1
1
|
# @plitzi/sdk-auth
|
|
2
2
|
|
|
3
|
+
## 0.39.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 587c35b: A team of agents on one project (`plitzi run`, `plitzi task`), the page tools those agents measure with, tests kept in
|
|
8
|
+
the space, and what authoring and the elements learnt from the runs. Each command and option is in the CLI's README;
|
|
9
|
+
how the runs work, in `docs/en/agent-runs.md`.
|
|
10
|
+
|
|
11
|
+
## To do when you upgrade
|
|
12
|
+
- **Node 24.** `engines` is `^24.22.1 || >=26.12.1`; Node 22 is no longer supported (`plitzi doctor` says it,
|
|
13
|
+
`doctor --fix` raises an older project's `engines`).
|
|
14
|
+
- **`createServer({ outbound: { privateOrigins } })` replaces `allowPrivatePluginHosts`:** a space's requests reach no
|
|
15
|
+
private address but the origins named (`privateOrigins: ['http://localhost:9000']`).
|
|
16
|
+
- **Job queues from 0.38.20 or before are recreated, not upgraded:** `createMongoJobQueue` / `createMysqlJobQueue` empty
|
|
17
|
+
or drop the old `action_jobs` / `action_kv` and make them again; `mysqlJobSchemaUpgrades` is gone.
|
|
18
|
+
- **`PLITZI_KV_FILE` is `PLITZI_STATE_DIR`**, a folder holding the server's `kv` and job queue.
|
|
19
|
+
- **A social provider's `fetchProfile` takes `{ accessToken, idToken, nonce }`**, and `createSocialAuth(...).start` is
|
|
20
|
+
async.
|
|
21
|
+
- **A `DraftStore` of a deployment's own keeps `inspected`** beside `reusable`, or a test session renders without the
|
|
22
|
+
state bridge.
|
|
23
|
+
- **`navigation.navigate(url, { external, replace })`** takes an object where it took `navigate(url, true)`.
|
|
24
|
+
- **`window.__plitzi.setSource` / `setAttribute` may answer `{ refused }`**: read it before treating the answer as written.
|
|
25
|
+
- **Renamed:** `stepText` → `e2eStepText` (a run's `said` is the step in words); `OverQuotaNotice` → `QuotaNotice` and
|
|
26
|
+
its classes `plitzi-quota-notice…`; `sightOf` / `sightText` come from `@plitzi/sdk-shared/devTools/sight`.
|
|
27
|
+
- **`SchemaVariables` and `StyleVariables` draw no add button of their own:** the holder passes `adding`, `onAddingEnd`
|
|
28
|
+
and optionally `empty`.
|
|
29
|
+
- **A page handed to `runE2eTest`** has `selectOption`, `position` in `click`/`hover` and `evaluate(fn, arg)`, as a
|
|
30
|
+
Playwright locator: a hand-written page adds them.
|
|
31
|
+
- **Journey steps play as the page commands do:** `scroll` with `dx`/`dy` scrolls the element's content, `waitFor`
|
|
32
|
+
waits 10 s, `type` replaces a field's value.
|
|
33
|
+
- **Authoring refuses more:** two flows of one element naming a step alike (`step-duplicate`), `visible` written as an
|
|
34
|
+
expression (`visible-expression`), a step condition naming a source by id alone (`condition-short-source`).
|
|
35
|
+
`navbar` / `navbarItem` are no longer read by `specFromSpace`.
|
|
36
|
+
- **`/robots.txt` ends naming its sitemap** unless the space's own text does.
|
|
37
|
+
- **The CLI's part of a project is `.plitzi/`** (it was split with `plitzi/`): `plitzi doctor --fix` moves it, and a
|
|
38
|
+
tsconfig names `.plitzi/**/*`.
|
|
39
|
+
- **`plitzi upgrade`** brings the new scripts (`start:preview`, the visual suite's server on 8400, `test`), the ignores
|
|
40
|
+
for `.plitzi/plitzi-reports/` and the skills. `test` runs the project's own tests, so red tests now fail
|
|
41
|
+
`plitzi verify` and a run's checks.
|
|
42
|
+
- **Reports to Plitzi live in `.plitzi/plitzi-reports/`**, committed: a run's in `runs/<run>/`, an agent's in
|
|
43
|
+
`agents/<date>/`. The old files are read no more.
|
|
44
|
+
- **The CLI's surface is smaller — one command for each thing.** Old names and flags are refused naming the new one;
|
|
45
|
+
`plitzi upgrade skills --write` updates the agents' skills. The main moves: `run plan` / `run rehearse` →
|
|
46
|
+
`run open --dry-run [--rehearse]`; `run extend` → `run open <stage>`; `run purge` → `run abort`; `task take` →
|
|
47
|
+
`task next <task>`; `task ask` / `block` / `note` → `task tell --ask | --blocked | --handoff`; `task wait` / `release`
|
|
48
|
+
→ `task claim --wait | --release`; `task request` → `task propose --file`; `task check --before | --mutate` →
|
|
49
|
+
`task prove`; `run feedback` → `run report --plitzi`; `functions pull|push` → `space pull|push functions`;
|
|
50
|
+
`runtime push` → `space push runtime`; `page shot --live` / `--clip` → `--fresh` / `--within`; `PLITZI_TASK_TOKEN` →
|
|
51
|
+
`PLITZI_TOKEN`.
|
|
52
|
+
- **Research and reviews are cards on one board:** `task spike` and the separate UI review are gone; a card's `review`
|
|
53
|
+
names its roles in order. Runs opened before keep working.
|
|
54
|
+
- **Page commands:** `page check --expect` fails only on what it expects; every page command reads at 900 px tall
|
|
55
|
+
(`--height`); a page that sends a guest away is read signed in as the project's account (`--as`, `--guest`).
|
|
56
|
+
- **`create --from`** names page files by the page's name; a space's functions are pushed without their tests.
|
|
57
|
+
|
|
58
|
+
## A space's tests (`@plitzi/sdk-authoring`, `@plitzi/sdk-shared`, `@plitzi/plitzi-builder`, `@plitzi/sdk-mcp`)
|
|
59
|
+
- **Tests are part of the space's document** (`Schema.tests`): unit tests (element checks) and journeys (what a visitor
|
|
60
|
+
does), authored in code, edited in the builder's Tests area, played on the canvas or the server. See
|
|
61
|
+
`docs/en/space-tests.md`.
|
|
62
|
+
- **Journeys play signed in as test accounts** (`tests.accounts`), carry tags, can be held and stopped
|
|
63
|
+
(`runE2eTest`'s `beforeStep`), and hold element checks (`e2e.expectCheck`).
|
|
64
|
+
- **`plitzi test [id…]`** runs a project's tests; **`plitzi_test`** lets an agent run them over the MCP. What a plan
|
|
65
|
+
allows (`journeysPerSpace`, `serverRunsPerMonth`) is in its entitlements; a `canTest` grant writes tests alone.
|
|
66
|
+
|
|
67
|
+
## Several agents on one project (`@plitzi/cli`)
|
|
68
|
+
- **A run is a kanban:** a lead plans, reviews and closes; developers, testers, designers and scouts take cards with
|
|
69
|
+
`task next`, each in its own copy of the project; every card is reviewed by the roles it names, step by step.
|
|
70
|
+
Nothing reaches the project until a person applies the run (`run finish --apply`).
|
|
71
|
+
- **Files are owned by imports:** one agent per file, shared files taken by turns or changed by agreement
|
|
72
|
+
(`task propose`), merged line by line, checked on the whole result.
|
|
73
|
+
- **The run keeps itself going:** a keeper starts the agents work is waiting for, and holds
|
|
74
|
+
starts after the harness's limit or repeated quick exits until the lead allows them (`run hold`, `run allow`).
|
|
75
|
+
- **`run monitor`:** the run live in a terminal — board, flow, agents, spend, activity — with an emergency panel (`!`)
|
|
76
|
+
to pause, resume, hold or allow agents.
|
|
77
|
+
- **A change mid-run says what it reaches:** `run open <stage> --dry-run` and `run amend --dry-run` name the approved
|
|
78
|
+
tasks, tasks at work and tests each change touches, read off the import graph.
|
|
79
|
+
- **Reviews see what goes in:** a review taken says whether the task merges with the run's newer work and, if not, the
|
|
80
|
+
failing lines; `task show <file> --merged` and `task look --merged` read and serve the merge;
|
|
81
|
+
`task look --alone <element> --with '{…}'` draws a component or plugin no page places yet. A step's time stops while
|
|
82
|
+
its reviewer proves or looks.
|
|
83
|
+
- **Proofs:** `task prove --before` (what each acceptance line proves against the run before the task) and
|
|
84
|
+
`--mutate` (whether a task's tests catch a broken change, with a control run).
|
|
85
|
+
- **The finish:** `run finish` checks the whole result and stops at the first failing line; `--every-line` reports
|
|
86
|
+
them all. The run then leaves its reports in `.plitzi/plitzi-reports/runs/<run>/`.
|
|
87
|
+
- **A report to Plitzi holds nothing of the person or the project:** a run's `feedback.md` writes over names, emails,
|
|
88
|
+
addresses, IPs, the project's files, tasks and elements, leaves out what was said of the project alone, and lists
|
|
89
|
+
quoted passages for the person to read before sending. `plitzi feedback` carries no project name, asks the developer
|
|
90
|
+
before anything of the project goes in, and `plitzi feedback --check <file>` names what a filled report still holds.
|
|
91
|
+
|
|
92
|
+
## Page tools (`@plitzi/cli`, `@plitzi/sdk-authoring`)
|
|
93
|
+
- **`page measure`** reads what an element draws (`--only drawn`, `box-*`, `attr:<name>`, `accessible-name`,
|
|
94
|
+
`scroll-*`, custom properties) and holds bounds and positions (`--expect "width<=44px"`, `"a.bottom + 8 <= b.top"`).
|
|
95
|
+
- **`page play`** plays steps — `drag … hold`, `scroll page 1500`, `click <el> 30%,60%` — reads what is drawn, not
|
|
96
|
+
what is in the DOM, and `--motion` plays animations moving. A press is made once and waits for the page to take it.
|
|
97
|
+
- **`page check`** says what a visitor cannot reach, text cut or spilling, canvases left blank, the server's error page
|
|
98
|
+
when the space does not author, and holds a text whole (`=`) or in part (`~`).
|
|
99
|
+
- **`page shot`** waits for canvases, pictures hovers (`--hover`, `--frames`) and parts (`--within`), and says what it
|
|
100
|
+
could not picture.
|
|
101
|
+
- **Every page command reads a page as one visitor from the same flags** (`--as`, `--guest`, `--width`, `--height`,
|
|
102
|
+
`--fresh`), with a browser driver of the CLI's own.
|
|
103
|
+
|
|
104
|
+
## Authoring (`@plitzi/sdk-authoring`)
|
|
105
|
+
- **New checks:** a server provider the page server cannot read (`server-query-unresolved`) or that reads browser state
|
|
106
|
+
(`server-when-unknown`), an action without `runtime: 'server'` (`server-source-in-browser`), class overrides,
|
|
107
|
+
messages arriving while a flow runs, unused plugins.
|
|
108
|
+
- **New authoring:** `focus('field')`, a factory for every trigger, the scroll family's sides, `pagesIn(...)` to
|
|
109
|
+
register pages by folder, channel topics with a choice, a plugin's imported stylesheets read for its tokens.
|
|
110
|
+
- **An element drawn alone:** a server started with `PLITZI_PREVIEW_FILE` gets a page for one element at
|
|
111
|
+
`/plitzi-preview` (`withPreview`, `SpacePreviewError`) — what `task look --alone` uses.
|
|
112
|
+
|
|
113
|
+
## Elements and the SDK (`@plitzi/sdk-elements`, `@plitzi/plitzi-sdk`, `@plitzi/sdk-shared`)
|
|
114
|
+
- **Navigation:** `navigate` can replace the address, and a navigation inside the site leaves the scroll as a page
|
|
115
|
+
load would.
|
|
116
|
+
- **Providers:** a `when` holds the same in the browser and on the page server; a server provider can read another
|
|
117
|
+
site's address while the page is built.
|
|
118
|
+
- **Plans and roles in the contract:** entitlements (`TSpaceEntitlements`), the space role (`TSpaceAccess`), the quota
|
|
119
|
+
warning at 80% (`render.quotaNear`) and the "Made with Plitzi" badge (`PlitziBadge`).
|
|
120
|
+
- **Fixes:** a binding's `sourceTo` is the previous value; an element with no tag and no `visible` draws nothing;
|
|
121
|
+
placeholder words never reach a page; notifications stay open for a visitor who asked for less motion.
|
|
122
|
+
|
|
123
|
+
## Server (`@plitzi/sdk-server`, `@plitzi/sdk-auth`, `@plitzi/sdk-mcp`)
|
|
124
|
+
- **`/sitemap.xml`** for every space, and `/robots.txt` naming it.
|
|
125
|
+
- **Accounts:** terms accepted at sign-up (MySQL schema version 7), single sign-on with any OpenID Connect issuer
|
|
126
|
+
(`createOidcProvider`), providers resolved at run time, a password that may not sign in, `/auth/continue` with a step
|
|
127
|
+
of the deployment's own, a signed-out visitor never signed back in by a stale answer.
|
|
128
|
+
- **Policy adapters:** metering can hold a page back (503), decide the badge and `noindex`; the MCP can cap tool calls
|
|
129
|
+
and names the space's plan; realtime admits spaces per deployment.
|
|
130
|
+
- **Dev server:** a removed plugin folder is unregistered (`PluginRegistry.unregister`), and a space that does not
|
|
131
|
+
author is said whole, with no stack.
|
|
132
|
+
|
|
133
|
+
## The builder (`@plitzi/plitzi-builder`)
|
|
134
|
+
- **A Tests area** with journeys played beside the page at the journey's device, and element checks.
|
|
135
|
+
- **One way to build a panel**, a header grouped by what its controls do, and the layout's mask dimming only what the
|
|
136
|
+
layout draws.
|
|
137
|
+
- **Plans and roles shown:** what the role allows (`useSpaceAccess`), what the plan leaves out shown locked, the plan
|
|
138
|
+
and its spend in the header; pages left out of the sitemap marked.
|
|
139
|
+
|
|
140
|
+
## Dev tools (`@plitzi/sdk-dev-tools`)
|
|
141
|
+
- **`element(id).visible` is what a visitor sees** (`sightOf`), with why not; `element(id).resolved` says what each
|
|
142
|
+
binding gave; a refused server action is a `refused` step.
|
|
143
|
+
- **Report what you see** in the Run tab of a run's preview, and the panel docks at the bottom under 900 px.
|
|
144
|
+
|
|
145
|
+
## The workspace
|
|
146
|
+
- **No file past 600 lines of code** (`max-lines`), and ESLint's `quotes` rule is gone — Prettier writes them.
|
|
147
|
+
|
|
148
|
+
### Patch Changes
|
|
149
|
+
|
|
150
|
+
- Updated dependencies [587c35b]
|
|
151
|
+
- @plitzi/sdk-navigation@0.39.0
|
|
152
|
+
- @plitzi/sdk-shared@0.39.0
|
|
153
|
+
|
|
3
154
|
## 0.38.24
|
|
4
155
|
|
|
5
156
|
### Patch Changes
|
|
@@ -3441,7 +3592,7 @@ author`, `plitzi_validate`/`plitzi_apply`, `plitzi explain` and the builder's pr
|
|
|
3441
3592
|
- **Devices are listed by device, not by session.** `GET /devices/sessions` groups sessions by what they were created
|
|
3442
3593
|
from and answers this device apart; a browser that signed in forty times is one row saying "40 sessions". The list
|
|
3443
3594
|
had shipped and drawn every session — 1,218 for one account a test suite signs in as — inside a box that scrolled.
|
|
3444
|
-
- **Every device is named for what it is**: the application as it registered over OAuth (`Plitzi CLI on
|
|
3595
|
+
- **Every device is named for what it is**: the application as it registered over OAuth (`Plitzi CLI on dev-laptop`,
|
|
3445
3596
|
`Plitzi Desktop on studio`), a browser and its system, an automated client (Playwright, headless Chrome) — never a
|
|
3446
3597
|
raw user agent. Sessions record their address and **when they were last used** (at most every five minutes, on the
|
|
3447
3598
|
lookup a request already makes). A sign-in deletes the account's dead sessions.
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { AuthContext as e } from "./AuthContext.mjs";
|
|
2
2
|
import { publishedSession as t } from "./helpers/publishedSession.mjs";
|
|
3
3
|
import { resolveAuthSettings as n } from "./helpers/resolveAuthSettings.mjs";
|
|
4
|
-
import r from "./
|
|
5
|
-
import i from "./hooks/
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
4
|
+
import { testAccountAuth as r } from "./helpers/sessionViews.mjs";
|
|
5
|
+
import i from "./hooks/useAuth/index.mjs";
|
|
6
|
+
import a from "./hooks/useSessionQueryReset/index.mjs";
|
|
7
|
+
import { QueryBuilderEvaluator as o } from "@plitzi/plitzi-ui/QueryBuilder/evaluator";
|
|
8
|
+
import { use as s, useMemo as c, useRef as l } from "react";
|
|
9
|
+
import { useNavigation as u } from "@plitzi/sdk-navigation";
|
|
10
|
+
import { processTwig as d } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
11
|
+
import { NetworkContext as f } from "@plitzi/sdk-shared/network";
|
|
12
|
+
import { useCommonStore as p, useRenderSettings as m } from "@plitzi/sdk-shared/store";
|
|
13
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
13
14
|
//#region src/AuthContextProvider.tsx
|
|
14
|
-
var
|
|
15
|
+
var g = [
|
|
15
16
|
"loginUrl",
|
|
16
17
|
"userUrl",
|
|
17
18
|
"refreshUrl",
|
|
18
19
|
"logoutUrl",
|
|
20
|
+
"revokeUrl",
|
|
19
21
|
"detailsPath",
|
|
20
22
|
"tokenPath",
|
|
21
23
|
"refreshTokenPath",
|
|
@@ -24,109 +26,114 @@ var h = [
|
|
|
24
26
|
"sessionHintCookie",
|
|
25
27
|
"sessionExchangeUrl",
|
|
26
28
|
"mfaUrl"
|
|
27
|
-
],
|
|
29
|
+
], _ = (e, t) => {
|
|
28
30
|
if (e === t) return !0;
|
|
29
31
|
if (!e || !t) return !1;
|
|
30
32
|
let n = e, r = t;
|
|
31
33
|
return [.../* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)])].every((e) => JSON.stringify(n[e]) === JSON.stringify(r[e]));
|
|
32
|
-
},
|
|
33
|
-
let { previewMode:
|
|
34
|
-
queryParams:
|
|
35
|
-
hostname:
|
|
36
|
-
environment:
|
|
34
|
+
}, v = ({ children: v, server: y }) => {
|
|
35
|
+
let { previewMode: b, isHydrating: x, environment: S } = m(), { webKey: C } = s(f), [[w, T]] = p(["schema.settings", "schema.variables"]), { queryParams: E, hostname: D } = u({ server: y }), O = c(() => ({
|
|
36
|
+
queryParams: E,
|
|
37
|
+
hostname: D,
|
|
38
|
+
environment: S
|
|
37
39
|
}), [
|
|
38
|
-
T,
|
|
39
40
|
E,
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
D,
|
|
42
|
+
S
|
|
43
|
+
]), k = c(() => Array.isArray(T) ? T.reduce((e, t) => {
|
|
42
44
|
let { name: n, value: r, subValues: i } = t;
|
|
43
45
|
if (!Array.isArray(i) || i.length === 0) return {
|
|
44
46
|
...e,
|
|
45
47
|
[n]: r
|
|
46
48
|
};
|
|
47
|
-
let
|
|
48
|
-
return
|
|
49
|
+
let a = i.find((e) => o(e.when, O));
|
|
50
|
+
return a ? {
|
|
49
51
|
...e,
|
|
50
|
-
[n]:
|
|
52
|
+
[n]: a.value
|
|
51
53
|
} : {
|
|
52
54
|
...e,
|
|
53
55
|
[n]: r
|
|
54
56
|
};
|
|
55
|
-
}, {}) : {}, [
|
|
56
|
-
let e = Object.fromEntries(
|
|
57
|
+
}, {}) : {}, [T, O]), A = c(() => {
|
|
58
|
+
let e = Object.fromEntries(g.map((e) => [e, w[e]]));
|
|
57
59
|
try {
|
|
58
|
-
return JSON.parse(
|
|
60
|
+
return JSON.parse(d(JSON.stringify(e), k));
|
|
59
61
|
} catch {
|
|
60
62
|
return e;
|
|
61
63
|
}
|
|
62
|
-
}, [
|
|
63
|
-
let e = n(
|
|
64
|
-
...
|
|
65
|
-
tokenStorage:
|
|
66
|
-
sessionGate:
|
|
67
|
-
sessionRevalidateSeconds:
|
|
68
|
-
},
|
|
64
|
+
}, [w, k]), { provider: j, settings: M } = c(() => {
|
|
65
|
+
let e = n(w.userProvider, {
|
|
66
|
+
...A,
|
|
67
|
+
tokenStorage: w.tokenStorage ?? "localStorage",
|
|
68
|
+
sessionGate: w.sessionGate,
|
|
69
|
+
sessionRevalidateSeconds: w.sessionRevalidateSeconds
|
|
70
|
+
}, y.auth);
|
|
69
71
|
return {
|
|
70
72
|
provider: e.provider,
|
|
71
73
|
settings: {
|
|
72
74
|
...e.settings,
|
|
73
|
-
spaceKey:
|
|
75
|
+
spaceKey: C
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
78
|
}, [
|
|
77
|
-
|
|
79
|
+
A,
|
|
80
|
+
w,
|
|
78
81
|
C,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
state: F,
|
|
82
|
+
y.auth
|
|
83
|
+
]), N = l(M), P = c(() => (_(N.current, M) || (N.current = M), N.current), [M]), { manager: F, loading: I, authenticated: L, state: R, bootstrapUser: z, bootstrapToken: B, peekedUser: V, peekedToken: H } = i({
|
|
84
|
+
server: y,
|
|
85
|
+
isHydrating: x,
|
|
86
|
+
provider: j,
|
|
87
|
+
settings: P
|
|
88
|
+
}), U = F.getProvider(), { user: W, accessToken: G } = t({
|
|
89
|
+
state: R,
|
|
88
90
|
provider: {
|
|
89
|
-
user:
|
|
90
|
-
accessToken:
|
|
91
|
+
user: U?.user,
|
|
92
|
+
accessToken: U?.token?.accessToken
|
|
91
93
|
},
|
|
92
94
|
bootstrap: {
|
|
93
|
-
user:
|
|
94
|
-
accessToken:
|
|
95
|
+
user: z,
|
|
96
|
+
accessToken: B
|
|
95
97
|
},
|
|
96
98
|
peeked: {
|
|
97
|
-
user:
|
|
98
|
-
accessToken: z
|
|
99
|
-
}
|
|
100
|
-
}), U = c(void 0), W = s(() => {
|
|
101
|
-
let e = V ? {
|
|
102
|
-
details: V,
|
|
99
|
+
user: V,
|
|
103
100
|
accessToken: H
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
101
|
+
}
|
|
102
|
+
}), K = l(void 0), q = c(() => {
|
|
103
|
+
let e = W ? {
|
|
104
|
+
details: W,
|
|
105
|
+
accessToken: G
|
|
106
|
+
} : void 0, t = K.current;
|
|
107
|
+
return t?.accessToken === e?.accessToken && _(t?.details, e?.details) || (K.current = e), K.current;
|
|
108
|
+
}, [W, G]);
|
|
109
|
+
a(L ? String(q?.details?.id ?? "") : "");
|
|
110
|
+
let J = c(() => ({
|
|
111
|
+
login: F.login.bind(F),
|
|
112
|
+
refresh: F.refresh.bind(F),
|
|
113
|
+
revalidate: F.revalidate.bind(F),
|
|
114
|
+
invalidate: F.invalidate.bind(F),
|
|
115
|
+
can: F.can.bind(F),
|
|
116
|
+
logout: F.logout.bind(F),
|
|
117
|
+
logoutEverywhere: F.logoutEverywhere.bind(F),
|
|
118
|
+
provider: F.getProviderType(),
|
|
119
|
+
state: R,
|
|
120
|
+
authenticated: L || !b,
|
|
121
|
+
user: q
|
|
119
122
|
}), [
|
|
120
|
-
M,
|
|
121
123
|
F,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
R,
|
|
125
|
+
L,
|
|
126
|
+
b,
|
|
127
|
+
q
|
|
128
|
+
]), [Y, X] = p("runtime.testAccount"), Z = c(() => Y ? r(J, Y, () => X(void 0)) : J, [
|
|
129
|
+
Y,
|
|
130
|
+
X,
|
|
131
|
+
J
|
|
125
132
|
]);
|
|
126
|
-
return /* @__PURE__ */
|
|
127
|
-
value:
|
|
128
|
-
children: !
|
|
133
|
+
return /* @__PURE__ */ h(e, {
|
|
134
|
+
value: Z,
|
|
135
|
+
children: !I && v
|
|
129
136
|
});
|
|
130
137
|
};
|
|
131
138
|
//#endregion
|
|
132
|
-
export {
|
|
139
|
+
export { v as default };
|
package/dist/AuthManager.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as AuthProvider, AuthBootstrap, AuthEventListener } from './AuthProvider';
|
|
2
2
|
import { AuthProviderSettings } from './types';
|
|
3
|
-
import { AuthFailureReason, AuthState, LoginResult, TokenResult } from '@plitzi/sdk-shared';
|
|
3
|
+
import { SessionScope, AuthFailureReason, AuthState, LoginResult, TokenResult } from '@plitzi/sdk-shared';
|
|
4
4
|
export type AuthProviderFactory<U = Record<string, unknown>> = (settings: AuthProviderSettings) => AuthProvider<U>;
|
|
5
5
|
/**
|
|
6
6
|
* Adds an auth provider a space can then select by name in its settings. Spaces run against whichever backend their
|
|
@@ -61,6 +61,8 @@ export declare class AuthManager<U = Record<string, unknown>> {
|
|
|
61
61
|
revalidate(force?: boolean): Promise<boolean>;
|
|
62
62
|
invalidate(reason?: AuthFailureReason): void;
|
|
63
63
|
logout(): Promise<void>;
|
|
64
|
+
/** No provider, nobody signed in: nothing to end anywhere. */
|
|
65
|
+
logoutEverywhere(scope: SessionScope): Promise<void>;
|
|
64
66
|
dispose(): void;
|
|
65
67
|
on(listener: AuthEventListener): (() => void) | undefined;
|
|
66
68
|
}
|
package/dist/AuthManager.mjs
CHANGED
|
@@ -60,6 +60,9 @@ var n = /* @__PURE__ */ new Map([["basic", (t) => new e(t)], ["server", (e) => n
|
|
|
60
60
|
logout() {
|
|
61
61
|
return this.provider?.logout() ?? Promise.resolve();
|
|
62
62
|
}
|
|
63
|
+
logoutEverywhere(e) {
|
|
64
|
+
return this.provider?.logoutEverywhere(e) ?? Promise.resolve();
|
|
65
|
+
}
|
|
63
66
|
dispose() {
|
|
64
67
|
this.provider?.dispose();
|
|
65
68
|
}
|
package/dist/AuthProvider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthFailureReason, AuthResult, AuthState, LoginResult, MfaChallenge, Schema, TokenResult } from '@plitzi/sdk-shared';
|
|
1
|
+
import { AuthFailureReason, AuthResult, AuthState, LoginResult, MfaChallenge, Schema, SessionScope, TokenResult } from '@plitzi/sdk-shared';
|
|
2
2
|
/** Why a state changed. Not control flow — it is what makes an auth trace readable, and every transition below
|
|
3
3
|
* names one, because "it went to guest" is not a diagnosis and "the hint cookie was gone" is. */
|
|
4
4
|
export type AuthStateReason = 'bootstrap' | 'restored' | 'granted' | 'renewed' | 'identity' | 'redirect' | 'exchanged' | 'no-provider' | 'skip-auth' | 'hint-missing' | 'no-evidence' | 'signed-out' | 'another-tab' | 'settled' | 'authenticating';
|
|
@@ -79,6 +79,11 @@ declare abstract class AuthProvider<U = Record<string, unknown>> {
|
|
|
79
79
|
protected abstract requestRenewal(refreshToken?: string): Promise<AuthResult<U>>;
|
|
80
80
|
protected abstract requestIdentity(): Promise<AuthResult<U>>;
|
|
81
81
|
protected abstract requestLogout(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Ends the person's sessions on every device, as `scope` says (`SessionScope`). Throws when the backend refused or
|
|
84
|
+
* was not reached: a sign-out everywhere that did not happen must not read as one that did.
|
|
85
|
+
*/
|
|
86
|
+
protected abstract requestLogoutEverywhere(scope: SessionScope): Promise<void>;
|
|
82
87
|
/**
|
|
83
88
|
* Hands the credential this browser just obtained to the rendering server, so it can establish a session of its
|
|
84
89
|
* own — see `handOffToServer`. Returning undefined, the default, means this provider's grants already come from
|
|
@@ -167,6 +172,8 @@ declare abstract class AuthProvider<U = Record<string, unknown>> {
|
|
|
167
172
|
/** What a refusal does to the session — and whether it was renewed because of it, so the request may be asked again. */
|
|
168
173
|
private recover;
|
|
169
174
|
logout(): Promise<void>;
|
|
175
|
+
/** Signs the person out on every device — this site's sessions, or every one of the account — and here too. */
|
|
176
|
+
logoutEverywhere(scope: SessionScope): Promise<void>;
|
|
170
177
|
on(listeners: AuthEventListener | AuthEventListener[]): () => void;
|
|
171
178
|
protected emit(event: AuthEvent): void;
|
|
172
179
|
protected setState(state: AuthState, reason?: AuthStateReason): void;
|
package/dist/AuthProvider.mjs
CHANGED
|
@@ -151,11 +151,14 @@ var s = 60, c = 300, l = 2147483647, u = class {
|
|
|
151
151
|
this.recover(e);
|
|
152
152
|
}
|
|
153
153
|
async recover(e) {
|
|
154
|
-
return e === "network" ? (this.offline = !0, !1) : this.renewable(e) ? this.renew() : (this.endSession(e), !1);
|
|
154
|
+
return e === "network" ? (this.offline = !0, !1) : this.hasEvidence() ? this.renewable(e) ? this.renew() : (this.endSession(e), !1) : !1;
|
|
155
155
|
}
|
|
156
156
|
async logout() {
|
|
157
157
|
await this.requestLogout(), this.endSession(), this.emit({ type: "logout" });
|
|
158
158
|
}
|
|
159
|
+
async logoutEverywhere(e) {
|
|
160
|
+
await this.requestLogoutEverywhere(e), this.endSession(), this.emit({ type: "logout" });
|
|
161
|
+
}
|
|
159
162
|
on(e) {
|
|
160
163
|
let t = Array.isArray(e) ? e : [e];
|
|
161
164
|
return t.forEach((e) => this.listeners.add(e)), () => t.forEach((e) => this.listeners.delete(e));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthContextValue, SignedInTestAccount } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* The page's auth as a visitor with no session sees it — as the server plays a journey: signed out, no one's details or
|
|
4
|
+
* token, no permission. What it can do is kept: a journey that signs in, signs in.
|
|
5
|
+
*/
|
|
6
|
+
export declare const guestAuth: (auth: AuthContextValue) => AuthContextValue;
|
|
7
|
+
/**
|
|
8
|
+
* The page's auth as a journey's test account (`tests.accounts`) — signed in with its details, roles and what they give,
|
|
9
|
+
* and a token no server takes (`test:<id>`): a page that reads its session by the token sees one, and the API answers
|
|
10
|
+
* it as a guest. Signing out drops it (`signOut`), as a person's would.
|
|
11
|
+
*/
|
|
12
|
+
export declare const testAccountAuth: (auth: AuthContextValue, account: SignedInTestAccount, signOut: () => void) => AuthContextValue;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { omit as e } from "@plitzi/plitzi-ui/helpers";
|
|
2
|
+
//#region src/helpers/sessionViews.ts
|
|
3
|
+
var t = (t) => ({
|
|
4
|
+
...e(t, ["user"]),
|
|
5
|
+
authenticated: !1,
|
|
6
|
+
state: "guest",
|
|
7
|
+
can: () => !1
|
|
8
|
+
}), n = (e, t, n) => {
|
|
9
|
+
let { permissions: r } = t;
|
|
10
|
+
return {
|
|
11
|
+
...e,
|
|
12
|
+
authenticated: !0,
|
|
13
|
+
state: "authenticated",
|
|
14
|
+
testAccount: t.id,
|
|
15
|
+
can: (e) => r.includes(e),
|
|
16
|
+
logout: () => Promise.resolve(n()),
|
|
17
|
+
user: {
|
|
18
|
+
details: {
|
|
19
|
+
id: 0,
|
|
20
|
+
username: t.id,
|
|
21
|
+
email: t.email ?? "",
|
|
22
|
+
verified: !0,
|
|
23
|
+
permissions: r,
|
|
24
|
+
roles: t.roles ?? []
|
|
25
|
+
},
|
|
26
|
+
accessToken: `test:${t.id}`
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { t as guestAuth, n as testAccountAuth };
|
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
import { AuthManager as e } from "../../AuthManager.mjs";
|
|
2
|
-
import { useCallback as t, useEffect as n, useMemo as r,
|
|
2
|
+
import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
|
|
3
3
|
//#region src/hooks/useAuth/useAuth.ts
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
]),
|
|
12
|
-
m,
|
|
13
|
-
o,
|
|
14
|
-
l
|
|
15
|
-
]), g = d !== "init" && d !== "initLoading" || !!l || o || h?.state === "authenticated" || h?.state === "guest";
|
|
16
|
-
return n(() => (m.init({
|
|
17
|
-
user: l,
|
|
18
|
-
accessToken: u,
|
|
19
|
-
expiresAt: a?.user?.expiresAt,
|
|
20
|
-
skipAuth: a?.skipAuth
|
|
21
|
-
}), () => m.dispose()), [
|
|
22
|
-
m,
|
|
4
|
+
var o = /* @__PURE__ */ new Set([
|
|
5
|
+
"authenticating",
|
|
6
|
+
"signed-out",
|
|
7
|
+
"another-tab"
|
|
8
|
+
]), s = ({ server: s, isHydrating: c = !1, provider: l = "", settings: u }) => {
|
|
9
|
+
let [d, f] = a(!1), p = i(!1), m = s?.authenticated ? s.user?.details : void 0, h = typeof s?.user?.accessToken == "string" ? s.user.accessToken : void 0, g = d ? void 0 : m, _ = d ? void 0 : h, [v, y] = a("init"), b = t((e) => {
|
|
10
|
+
e.type === "state" && (y(e.state), e.reason !== void 0 && o.has(e.reason) && (p.current = !0, f(!0)));
|
|
11
|
+
}, []), x = r(() => new e(l, b, u), [
|
|
23
12
|
l,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
b,
|
|
14
|
+
u
|
|
15
|
+
]), S = r(() => c || g ? void 0 : x.peek(), [
|
|
16
|
+
x,
|
|
17
|
+
c,
|
|
18
|
+
g
|
|
19
|
+
]), C = v !== "init" && v !== "initLoading" || !!g || c || S?.state === "authenticated" || S?.state === "guest";
|
|
20
|
+
return n(() => {
|
|
21
|
+
let e = !p.current;
|
|
22
|
+
return x.init({
|
|
23
|
+
user: e ? m : void 0,
|
|
24
|
+
accessToken: e ? h : void 0,
|
|
25
|
+
expiresAt: e ? s?.user?.expiresAt : void 0,
|
|
26
|
+
skipAuth: s?.skipAuth
|
|
27
|
+
}), () => x.dispose();
|
|
28
|
+
}, [
|
|
29
|
+
x,
|
|
30
|
+
m,
|
|
31
|
+
h,
|
|
32
|
+
s?.user?.expiresAt,
|
|
33
|
+
s?.skipAuth
|
|
27
34
|
]), r(() => ({
|
|
28
|
-
manager:
|
|
29
|
-
state:
|
|
30
|
-
bootstrapUser:
|
|
31
|
-
bootstrapToken:
|
|
32
|
-
peekedUser:
|
|
33
|
-
peekedToken:
|
|
34
|
-
loading:
|
|
35
|
-
authenticated:
|
|
35
|
+
manager: x,
|
|
36
|
+
state: v,
|
|
37
|
+
bootstrapUser: g,
|
|
38
|
+
bootstrapToken: _,
|
|
39
|
+
peekedUser: S?.user,
|
|
40
|
+
peekedToken: S?.token?.accessToken,
|
|
41
|
+
loading: v === "initLoading" || !C,
|
|
42
|
+
authenticated: v === "authenticated" || v === "init" && (!!g || S?.state === "authenticated")
|
|
36
43
|
}), [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
l,
|
|
40
|
-
u,
|
|
44
|
+
x,
|
|
45
|
+
v,
|
|
41
46
|
g,
|
|
42
|
-
|
|
47
|
+
_,
|
|
48
|
+
C,
|
|
49
|
+
S
|
|
43
50
|
]);
|
|
44
51
|
};
|
|
45
52
|
//#endregion
|
|
46
|
-
export {
|
|
53
|
+
export { s as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from './AuthProvider';
|
|
|
8
8
|
export * from './AuthManager';
|
|
9
9
|
export * from './types';
|
|
10
10
|
export { readSessionHint } from './helpers/sessionHint';
|
|
11
|
+
export { guestAuth, testAccountAuth } from './helpers/sessionViews';
|
|
11
12
|
export { nowInSeconds, tokenExpiresAt } from './helpers/tokenClaims';
|
|
12
13
|
export { useAuth, AuthContext, AuthContextProvider, AuthProvider };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AuthContext as e } from "./AuthContext.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import i from "./
|
|
5
|
-
import
|
|
6
|
-
import c from "./
|
|
7
|
-
import
|
|
8
|
-
|
|
2
|
+
import { guestAuth as t, testAccountAuth as n } from "./helpers/sessionViews.mjs";
|
|
3
|
+
import { readSessionHint as r } from "./helpers/sessionHint.mjs";
|
|
4
|
+
import { nowInSeconds as i, tokenExpiresAt as a } from "./helpers/tokenClaims.mjs";
|
|
5
|
+
import o from "./AuthProvider.mjs";
|
|
6
|
+
import { AuthManager as s, getAuthProviderNames as c, registerAuthProvider as l } from "./AuthManager.mjs";
|
|
7
|
+
import u from "./hooks/useAuth/index.mjs";
|
|
8
|
+
import d from "./AuthContextProvider.mjs";
|
|
9
|
+
export { e as AuthContext, d as AuthContextProvider, s as AuthManager, o as AuthProvider, c as getAuthProviderNames, t as guestAuth, i as nowInSeconds, r as readSessionHint, l as registerAuthProvider, n as testAccountAuth, a as tokenExpiresAt, u as useAuth };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { default as AuthProvider, AuthProviderProps } from '../AuthProvider';
|
|
2
|
-
import { AuthResult, MfaChallenge, Schema } from '@plitzi/sdk-shared';
|
|
2
|
+
import { AuthResult, MfaChallenge, Schema, SessionScope } from '@plitzi/sdk-shared';
|
|
3
3
|
export type BasicAuthProviderProps = AuthProviderProps & {
|
|
4
4
|
loginUrl?: string;
|
|
5
5
|
userUrl?: string;
|
|
6
6
|
refreshUrl?: string;
|
|
7
7
|
logoutUrl?: string;
|
|
8
|
+
revokeUrl?: string;
|
|
8
9
|
sessionExchangeUrl?: Schema['settings']['sessionExchangeUrl'];
|
|
9
10
|
mfaUrl?: Schema['settings']['mfaUrl'];
|
|
10
11
|
detailsPath?: Schema['settings']['detailsPath'];
|
|
@@ -16,7 +17,7 @@ export type BasicAuthProviderProps = AuthProviderProps & {
|
|
|
16
17
|
declare class BasicAuthProvider<U = Record<string, unknown>> extends AuthProvider<U> {
|
|
17
18
|
readonly name = "basic";
|
|
18
19
|
private readonly options;
|
|
19
|
-
constructor({ loginUrl, userUrl, refreshUrl, logoutUrl, sessionExchangeUrl, mfaUrl, detailsPath, tokenPath, refreshTokenPath, expirationTimePath, refreshExpirationTimePath, ...providerProps }?: BasicAuthProviderProps);
|
|
20
|
+
constructor({ loginUrl, userUrl, refreshUrl, logoutUrl, revokeUrl, sessionExchangeUrl, mfaUrl, detailsPath, tokenPath, refreshTokenPath, expirationTimePath, refreshExpirationTimePath, ...providerProps }?: BasicAuthProviderProps);
|
|
20
21
|
protected get capabilities(): {
|
|
21
22
|
renew: boolean;
|
|
22
23
|
identity: boolean;
|
|
@@ -46,6 +47,12 @@ declare class BasicAuthProvider<U = Record<string, unknown>> extends AuthProvide
|
|
|
46
47
|
protected requestExchange(): Promise<AuthResult<U> | undefined>;
|
|
47
48
|
protected requestIdentity(): Promise<AuthResult<U>>;
|
|
48
49
|
protected requestLogout(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* The backend ends them (`revokeUrl`, `{ scope }` posted), asked with the session's own token — a bearer needs no
|
|
52
|
+
* CSRF token, and is the credential the backend reads first. No `revokeUrl`: refused, naming it, never a sign-out
|
|
53
|
+
* here that left the other devices signed in.
|
|
54
|
+
*/
|
|
55
|
+
protected requestLogoutEverywhere(scope: SessionScope): Promise<void>;
|
|
49
56
|
private request;
|
|
50
57
|
/**
|
|
51
58
|
* A right password on an account with a second factor: a challenge, not a session with nobody in it. Read as the
|
|
@@ -11,19 +11,20 @@ var r = (e, n) => t(e, n, void 0), i = (e, t) => {
|
|
|
11
11
|
}, o = (e) => typeof e == "string" ? e : typeof e == "number" && Number.isFinite(e) ? String(e) : "", s = class extends e {
|
|
12
12
|
name = "basic";
|
|
13
13
|
options;
|
|
14
|
-
constructor({ loginUrl: e = "", userUrl: t = "", refreshUrl: n = "", logoutUrl: r = "",
|
|
15
|
-
super(
|
|
14
|
+
constructor({ loginUrl: e = "", userUrl: t = "", refreshUrl: n = "", logoutUrl: r = "", revokeUrl: i = "", sessionExchangeUrl: a = "", mfaUrl: o = "", detailsPath: s = "details", tokenPath: c = "access_token", refreshTokenPath: l = "refresh_token", expirationTimePath: u = "expire_at", refreshExpirationTimePath: d = "refresh_expire_at", ...f } = {}) {
|
|
15
|
+
super(f), this.options = {
|
|
16
16
|
loginUrl: e,
|
|
17
17
|
userUrl: t,
|
|
18
18
|
refreshUrl: n,
|
|
19
19
|
logoutUrl: r,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
revokeUrl: i,
|
|
21
|
+
sessionExchangeUrl: a,
|
|
22
|
+
mfaUrl: o,
|
|
23
|
+
detailsPath: s,
|
|
24
|
+
tokenPath: c,
|
|
25
|
+
refreshTokenPath: l,
|
|
26
|
+
expirationTimePath: u,
|
|
27
|
+
refreshExpirationTimePath: d
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
get capabilities() {
|
|
@@ -33,12 +34,13 @@ var r = (e, n) => t(e, n, void 0), i = (e, t) => {
|
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
get endpoints() {
|
|
36
|
-
let { loginUrl: e, userUrl: t, refreshUrl: n, logoutUrl: r } = this.options;
|
|
37
|
+
let { loginUrl: e, userUrl: t, refreshUrl: n, logoutUrl: r, revokeUrl: i } = this.options;
|
|
37
38
|
return [
|
|
38
39
|
e,
|
|
39
40
|
t,
|
|
40
41
|
n,
|
|
41
|
-
r
|
|
42
|
+
r,
|
|
43
|
+
i
|
|
42
44
|
];
|
|
43
45
|
}
|
|
44
46
|
async requestLogin(e) {
|
|
@@ -133,6 +135,18 @@ var r = (e, n) => t(e, n, void 0), i = (e, t) => {
|
|
|
133
135
|
async requestLogout() {
|
|
134
136
|
this.options.logoutUrl && await this.request(this.options.logoutUrl, { method: "POST" });
|
|
135
137
|
}
|
|
138
|
+
async requestLogoutEverywhere(e) {
|
|
139
|
+
if (!this.options.revokeUrl) throw Error("This space signs out everywhere through its revokeUrl, and it names none (settings.revokeUrl)");
|
|
140
|
+
let t = this.token?.accessToken, n = await this.request(this.options.revokeUrl, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
headers: {
|
|
143
|
+
"Content-Type": "application/json",
|
|
144
|
+
...t ? { Authorization: `Bearer ${t}` } : {}
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify({ scope: e })
|
|
147
|
+
});
|
|
148
|
+
if (n.reason && n.status !== 401) throw Error(`Signing out everywhere was refused (${String(n.status)})`);
|
|
149
|
+
}
|
|
136
150
|
async request(e, t) {
|
|
137
151
|
let r;
|
|
138
152
|
try {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { default as AuthProvider, AuthProviderProps } from '../AuthProvider';
|
|
2
|
-
import { AuthResult, MfaChallenge } from '@plitzi/sdk-shared';
|
|
2
|
+
import { AuthResult, MfaChallenge, SessionScope } from '@plitzi/sdk-shared';
|
|
3
3
|
export type ServerAuthProviderProps = AuthProviderProps & {
|
|
4
4
|
/** Where the page server starts a sign-in by redirect. Default `/auth/sign-in` (`createServer({ signIn })`). */
|
|
5
5
|
loginUrl?: string;
|
|
6
6
|
/** Where the page server ends the session on its host. Default `/auth/logout`. */
|
|
7
7
|
logoutUrl?: string;
|
|
8
|
+
/** Where it ends the person's sessions on every device (`endSessions`). Default `/auth/logout-everywhere`. */
|
|
9
|
+
logoutEverywhereUrl?: string;
|
|
8
10
|
};
|
|
9
11
|
/**
|
|
10
12
|
* A space whose people sign in THROUGH the server that renders it: signing in is a redirect out and back
|
|
@@ -19,7 +21,8 @@ declare class ServerAuthProvider<U = Record<string, unknown>> extends AuthProvid
|
|
|
19
21
|
readonly name = "server";
|
|
20
22
|
private readonly loginUrl;
|
|
21
23
|
private readonly logoutUrl;
|
|
22
|
-
|
|
24
|
+
private readonly logoutEverywhereUrl;
|
|
25
|
+
constructor({ loginUrl, logoutUrl, logoutEverywhereUrl, ...providerProps }?: ServerAuthProviderProps);
|
|
23
26
|
protected get capabilities(): {
|
|
24
27
|
renew: boolean;
|
|
25
28
|
identity: boolean;
|
|
@@ -32,6 +35,11 @@ declare class ServerAuthProvider<U = Record<string, unknown>> extends AuthProvid
|
|
|
32
35
|
protected requestRenewal(): Promise<AuthResult<U>>;
|
|
33
36
|
protected requestIdentity(): Promise<AuthResult<U>>;
|
|
34
37
|
protected requestLogout(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* The page server ends them (`/auth/logout-everywhere`): `site`, those signed in on this space's host — a visitor's
|
|
40
|
+
* own, on every device; `all`, every one of the account. A 401 is nobody signed in, so nothing is left to end.
|
|
41
|
+
*/
|
|
42
|
+
protected requestLogoutEverywhere(scope: SessionScope): Promise<void>;
|
|
35
43
|
/**
|
|
36
44
|
* Nothing to confirm from here: the page cannot see its own session, and the server answers who is signed in on
|
|
37
45
|
* every page it serves. The session stands as the server rendered it until the server says otherwise.
|
|
@@ -4,11 +4,12 @@ var t = class extends e {
|
|
|
4
4
|
name = "server";
|
|
5
5
|
loginUrl;
|
|
6
6
|
logoutUrl;
|
|
7
|
-
|
|
7
|
+
logoutEverywhereUrl;
|
|
8
|
+
constructor({ loginUrl: e = "", logoutUrl: t = "", logoutEverywhereUrl: n = "", ...r } = {}) {
|
|
8
9
|
super({
|
|
9
|
-
...
|
|
10
|
+
...r,
|
|
10
11
|
tokenStorage: ""
|
|
11
|
-
}), this.loginUrl = e || "/auth/sign-in", this.logoutUrl = t || "/auth/logout";
|
|
12
|
+
}), this.loginUrl = e || "/auth/sign-in", this.logoutUrl = t || "/auth/logout", this.logoutEverywhereUrl = n || "/auth/logout-everywhere";
|
|
12
13
|
}
|
|
13
14
|
get capabilities() {
|
|
14
15
|
return {
|
|
@@ -38,6 +39,15 @@ var t = class extends e {
|
|
|
38
39
|
credentials: "same-origin"
|
|
39
40
|
});
|
|
40
41
|
}
|
|
42
|
+
async requestLogoutEverywhere(e) {
|
|
43
|
+
let t = await fetch(this.logoutEverywhereUrl, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
credentials: "same-origin",
|
|
46
|
+
headers: { "Content-Type": "application/json" },
|
|
47
|
+
body: JSON.stringify({ scope: e })
|
|
48
|
+
});
|
|
49
|
+
if (!t.ok && t.status !== 401) throw Error(`Signing out everywhere was refused (${String(t.status)})`);
|
|
50
|
+
}
|
|
41
51
|
revalidate() {
|
|
42
52
|
return Promise.resolve(this.getState() === "authenticated");
|
|
43
53
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { Schema } from '@plitzi/sdk-shared';
|
|
|
3
3
|
* Everything a space declares about its auth backend, handed to whichever provider it selected. Derived from the
|
|
4
4
|
* schema rather than restated, so a setting added there reaches providers without a second definition to keep in step.
|
|
5
5
|
*/
|
|
6
|
-
export type AuthProviderSettings = Pick<Schema['settings'], 'tokenStorage' | 'loginUrl' | 'userUrl' | 'refreshUrl' | 'logoutUrl' | 'detailsPath' | 'tokenPath' | 'refreshTokenPath' | 'expirationTimePath' | 'refreshExpirationTimePath' | 'sessionHintCookie' | 'sessionExchangeUrl' | 'mfaUrl' | 'sessionGate' | 'sessionRevalidateSeconds'>;
|
|
6
|
+
export type AuthProviderSettings = Pick<Schema['settings'], 'tokenStorage' | 'loginUrl' | 'userUrl' | 'refreshUrl' | 'logoutUrl' | 'revokeUrl' | 'detailsPath' | 'tokenPath' | 'refreshTokenPath' | 'expirationTimePath' | 'refreshExpirationTimePath' | 'sessionHintCookie' | 'sessionExchangeUrl' | 'mfaUrl' | 'sessionGate' | 'sessionRevalidateSeconds'>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@plitzi/nexus": "^1.4.0",
|
|
34
|
-
"@plitzi/plitzi-ui": "^1.6.
|
|
35
|
-
"@plitzi/sdk-navigation": "0.
|
|
36
|
-
"@plitzi/sdk-shared": "0.
|
|
34
|
+
"@plitzi/plitzi-ui": "^1.6.36",
|
|
35
|
+
"@plitzi/sdk-navigation": "0.39.0",
|
|
36
|
+
"@plitzi/sdk-shared": "0.39.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"eslint": "^9.39.5",
|