@flipstream/sdk 0.5.0 → 0.7.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 +69 -0
- package/README.md +325 -53
- package/dist/auth/discovery.d.ts +5 -4
- package/dist/auth/discovery.js +10 -8
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.js +10 -5
- package/dist/auth/signIn.js.map +1 -1
- package/dist/auth/transport.d.ts +20 -2
- package/dist/auth/transport.js +25 -5
- package/dist/auth/transport.js.map +1 -1
- package/dist/core/fetch.d.ts +5 -0
- package/dist/core/fetch.js +8 -1
- package/dist/core/fetch.js.map +1 -1
- package/dist/flipstream.d.ts +8 -0
- package/dist/flipstream.js +4 -3
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/node/fileLock.d.ts +21 -0
- package/dist/node/fileLock.js +36 -48
- package/dist/node/fileLock.js.map +1 -1
- package/dist/node/fileStore.d.ts +41 -0
- package/dist/node/fileStore.js +137 -0
- package/dist/node/fileStore.js.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.js +3 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.d.ts +1 -0
- package/dist/node/keychainChild.js +136 -0
- package/dist/node/keychainChild.js.map +1 -0
- package/dist/node/keychainStore.d.ts +34 -0
- package/dist/node/keychainStore.js +268 -0
- package/dist/node/keychainStore.js.map +1 -0
- package/dist/node/loopback.js +1 -1
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +73 -12
- package/dist/node/session.js +248 -35
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +48 -0
- package/dist/node/store.js +99 -0
- package/dist/node/store.js.map +1 -0
- package/dist/query/catalog.d.ts +271 -2
- package/dist/query/catalog.js +93 -5
- package/dist/query/catalog.js.map +1 -1
- package/dist/query/query.d.ts +14 -5
- package/dist/query/query.js +21 -6
- package/dist/query/query.js.map +1 -1
- package/dist/spec/query-planner/index.d.ts +1 -1
- package/dist/spec/query-planner/types.gen.d.ts +35 -4
- package/dist/spec/query-planner/zod.gen.d.ts +257 -64
- package/dist/spec/query-planner/zod.gen.js +31 -5
- package/dist/spec/query-planner/zod.gen.js.map +1 -1
- package/dist/version.gen.d.ts +2 -0
- package/dist/version.gen.js +4 -0
- package/dist/version.gen.js.map +1 -0
- package/package.json +9 -3
package/dist/node/loopback.js
CHANGED
|
@@ -68,7 +68,7 @@ export async function signInWithLoopback(options) {
|
|
|
68
68
|
// The redirect came in time: the exchange has its own deadline (`finishSignIn`).
|
|
69
69
|
clearTimeout(timer);
|
|
70
70
|
reading.abort();
|
|
71
|
-
return finishSignIn(callbackUrl, pending, { signal, fetch: options.fetch });
|
|
71
|
+
return finishSignIn(callbackUrl, pending, { signal, fetch: options.fetch, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
72
72
|
};
|
|
73
73
|
timer = setTimeout(() => {
|
|
74
74
|
endWait({ kind: 'timeout' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopback.js","sourceRoot":"","sources":["../../src/node/loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAA;AAEhG,OAAO,EAAE,YAAY,EAAE,WAAW,EAAwE,MAAM,mBAAmB,CAAA;AAEnI,OAAO,EAAE,mBAAmB,EAAuB,MAAM,eAAe,CAAA;AAyCxE,MAAM,OAAO,GAAG,OAAO,CAAA;AAEvB,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,IAAY,EAAU,EAAE,CACrD,qEAAqE,OAAO,iBAAiB;IAC7F,iGAAiG;IACjG,OAAO,OAAO,WAAW,IAAI,MAAM;IACnC,kFAAkF;IAClF,+FAA+F,CAAA;AACjG,MAAM,KAAK,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,yBAAyB,CAAC,EAAE,MAAM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,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAA;QAC1H,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IACtE,MAAM,KAAK,EAAE,CAAA;IACb,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAA;AACzC,CAAC;AAED;;;GAGG;AACH,SAAS,IAAI,CAAC,QAAwB,EAAE,MAAc,EAAE,IAAY;IAClE,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,aAAa;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1E,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,0BAA0B,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAA;IAC5H,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/node/session.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TokenAsk } from '../core/fetch.js';
|
|
2
2
|
import type { ApiError } from '../core/result.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type AuthServer } from '../auth/discovery.js';
|
|
4
4
|
import type { Tokens } from '../auth/signIn.js';
|
|
5
5
|
import { type AuthCallOptions } from '../auth/transport.js';
|
|
6
6
|
/** What the app's store holds: `finishSignIn`'s tokens fit. */
|
|
@@ -33,21 +33,40 @@ export type TokenUpdate =
|
|
|
33
33
|
readonly replaces: string;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* The server ended
|
|
37
|
-
* store's key is still `replaces`, so a
|
|
36
|
+
* The session is over: the server ended it (`invalid_grant`), or the app signed out
|
|
37
|
+
* (`revoke()`). Delete the stored tokens, only while the store's key is still `replaces`, so a
|
|
38
|
+
* newer sign-in is kept. For a store that holds only an access token, `replaces` is that token.
|
|
38
39
|
*/
|
|
39
40
|
| {
|
|
40
41
|
readonly kind: 'cleared';
|
|
41
42
|
readonly replaces: string;
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Where the session refreshes and signs out comes from exactly one of `issuer` and `server`:
|
|
46
|
+
* neither or both doesn't compile. From JavaScript, neither, both, or an issuer that is no https
|
|
47
|
+
* URL (or, with `allowLocalhostHttp`, no http one on this machine) is a TypeError at creation, and
|
|
48
|
+
* so, with the option, is a server whose endpoints break its issuer's rule: https for an https
|
|
49
|
+
* issuer, its own origin for an http one.
|
|
50
|
+
*/
|
|
51
|
+
export type SessionOptions = Pick<AuthCallOptions, 'fetch' | 'allowLocalhostHttp'> & ({
|
|
52
|
+
/**
|
|
53
|
+
* The session discovers the server itself (`discover`'s rules), at the first refresh or
|
|
54
|
+
* sign-out that needs it, and keeps it (#130). A token with time left is handed out with
|
|
55
|
+
* nothing sent to the auth host. Written exactly as the metadata names it: for pulse-auth,
|
|
56
|
+
* `https://auth.flipstream.io`, with no slash at the end.
|
|
57
|
+
*/
|
|
58
|
+
readonly issuer: string;
|
|
59
|
+
readonly server?: never;
|
|
60
|
+
} | {
|
|
61
|
+
/** The server, as `discover` gave it, for an app that has discovered already. */
|
|
45
62
|
readonly server: AuthServer;
|
|
63
|
+
readonly issuer?: never;
|
|
64
|
+
}) & {
|
|
46
65
|
/** The app's own OAuth client ID (D421). */
|
|
47
66
|
readonly clientId: string;
|
|
48
67
|
/**
|
|
49
68
|
* The app's client secret, as a confidential client (#123): sent only in the Authorization header
|
|
50
|
-
* of the refresh and the revocation, to
|
|
69
|
+
* of the refresh and the revocation, to the server's own endpoints, and their failures then keep
|
|
51
70
|
* no server text (`finishSignIn`'s rule). Left out, the session is a public client's. Never log it.
|
|
52
71
|
*/
|
|
53
72
|
readonly clientSecret?: string | undefined;
|
|
@@ -67,8 +86,8 @@ export interface SessionOptions extends Pick<AuthCallOptions, 'fetch'> {
|
|
|
67
86
|
*/
|
|
68
87
|
readonly tokens: () => SessionTokens | null | Promise<SessionTokens | null>;
|
|
69
88
|
/**
|
|
70
|
-
* Saves a refresh's tokens, or clears them once the
|
|
71
|
-
*
|
|
89
|
+
* Saves a refresh's tokens, or clears them once the session is over, only while the store's key
|
|
90
|
+
* (`refreshToken || accessToken`) is still `update.replaces`. The session reads the
|
|
72
91
|
* store again just before, and lets the answer go when the store has moved on (a newer sign-in,
|
|
73
92
|
* or a sign-out); comparing and setting on `replaces` closes the moment between that read and
|
|
74
93
|
* this write, and a store that refuses then throws. A refresh's answer is used only once this has
|
|
@@ -89,6 +108,8 @@ export interface SessionOptions extends Pick<AuthCallOptions, 'fetch'> {
|
|
|
89
108
|
* The lock's promise must settle only once `work` has settled, as Web Locks does with its
|
|
90
109
|
* signal: a lock that lets go while `work` still runs (a mutex with a timeout) lets another
|
|
91
110
|
* process in beside a pending save. The session itself waits for `work` before its next turn.
|
|
111
|
+
* A sign-out's turn passes a signal that fires 60 s after the turn reaches the lock (D487): it
|
|
112
|
+
* waits that long to clear the store, though it sends nothing after its own 10 s.
|
|
92
113
|
*
|
|
93
114
|
* Without one, there must be one session per store, shared by everything that uses it: two
|
|
94
115
|
* sessions on one store, in one process (a backend making one per request) or in two, refresh
|
|
@@ -97,7 +118,7 @@ export interface SessionOptions extends Pick<AuthCallOptions, 'fetch'> {
|
|
|
97
118
|
* ends.
|
|
98
119
|
*/
|
|
99
120
|
readonly lock?: <T>(work: () => Promise<T>, signal: AbortSignal) => Promise<T>;
|
|
100
|
-
}
|
|
121
|
+
};
|
|
101
122
|
/** Why a session has no token to give. */
|
|
102
123
|
export type SessionFailure =
|
|
103
124
|
/**
|
|
@@ -183,10 +204,50 @@ export interface Session {
|
|
|
183
204
|
* fails, the live refresh token goes (the store's, or a rotation's whose save failed, D456), and
|
|
184
205
|
* the result is `unconfirmed`.
|
|
185
206
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
207
|
+
* A sign-out ends the session the store holds when its turn comes (#134), a newer sign-in from
|
|
208
|
+
* another terminal included: signing out means this person is signed out on this machine (D484).
|
|
209
|
+
* Its turn is queued at the call, and in one hold of the app's lock it revokes that session, then
|
|
210
|
+
* clears it from the store through `onTokens` (`cleared`), once, however the revocation went: in
|
|
211
|
+
* time or too late to send anything, aborted by the caller (D478), failed, or with any result. A
|
|
212
|
+
* sign-in saved after the turn read the store is kept. The caller waits for the clear within its
|
|
213
|
+
* 10 s.
|
|
214
|
+
*
|
|
215
|
+
* A refresh token the session holds only in memory, because saving it failed (D456), goes too once
|
|
216
|
+
* the store has moved on from the token it replaced: as a refresh token, after the stored session,
|
|
217
|
+
* in the same 10 s. One sign-out sends it, whatever the result, and the session then lets it go
|
|
218
|
+
* (D500). Its send failing is the result when the stored session's went as well as it can.
|
|
219
|
+
*
|
|
220
|
+
* Once the turn reaches the lock, it waits at most 60 s for it, and at most 60 s for each store
|
|
221
|
+
* call; then it gives up, touching nothing more, and later turns run (D487). So after `timeout`
|
|
222
|
+
* or `aborted` the clear may still be on its way: 60 s for the lock and for each of its three
|
|
223
|
+
* store calls, so up to about four minutes after the turn reaches the lock, plus any queue ahead
|
|
224
|
+
* of it. A lock held longer than its 60 s by another process, or a store call that doesn't answer
|
|
225
|
+
* within its 60 s, leaves the store as it was. A clear the
|
|
226
|
+
* store fails leaves the tokens too: until the next refresh meets `invalid_grant`, or, for a store
|
|
227
|
+
* holding only an access token, until that token expires.
|
|
189
228
|
*/
|
|
190
229
|
revoke(options?: Pick<AuthCallOptions, 'signal'>): Promise<RevokeResult>;
|
|
230
|
+
/**
|
|
231
|
+
* Resolves once nothing is in flight in this session: no refresh, no save, no sign-out, and no
|
|
232
|
+
* `token()` still reading the store before it queues a refresh (#170, D516). Await it before the
|
|
233
|
+
* process exits, on Ctrl-C or after `unavailable`: `token()` answers at its 15 s and `revoke()`
|
|
234
|
+
* at its 10 s while their work goes on, and an exit then can cut a refresh after pulse-auth has
|
|
235
|
+
* rotated, losing the new token. Work that starts while it waits is waited for too.
|
|
236
|
+
*
|
|
237
|
+
* It never rejects, and it starts no work. It waits at most as long as the session's own limits
|
|
238
|
+
* (D521): a refresh's 60 s for its lock and its request (D445), and a sign-out's 60 s for the lock
|
|
239
|
+
* and for each store call (D487). What those limits leave out:
|
|
240
|
+
* - a store that never answers a read or a save holds it too: a `token()` call's first read, and a
|
|
241
|
+
* refresh's re-read and save, are waited out, never cut short;
|
|
242
|
+
* - so does a lock that ignores its signal, which holds a turn for as long as it waits;
|
|
243
|
+
* - so do calls that keep coming: stop making them before awaiting this;
|
|
244
|
+
* - a sign-out's store call still running after its 60 s isn't waited for: the turn has given up
|
|
245
|
+
* on it, and so does this.
|
|
246
|
+
* The SDK's own stores answer every call: `fileStore`'s steps don't hang, and `keychainStore`'s
|
|
247
|
+
* each end within its `timeoutMs`, 30 s unless the app sets more. A save or a clear is two of
|
|
248
|
+
* those steps, a read and a write, so a `timeoutMs` over 30 s can run a sign-out's clear past its
|
|
249
|
+
* 60 s.
|
|
250
|
+
*/
|
|
251
|
+
settled(): Promise<void>;
|
|
191
252
|
}
|
|
192
253
|
export declare function createSession(options: SessionOptions): Session;
|
package/dist/node/session.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
|
+
import { discover } from '../auth/discovery.js';
|
|
3
4
|
import { tokenCall } from '../auth/tokenEndpoint.js';
|
|
4
|
-
import { authTransport,
|
|
5
|
+
import { authTransport, endpointProblem, isSignInUrl } from '../auth/transport.js';
|
|
5
6
|
import { clientAuthorization, vouched } from './clientSecret.js';
|
|
6
7
|
/** Thrown by `session.token()`; the default transport turns it into `no_token`, with this as its `cause`. */
|
|
7
8
|
export class SessionError extends Error {
|
|
@@ -24,6 +25,11 @@ const MARGIN_MS = 60_000;
|
|
|
24
25
|
const CHECK_MARGIN_MS = 30_000;
|
|
25
26
|
/** A refresh with less than this left isn't sent: its answer could be cut off after the rotation (K6). */
|
|
26
27
|
const SEND_FLOOR_MS = 5_000;
|
|
28
|
+
/**
|
|
29
|
+
* A sign-out's turn waits at most this for the app's lock, counted from when it reaches the lock,
|
|
30
|
+
* and at most this for each of its store calls; then it gives up, touching nothing more (D487).
|
|
31
|
+
*/
|
|
32
|
+
const SIGN_OUT_WAIT_MS = 60_000;
|
|
27
33
|
// A field set to undefined is read as left out, as a JavaScript store may well hand it back.
|
|
28
34
|
const zStored = z.object({
|
|
29
35
|
accessToken: z.string().min(1),
|
|
@@ -33,20 +39,59 @@ const zStored = z.object({
|
|
|
33
39
|
const SIGNED_OUT = { kind: 'signed-out' };
|
|
34
40
|
const UNAVAILABLE = { kind: 'unavailable' };
|
|
35
41
|
export function createSession(options) {
|
|
36
|
-
const {
|
|
42
|
+
const { clientId, issuer } = options;
|
|
43
|
+
if ((options.server === undefined) === (issuer === undefined))
|
|
44
|
+
throw new TypeError('createSession: give exactly one of issuer and server');
|
|
45
|
+
if (issuer !== undefined && (typeof issuer !== 'string' || !isSignInUrl(issuer, options.allowLocalhostHttp))) {
|
|
46
|
+
throw new TypeError(options.allowLocalhostHttp === true ? 'createSession: issuer must be an https URL, or an http one on this machine' : 'createSession: issuer must be an https URL');
|
|
47
|
+
}
|
|
48
|
+
const given = options.server;
|
|
49
|
+
if (options.allowLocalhostHttp === true && given !== undefined) {
|
|
50
|
+
const endpoints = [given.authorizationEndpoint, given.tokenEndpoint, ...(given.revocationEndpoint === undefined ? [] : [given.revocationEndpoint])];
|
|
51
|
+
if (endpointProblem(given.issuer, endpoints) !== null)
|
|
52
|
+
throw new TypeError("createSession: the server's endpoints must be https, or for an http issuer on this machine, on its origin");
|
|
53
|
+
}
|
|
37
54
|
// Made once: a TypeError here, at creation, for a secret that is given but blank.
|
|
38
55
|
const authorization = clientAuthorization('createSession', clientId, options.clientSecret);
|
|
39
|
-
const transport = authTransport({ fetch: options.fetch });
|
|
56
|
+
const transport = authTransport({ fetch: options.fetch, allowLocalhostHttp: options.allowLocalhostHttp });
|
|
40
57
|
let inFlight = null;
|
|
41
58
|
let tail = Promise.resolve();
|
|
59
|
+
// Every token() call's own work, until it has answered or queued its turn: one still reading the
|
|
60
|
+
// store hasn't queued its refresh yet, so settled() waits for it as well as for the queue.
|
|
61
|
+
const asking = new Set();
|
|
42
62
|
// A rotation whose save failed. Its refresh token is the session's only live one while the store
|
|
43
63
|
// still holds the token it replaced, which is spent (D456).
|
|
44
64
|
let unsaved = null;
|
|
65
|
+
// Unsaved rotations the store has moved on from: no longer the session's, but still live at
|
|
66
|
+
// pulse-auth, so the next sign-out sends them too, and then lets them go (D500).
|
|
67
|
+
let setAside = [];
|
|
45
68
|
// A refresh token whose last refresh got no answer the session could read: the server may have
|
|
46
69
|
// rotated it, so it may be spent (S5.B1). Cleared by the next answer for it.
|
|
47
70
|
let doubtful = null;
|
|
48
71
|
// The issuer's userinfo endpoint, once found: what a revocation is checked against.
|
|
49
72
|
let userinfo = null;
|
|
73
|
+
// The server, once known: given, or discovered by the first turn that needs it, then kept. A
|
|
74
|
+
// discovery that fails is tried again at the next need.
|
|
75
|
+
let known = options.server;
|
|
76
|
+
/**
|
|
77
|
+
* The server, discovered inside the turn that needs it (#130): only a refresh about to send, or
|
|
78
|
+
* a sign-out with something to revoke, asks the auth host for it. Held to that turn's deadline.
|
|
79
|
+
*/
|
|
80
|
+
async function serverFor(limit) {
|
|
81
|
+
if (known !== undefined)
|
|
82
|
+
return { ok: true, data: known };
|
|
83
|
+
if (issuer === undefined)
|
|
84
|
+
return { ok: false, error: { kind: 'refused' } };
|
|
85
|
+
// By the clock too, as every send: a store that blocked the thread past the deadline returns
|
|
86
|
+
// before its timer has run (S1.F1).
|
|
87
|
+
const ended = limit.ended();
|
|
88
|
+
if (ended !== null)
|
|
89
|
+
return { ok: false, error: ended };
|
|
90
|
+
const found = await discover(issuer, { fetch: options.fetch, allowLocalhostHttp: options.allowLocalhostHttp, signal: limit.signal });
|
|
91
|
+
if (found.ok)
|
|
92
|
+
known = found.data;
|
|
93
|
+
return found;
|
|
94
|
+
}
|
|
50
95
|
async function read() {
|
|
51
96
|
try {
|
|
52
97
|
const stored = await options.tokens();
|
|
@@ -63,12 +108,14 @@ export function createSession(options) {
|
|
|
63
108
|
/**
|
|
64
109
|
* The refresh token that is live now, and the stored one it stands for: an unsaved rotation's
|
|
65
110
|
* while the store still holds the token it replaced, else the store's. A store that moved on (a
|
|
66
|
-
* newer sign-in, a sign-out)
|
|
111
|
+
* newer sign-in, a sign-out) sets the unsaved rotation aside, for the next sign-out (D500).
|
|
67
112
|
*/
|
|
68
113
|
function liveOf(held) {
|
|
69
114
|
const stored = held?.refreshToken;
|
|
70
|
-
if (unsaved !== null && unsaved.replaces !== stored)
|
|
115
|
+
if (unsaved !== null && unsaved.replaces !== stored) {
|
|
116
|
+
setAside.push(unsaved.refreshToken);
|
|
71
117
|
unsaved = null;
|
|
118
|
+
}
|
|
72
119
|
if (stored === undefined || stored === '')
|
|
73
120
|
return undefined;
|
|
74
121
|
return { token: unsaved?.refreshToken ?? stored, stored };
|
|
@@ -95,6 +142,11 @@ export function createSession(options) {
|
|
|
95
142
|
return { kind: 'token', accessToken: held.accessToken };
|
|
96
143
|
if (live === undefined)
|
|
97
144
|
return SIGNED_OUT;
|
|
145
|
+
// The server, discovered now if this is the first turn that needs it (#130).
|
|
146
|
+
const found = await serverFor(limit);
|
|
147
|
+
if (!found.ok)
|
|
148
|
+
return discoveryFailure(found.error);
|
|
149
|
+
const server = found.data;
|
|
98
150
|
// By the clock, not only the timer (a store that blocks the thread returns before the timer
|
|
99
151
|
// runs), and never with under 5 s left: a request cut off after pulse-auth rotated loses the
|
|
100
152
|
// new token, and the next refresh then ends the session (K6). Unsent is better.
|
|
@@ -108,15 +160,16 @@ export function createSession(options) {
|
|
|
108
160
|
const failure = failureOf(answer.error);
|
|
109
161
|
if (failure.kind !== 'signed-out')
|
|
110
162
|
return failure;
|
|
111
|
-
// The server ended the session the token sent belongs to
|
|
163
|
+
// The server ended the session the token sent belongs to, an unsaved rotation's included:
|
|
164
|
+
// nothing of it is live, so nothing is set aside (D500). The store's tokens are cleared,
|
|
112
165
|
// but only if they're still that session's: a newer sign-in another process saved
|
|
113
166
|
// meanwhile is kept, and used (D461).
|
|
167
|
+
unsaved = null;
|
|
114
168
|
const after = await read();
|
|
115
169
|
if (!after.ok)
|
|
116
170
|
return after.failure;
|
|
117
171
|
if (after.tokens?.refreshToken !== live.stored)
|
|
118
172
|
continue;
|
|
119
|
-
unsaved = null;
|
|
120
173
|
try {
|
|
121
174
|
await options.onTokens({ kind: 'cleared', replaces: live.stored });
|
|
122
175
|
}
|
|
@@ -139,9 +192,15 @@ export function createSession(options) {
|
|
|
139
192
|
return before.failure;
|
|
140
193
|
}
|
|
141
194
|
// The store moved on meanwhile, to a newer sign-in or a sign-out that this answer must not
|
|
142
|
-
// overwrite: the answer
|
|
143
|
-
|
|
195
|
+
// overwrite: the answer isn't saved, and the refresh starts over from the store as it is now.
|
|
196
|
+
// The token sent is spent. A rotation it got is live at pulse-auth, and no longer the
|
|
197
|
+
// session's, so it's set aside for the next sign-out (D500).
|
|
198
|
+
if (before.tokens?.refreshToken !== live.stored) {
|
|
199
|
+
unsaved = null;
|
|
200
|
+
if (update.kind === 'rotated')
|
|
201
|
+
setAside.push(update.refreshToken);
|
|
144
202
|
continue;
|
|
203
|
+
}
|
|
145
204
|
try {
|
|
146
205
|
await options.onTokens(update);
|
|
147
206
|
}
|
|
@@ -171,6 +230,35 @@ export function createSession(options) {
|
|
|
171
230
|
tail = turn.then(noop, noop).then(() => run.begun?.then(noop, noop));
|
|
172
231
|
return { turn, run };
|
|
173
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* A sign-out's turn in the session's queue (#134, D487). Once it reaches the app's lock, it waits
|
|
235
|
+
* for it at most 60 s: the lock's signal fires then, and a lock that runs the work later anyway
|
|
236
|
+
* runs nothing. Past that, the turn gives up without touching the store (`late()`), and the
|
|
237
|
+
* queue moves on. The work, once begun, is bound by its own calls, each at most 60 s.
|
|
238
|
+
*/
|
|
239
|
+
function enqueueSignOut(work, late) {
|
|
240
|
+
const run = {};
|
|
241
|
+
const { lock } = options;
|
|
242
|
+
const turn = tail.then(async () => {
|
|
243
|
+
const bound = createLimit(SIGN_OUT_WAIT_MS, undefined);
|
|
244
|
+
try {
|
|
245
|
+
const begin = () => {
|
|
246
|
+
run.begun = bound.ended() !== null ? Promise.resolve(late()) : work();
|
|
247
|
+
return run.begun;
|
|
248
|
+
};
|
|
249
|
+
const held = orAborted(lock === undefined ? begin() : lock(begin, bound.signal), bound.signal);
|
|
250
|
+
const first = await held;
|
|
251
|
+
return isAborted(first) ? await (run.begun ?? Promise.resolve(late())) : first;
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
bound.dispose();
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
// As every turn: the next waits for the work itself too, not only for the lock's promise (K1),
|
|
258
|
+
// and the work is bound by its own calls (D487).
|
|
259
|
+
tail = turn.then(noop, noop).then(() => run.begun?.then(noop, noop));
|
|
260
|
+
return { turn, run };
|
|
261
|
+
}
|
|
174
262
|
/**
|
|
175
263
|
* One at a time within this session, a refresh or a revocation, each inside the app's lock when
|
|
176
264
|
* there is one, so a revocation never sends a token a refresh is spending, nor a refresh one a
|
|
@@ -219,30 +307,75 @@ export function createSession(options) {
|
|
|
219
307
|
// RFC 7009 on the tokens as they are once no refresh is spending them. pulse-auth answers 200
|
|
220
308
|
// whatever it is sent, a spent refresh token or an access token that has run out included, and
|
|
221
309
|
// revokes nothing for those: so the answer is checked against the server, never taken on trust.
|
|
222
|
-
|
|
223
|
-
|
|
310
|
+
/**
|
|
311
|
+
* A sign-out's turn (#134): the revocation, then the store's clear, in one hold of the app's lock,
|
|
312
|
+
* so nothing can rotate the session in between. The turn's one read of the store serves both:
|
|
313
|
+
* the revocation waits for it only within its 10 s, the clear for as long as it takes. The
|
|
314
|
+
* revocation's result goes to `answer` as soon as it's known. The clear runs whatever the
|
|
315
|
+
* revocation did: in time or too late to send anything, aborted (D478), failed, or with any
|
|
316
|
+
* result.
|
|
317
|
+
*/
|
|
318
|
+
async function signOut(limit, answer) {
|
|
319
|
+
const reading = waitedAtMost(read());
|
|
320
|
+
// Whatever the revocation half does, throwing included, the clear below still runs (rev140's
|
|
321
|
+
// P3.2): a throw is the revocation's own failure, outside the contract.
|
|
322
|
+
const result = await revokeWith(reading, limit).catch((cause) => ({ kind: 'unconfirmed', reason: { kind: 'invalid', issues: `the revocation failed: ${cause instanceof Error ? cause.message : String(cause)}` } }));
|
|
323
|
+
// One sign-out sends the rotations set aside, whatever its result, and lets them go (D500).
|
|
324
|
+
setAside = [];
|
|
325
|
+
answer(result);
|
|
326
|
+
// The session the turn read, while the store still holds it: a sign-in saved since is kept.
|
|
327
|
+
const now = await reading;
|
|
328
|
+
if (!isAborted(now) && now.ok)
|
|
329
|
+
await clearIfStill(keyOf(now.tokens));
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
/** A store call, given up on after 60 s (D487): the turn then touches nothing more. */
|
|
333
|
+
function waitedAtMost(call) {
|
|
334
|
+
const bound = createLimit(SIGN_OUT_WAIT_MS, undefined);
|
|
335
|
+
return orAborted(call, bound.signal).finally(bound.dispose);
|
|
336
|
+
}
|
|
337
|
+
async function revokeWith(reading, limit) {
|
|
338
|
+
// A turn that came after the 10 s, by the timer or the clock: nothing is sent.
|
|
339
|
+
if (limit.ended() !== null)
|
|
224
340
|
return limit.unconfirmed();
|
|
225
|
-
const now = await orAborted(
|
|
226
|
-
if (
|
|
341
|
+
const now = await orAborted(reading, limit.signal);
|
|
342
|
+
if (isAborted(now))
|
|
227
343
|
return limit.unconfirmed();
|
|
228
344
|
if (!now.ok)
|
|
229
345
|
return { kind: 'unconfirmed', reason: now.failure };
|
|
230
346
|
const held = now.tokens;
|
|
347
|
+
// Sets aside an unsaved rotation the store has moved on from, sent below (D500).
|
|
231
348
|
const live = liveOf(held);
|
|
232
|
-
|
|
349
|
+
// The stored session, unless there's nothing of it to send: no refresh token, and an access
|
|
350
|
+
// token that has run out, which ends nothing at pulse-auth.
|
|
351
|
+
const stored = held !== null && (live !== undefined || unexpired(held)) ? held : null;
|
|
352
|
+
// Nothing to send at all, so the auth host isn't asked (#130).
|
|
353
|
+
if (stored === null && setAside.length === 0)
|
|
233
354
|
return { kind: 'unconfirmed', reason: { kind: 'no_tokens' } };
|
|
355
|
+
const found = await serverFor(limit);
|
|
356
|
+
if (!found.ok)
|
|
357
|
+
return { kind: 'unconfirmed', reason: limit.ended() ?? found.error };
|
|
358
|
+
const server = found.data;
|
|
359
|
+
const endpoint = server.revocationEndpoint;
|
|
360
|
+
if (endpoint === undefined)
|
|
361
|
+
return { kind: 'unconfirmed', reason: { kind: 'no_endpoint' } };
|
|
362
|
+
const result = stored === null ? null : await revokeStored(stored, live, server, endpoint, limit);
|
|
363
|
+
return sendSetAside(endpoint, result, limit);
|
|
364
|
+
}
|
|
365
|
+
/** The stored session's end (D484), checked against the server where it can be (D464). */
|
|
366
|
+
async function revokeStored(held, live, server, endpoint, limit) {
|
|
234
367
|
// D464: a 200 from the issuer just before, then a 401 for the same token just after, is a
|
|
235
368
|
// difference only the revocation explains. A 401 on its own isn't: pulse-auth answers every
|
|
236
369
|
// failure of a token with the same 401 (expired, another audience, an ended session).
|
|
237
370
|
// A known expiry only: a token that could run out between the two checks would revoke nothing,
|
|
238
371
|
// and still be refused after (S6.B1).
|
|
239
372
|
if (held.expiresAt !== undefined && held.expiresAt - Date.now() >= CHECK_MARGIN_MS) {
|
|
240
|
-
const before = await taken(held.accessToken, limit);
|
|
373
|
+
const before = await taken(server, held.accessToken, limit);
|
|
241
374
|
if (before.kind === 'taken') {
|
|
242
375
|
const sent = await revocation(endpoint, held.accessToken, 'access_token', limit);
|
|
243
376
|
if (!sent.ok)
|
|
244
377
|
return { kind: 'unconfirmed', reason: sent.error };
|
|
245
|
-
const after = await taken(held.accessToken, limit);
|
|
378
|
+
const after = await taken(server, held.accessToken, limit);
|
|
246
379
|
if (after.kind === 'taken')
|
|
247
380
|
return { kind: 'unconfirmed', reason: { kind: 'still_live' } };
|
|
248
381
|
if (after.kind === 'failed')
|
|
@@ -256,15 +389,51 @@ export function createSession(options) {
|
|
|
256
389
|
const sent = await revocation(endpoint, live?.token ?? held.accessToken, live === undefined ? 'access_token' : 'refresh_token', limit);
|
|
257
390
|
return { kind: 'unconfirmed', reason: sent.ok ? { kind: 'check_failed', error: before.error } : sent.error };
|
|
258
391
|
}
|
|
259
|
-
// No access token to check with: the live refresh token goes, or, with none,
|
|
260
|
-
// that hasn't run out yet (pulse-auth ends a session by either).
|
|
261
|
-
if (live === undefined && !unexpired(held))
|
|
262
|
-
return { kind: 'unconfirmed', reason: { kind: 'no_tokens' } };
|
|
392
|
+
// No access token to check with: the live refresh token goes, or, with none, the access token.
|
|
263
393
|
const sent = await revocation(endpoint, live?.token ?? held.accessToken, live === undefined ? 'access_token' : 'refresh_token', limit);
|
|
264
394
|
if (!sent.ok)
|
|
265
395
|
return { kind: 'unconfirmed', reason: sent.error };
|
|
266
396
|
return { kind: 'unconfirmed', reason: { kind: live !== undefined && doubtful === live.token ? 'maybe_spent' : 'unconfirmable' } };
|
|
267
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* The rotations set aside, each sent as a refresh token after the stored session, within the
|
|
400
|
+
* same 10 s (D500). pulse-auth answers 200 for any refresh token, so nothing confirms them. A
|
|
401
|
+
* send that fails is the result when the stored session went as well as it can (`revoked` or
|
|
402
|
+
* `unconfirmable`) or there was none; any other result of the stored session stands, `maybe_spent`
|
|
403
|
+
* included, since it says that session may still be live. With nothing stored and every send
|
|
404
|
+
* made, the result is `unconfirmable`, or `maybe_spent` when a token sent is one whose last refresh
|
|
405
|
+
* got no answer, as for the store's own.
|
|
406
|
+
*/
|
|
407
|
+
async function sendSetAside(endpoint, result, limit) {
|
|
408
|
+
let failure = null;
|
|
409
|
+
for (const token of setAside) {
|
|
410
|
+
const sent = await revocation(endpoint, token, 'refresh_token', limit);
|
|
411
|
+
if (!sent.ok)
|
|
412
|
+
failure ??= sent.error;
|
|
413
|
+
}
|
|
414
|
+
const wentWell = result === null || result.kind === 'revoked' || result.reason.kind === 'unconfirmable';
|
|
415
|
+
if (failure !== null && wentWell)
|
|
416
|
+
return { kind: 'unconfirmed', reason: failure };
|
|
417
|
+
if (result !== null)
|
|
418
|
+
return result;
|
|
419
|
+
return { kind: 'unconfirmed', reason: { kind: doubtful !== null && setAside.includes(doubtful) ? 'maybe_spent' : 'unconfirmable' } };
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Clears the store, as C2 does after `invalid_grant`: read again, and `cleared` only while the
|
|
423
|
+
* store's key is still `key`, so a sign-in another process saved meanwhile is kept. Waited out,
|
|
424
|
+
* the read as well as the write, however slow the store (rev140's P2.1): nobody but the queue
|
|
425
|
+
* waits for it. A clear that fails leaves the tokens: the result is about the server, and the next
|
|
426
|
+
* refresh of an ended session clears them (C2).
|
|
427
|
+
*/
|
|
428
|
+
async function clearIfStill(key) {
|
|
429
|
+
if (key === undefined)
|
|
430
|
+
return;
|
|
431
|
+
const now = await waitedAtMost(read());
|
|
432
|
+
if (isAborted(now) || !now.ok || keyOf(now.tokens) !== key)
|
|
433
|
+
return;
|
|
434
|
+
unsaved = null;
|
|
435
|
+
await waitedAtMost(Promise.resolve().then(() => options.onTokens({ kind: 'cleared', replaces: key }))).catch(noop);
|
|
436
|
+
}
|
|
268
437
|
function revocation(endpoint, token, hint, limit) {
|
|
269
438
|
// Nothing is sent once the turn's 10 s are up, not even with no time left (S6.F1).
|
|
270
439
|
const ended = limit.ended();
|
|
@@ -288,8 +457,8 @@ export function createSession(options) {
|
|
|
288
457
|
* scope, and answers every refusal with the same 401, an ended session or an expired token alike.
|
|
289
458
|
* Resource servers trust the signature alone, so only the issuer can say.
|
|
290
459
|
*/
|
|
291
|
-
async function taken(accessToken, limit) {
|
|
292
|
-
const found = await userinfoEndpoint(limit);
|
|
460
|
+
async function taken(server, accessToken, limit) {
|
|
461
|
+
const found = await userinfoEndpoint(server, limit);
|
|
293
462
|
if (!found.ok)
|
|
294
463
|
return { kind: 'failed', error: found.error };
|
|
295
464
|
const ended = limit.ended();
|
|
@@ -311,11 +480,12 @@ export function createSession(options) {
|
|
|
311
480
|
/**
|
|
312
481
|
* pulse-auth names its userinfo endpoint only in its OpenID configuration (OIDC Discovery §4),
|
|
313
482
|
* not in the RFC 8414 metadata `discover` reads: so it is read there, once, and held to what
|
|
314
|
-
* discovery holds an endpoint to: the same issuer, https
|
|
483
|
+
* discovery holds an endpoint to: the same issuer, https (or with `allowLocalhostHttp`, http on
|
|
484
|
+
* this machine), and here the issuer's own origin. Once
|
|
315
485
|
* pulse-auth names it in its RFC 8414 metadata too (flipstream-io/pulse-auth#83), read it there
|
|
316
486
|
* first.
|
|
317
487
|
*/
|
|
318
|
-
async function userinfoEndpoint(limit) {
|
|
488
|
+
async function userinfoEndpoint(server, limit) {
|
|
319
489
|
if (userinfo !== null)
|
|
320
490
|
return { ok: true, data: userinfo };
|
|
321
491
|
const ended = limit.ended();
|
|
@@ -335,7 +505,7 @@ export function createSession(options) {
|
|
|
335
505
|
const { issuer, userinfo_endpoint: found } = read.data;
|
|
336
506
|
if (issuer !== server.issuer)
|
|
337
507
|
return { ok: false, error: { kind: 'invalid', issues: 'the OpenID configuration names another issuer', status: 200 } };
|
|
338
|
-
if (found === undefined || !
|
|
508
|
+
if (found === undefined || !isSignInUrl(found, options.allowLocalhostHttp) || new URL(found).origin !== new URL(server.issuer).origin) {
|
|
339
509
|
return { ok: false, error: { kind: 'invalid', issues: 'the OpenID configuration names no userinfo endpoint on the issuer', status: 200 } };
|
|
340
510
|
}
|
|
341
511
|
userinfo = found;
|
|
@@ -343,28 +513,67 @@ export function createSession(options) {
|
|
|
343
513
|
}
|
|
344
514
|
return {
|
|
345
515
|
async token(ask = {}) {
|
|
346
|
-
const
|
|
516
|
+
const asked = acquire(ask);
|
|
517
|
+
asking.add(asked);
|
|
518
|
+
const done = () => {
|
|
519
|
+
asking.delete(asked);
|
|
520
|
+
};
|
|
521
|
+
asked.then(done, done);
|
|
522
|
+
const outcome = await within(asked, WAIT_MS);
|
|
347
523
|
if (outcome.kind === 'token')
|
|
348
524
|
return outcome.accessToken;
|
|
349
525
|
throw new SessionError(outcome);
|
|
350
526
|
},
|
|
351
|
-
|
|
352
|
-
const endpoint = server.revocationEndpoint;
|
|
353
|
-
if (endpoint === undefined)
|
|
354
|
-
return { kind: 'unconfirmed', reason: { kind: 'no_endpoint' } };
|
|
527
|
+
revoke(revokeOptions = {}) {
|
|
355
528
|
const limit = createLimit(REVOKE_DEADLINE_MS, revokeOptions.signal);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return await serial(() => revokeNow(endpoint, limit), limit, limit.unconfirmed, lockFailed);
|
|
359
|
-
}
|
|
360
|
-
finally {
|
|
529
|
+
// A sign-out asked with a signal that has already fired does nothing at all.
|
|
530
|
+
if (limit.signal.aborted) {
|
|
361
531
|
limit.dispose();
|
|
532
|
+
return Promise.resolve(limit.unconfirmed());
|
|
533
|
+
}
|
|
534
|
+
let answer = noop;
|
|
535
|
+
const answered = new Promise((resolve) => (answer = resolve));
|
|
536
|
+
// Queued now, before anything is awaited, so neither an abort nor a stalled read can keep the
|
|
537
|
+
// turn from coming, and a refresh asked after the sign-out comes after it (K1).
|
|
538
|
+
const { turn, run } = enqueueSignOut(() => signOut(limit, answer), limit.unconfirmed);
|
|
539
|
+
return new Promise((resolve) => {
|
|
540
|
+
// The revocation's result, once the clear is done, so a token() just after finds the store
|
|
541
|
+
// cleared; but never past the 10 s, so a clear that stalls holds the queue, not the caller.
|
|
542
|
+
answered.then(async (result) => {
|
|
543
|
+
await orAborted(turn.then(noop, noop), limit.signal);
|
|
544
|
+
resolve(result);
|
|
545
|
+
}, noop);
|
|
546
|
+
// At the 10 s, a turn that hasn't begun is `timeout` (or `aborted`); one that has begun
|
|
547
|
+
// answers soon, every step of it being bound to the same 10 s. A lock that fails after the
|
|
548
|
+
// work began leaves the work's own result standing (rev140's P3.1).
|
|
549
|
+
void orAborted(turn, limit.signal).then((first) => {
|
|
550
|
+
if (isAborted(first) && run.begun === undefined)
|
|
551
|
+
resolve(limit.unconfirmed());
|
|
552
|
+
}, (cause) => {
|
|
553
|
+
if (run.begun === undefined)
|
|
554
|
+
resolve({ kind: 'unconfirmed', reason: { kind: 'store_failed', step: 'lock', cause } });
|
|
555
|
+
// A turn whose own work failed, without an answer: the caller still gets one (K6), not
|
|
556
|
+
// a wait for an answer that won't come (rev140's round-3 P3.5).
|
|
557
|
+
else
|
|
558
|
+
void run.begun.catch((failed) => resolve({ kind: 'unconfirmed', reason: { kind: 'invalid', issues: `the sign-out failed: ${failed instanceof Error ? failed.message : String(failed)}` } }));
|
|
559
|
+
});
|
|
560
|
+
}).finally(limit.dispose);
|
|
561
|
+
},
|
|
562
|
+
async settled() {
|
|
563
|
+
// Until nothing new came while it waited: work queued meanwhile is waited for too.
|
|
564
|
+
for (;;) {
|
|
565
|
+
const queued = tail;
|
|
566
|
+
await Promise.all([queued, ...asking].map((work) => work.then(noop, noop)));
|
|
567
|
+
if (tail === queued && asking.size === 0)
|
|
568
|
+
return;
|
|
362
569
|
}
|
|
363
570
|
},
|
|
364
571
|
};
|
|
365
572
|
}
|
|
366
573
|
const fresh = (held) => held.expiresAt === undefined || held.expiresAt - Date.now() > MARGIN_MS;
|
|
367
574
|
const unexpired = (held) => held.expiresAt === undefined || held.expiresAt > Date.now();
|
|
575
|
+
/** What a store compares on (D472): its refresh token, or its access token when it has none (`||`). */
|
|
576
|
+
const keyOf = (held) => (held === null ? undefined : held.refreshToken || held.accessToken);
|
|
368
577
|
/**
|
|
369
578
|
* A refresh the server may have carried out without the session learning of it: no answer, past
|
|
370
579
|
* the deadline, a server error, or a success it couldn't read. A 4xx answer, or a request never
|
|
@@ -450,6 +659,10 @@ function updateOf(answer, replaces, sentAt) {
|
|
|
450
659
|
? { kind: 'rotated', accessToken: answer.access_token, refreshToken: answer.refresh_token, ...expiry, replaces }
|
|
451
660
|
: { kind: 'access-only', accessToken: answer.access_token, ...expiry, replaces };
|
|
452
661
|
}
|
|
662
|
+
/** A discovery that failed in a refresh's turn: no answer is `unavailable`; anything else, a refresh that failed. */
|
|
663
|
+
function discoveryFailure(error) {
|
|
664
|
+
return error.kind === 'unavailable' || error.kind === 'timeout' || error.kind === 'aborted' ? UNAVAILABLE : { kind: 'refresh_failed', error };
|
|
665
|
+
}
|
|
453
666
|
function failureOf(error) {
|
|
454
667
|
switch (error.kind) {
|
|
455
668
|
case 'unavailable':
|