@idp.global/sdk 19.3.0 → 19.5.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 +66 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts_browser/classes.idpclient.js +1 -1
- package/dist_ts_browser/classes.idprequests.js +1 -1
- package/dist_ts_browser/classes.relyingpartybearerclient.d.ts +313 -0
- package/dist_ts_browser/classes.relyingpartybearerclient.js +646 -0
- package/dist_ts_browser/index.d.ts +1 -0
- package/dist_ts_browser/index.js +2 -1
- package/dist_ts_browser/plugins.js +1 -1
- package/dist_ts_browser/secret-delivery.js +1 -1
- package/dist_ts_relyingparty/classes.authorityobserver.d.ts +23 -0
- package/dist_ts_relyingparty/classes.authorityobserver.js +68 -13
- package/dist_ts_relyingparty/classes.errors.d.ts +5 -1
- package/dist_ts_relyingparty/classes.errors.js +3 -1
- package/dist_ts_relyingparty/classes.relyingpartyroutes.d.ts +12 -0
- package/dist_ts_relyingparty/classes.relyingpartyroutes.js +33 -6
- package/dist_ts_relyingparty/classes.relyingpartysessions.d.ts +161 -11
- package/dist_ts_relyingparty/classes.relyingpartysessions.js +381 -55
- package/dist_ts_relyingparty/classes.rpmodels.d.ts +6 -4
- package/dist_ts_relyingparty/classes.rpmodels.js +8 -6
- package/dist_ts_relyingparty/contract.bearer.d.ts +119 -0
- package/dist_ts_relyingparty/contract.bearer.js +13 -0
- package/dist_ts_relyingparty/helpers.bearer.d.ts +3 -4
- package/dist_ts_relyingparty/helpers.bearer.js +4 -6
- package/dist_ts_relyingparty/interfaces.d.ts +75 -26
- package/package.json +2 -1
- package/readme.md +363 -21
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts_browser/classes.relyingpartybearerclient.ts +901 -0
- package/ts_browser/index.ts +1 -0
- package/ts_relyingparty/classes.authorityobserver.ts +80 -12
- package/ts_relyingparty/classes.errors.ts +7 -1
- package/ts_relyingparty/classes.relyingpartyroutes.ts +38 -7
- package/ts_relyingparty/classes.relyingpartysessions.ts +463 -65
- package/ts_relyingparty/classes.rpmodels.ts +7 -4
- package/ts_relyingparty/contract.bearer.ts +145 -0
- package/ts_relyingparty/helpers.bearer.ts +10 -14
- package/ts_relyingparty/interfaces.ts +93 -33
|
@@ -3,10 +3,11 @@ import { RelyingPartyDatabaseUnavailableError } from './classes.errors.js';
|
|
|
3
3
|
import type { TRelyingPartyBearerClientKind } from './interfaces.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* One browser session of a relying party. The persisted field names
|
|
7
|
-
* types
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* One browser session of a relying party. The persisted field names and their
|
|
7
|
+
* types are the ones nevermind.finance has stored under `SessionDoc` since
|
|
8
|
+
* before this module existed, so its collection is read and written
|
|
9
|
+
* unchanged; its indexes are those and the `expiresAt` index the sweep of
|
|
10
|
+
* ended sessions reads.
|
|
10
11
|
*/
|
|
11
12
|
export class RelyingPartySessionDoc extends plugins.nosqldb.SmartDataDbDoc<RelyingPartySessionDoc, RelyingPartySessionDoc> {
|
|
12
13
|
@plugins.nosqldb.unI()
|
|
@@ -27,7 +28,9 @@ export class RelyingPartySessionDoc extends plugins.nosqldb.SmartDataDbDoc<Relyi
|
|
|
27
28
|
@plugins.nosqldb.svDb()
|
|
28
29
|
public lastSeenAt: number = 0;
|
|
29
30
|
|
|
31
|
+
/** a revocation lowers it to `revokedAt` when that is earlier, so the sweep finds every ended session by it */
|
|
30
32
|
@plugins.nosqldb.svDb()
|
|
33
|
+
@plugins.nosqldb.index()
|
|
31
34
|
public expiresAt: number = 0;
|
|
32
35
|
|
|
33
36
|
/** absent while the session is valid */
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract of the bearer hand-off routes: what a bearer client sends
|
|
3
|
+
* and what it is answered. This module imports nothing, so the browser client
|
|
4
|
+
* (`@idp.global/sdk/browser`) shares it with the routes without reaching any
|
|
5
|
+
* server code; keep it that way.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The `type` of every message a popup delivery posts. */
|
|
9
|
+
export const RELYING_PARTY_BEARER_MESSAGE_TYPE = 'idp.global/relyingparty:bearer-handoff';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* How a bearer client receives the outcome of its login:
|
|
13
|
+
*
|
|
14
|
+
* - `web`: a redirect to a same-origin path of the application
|
|
15
|
+
* - `loopback`: a redirect to `http://127.0.0.1:<port>/…` or `http://[::1]:<port>/…`, any port (RFC 8252)
|
|
16
|
+
* - `custom_scheme`: a redirect to a registered private-use URI scheme such as `com.example.app:/signed-in` (RFC 8252)
|
|
17
|
+
* - `popup`: a page that posts the outcome to `window.opener` at exactly one registered origin
|
|
18
|
+
*/
|
|
19
|
+
export type TRelyingPartyBearerClientKind = 'web' | 'loopback' | 'custom_scheme' | 'popup';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* What the popup page of a `popup` delivery posts to `window.opener`. The
|
|
23
|
+
* receiver accepts it only when `event.origin` is the relying party's public
|
|
24
|
+
* origin, `event.source` is the popup it opened, `type` is
|
|
25
|
+
* `RELYING_PARTY_BEARER_MESSAGE_TYPE` and `state` is its own.
|
|
26
|
+
*/
|
|
27
|
+
export interface IRelyingPartyBearerMessage {
|
|
28
|
+
type: string;
|
|
29
|
+
/** the hand-off code; absent when the login failed */
|
|
30
|
+
code?: string;
|
|
31
|
+
/** why the login failed (`TRelyingPartyBearerDeliveryError`); absent when it succeeded */
|
|
32
|
+
error?: string;
|
|
33
|
+
state?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Why a bearer login delivered no code, as the `error` of its redirect or
|
|
38
|
+
* popup message: `access_denied` when the provider came back without one,
|
|
39
|
+
* `authentication_failed` when the login could not be completed, or the code
|
|
40
|
+
* of the application's own refusal (`RelyingPartyRefusal.code`).
|
|
41
|
+
*/
|
|
42
|
+
export type TRelyingPartyBearerDeliveryError = 'access_denied' | 'authentication_failed' | (string & {});
|
|
43
|
+
|
|
44
|
+
/** RFC 7636 §4.1: a code verifier is 43 to 128 characters of `A-Z a-z 0-9 . _ ~ -`. */
|
|
45
|
+
const PKCE_VERIFIER = /^[A-Za-z0-9._~-]{43,128}$/u;
|
|
46
|
+
|
|
47
|
+
/** Whether a value is a well-formed PKCE code verifier (RFC 7636 §4.1). */
|
|
48
|
+
export const isPkceVerifier = (valueArg: unknown): valueArg is string =>
|
|
49
|
+
typeof valueArg === 'string' && PKCE_VERIFIER.test(valueArg);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The query of `GET <prefix>bearer/login`, by its parameter names on the
|
|
53
|
+
* wire. The routes check every parameter as untrusted input.
|
|
54
|
+
*/
|
|
55
|
+
export interface IRelyingPartyBearerLoginQuery {
|
|
56
|
+
client_kind: TRelyingPartyBearerClientKind;
|
|
57
|
+
/** one of the configured return targets of the kind, exactly; a loopback target with the client's port */
|
|
58
|
+
return_target: string;
|
|
59
|
+
/** BASE64URL(SHA-256(code verifier)), 43 characters */
|
|
60
|
+
code_challenge: string;
|
|
61
|
+
/** only `S256` is accepted */
|
|
62
|
+
code_challenge_method: 'S256';
|
|
63
|
+
/** the client's own correlation value, 1 to 256 characters of `A-Z a-z 0-9 . _ ~ -`, handed back with the outcome */
|
|
64
|
+
state?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The JSON body of `POST <prefix>bearer/claim`. */
|
|
68
|
+
export interface IRelyingPartyBearerClaimRequest {
|
|
69
|
+
/** the hand-off code, claimed once */
|
|
70
|
+
code: string;
|
|
71
|
+
/** the verifier of the challenge the code is bound to (`isPkceVerifier`) */
|
|
72
|
+
codeVerifier: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The JSON body of `POST <prefix>bearer/refresh`. */
|
|
76
|
+
export interface IRelyingPartyBearerRefreshRequest {
|
|
77
|
+
/** the current refresh token; this call spends it */
|
|
78
|
+
refreshToken: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The JSON body of `POST <prefix>bearer/logout`. The session is named by
|
|
83
|
+
* `Authorization: Bearer <accessToken>`, or by `refreshToken` once that access
|
|
84
|
+
* token has expired.
|
|
85
|
+
*/
|
|
86
|
+
export interface IRelyingPartyBearerLogoutRequest {
|
|
87
|
+
refreshToken?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The session a bearer answer names. */
|
|
91
|
+
export interface IRelyingPartyBearerSessionInfo {
|
|
92
|
+
sessionId: string;
|
|
93
|
+
principalId: string;
|
|
94
|
+
/** epoch milliseconds: the end of the session, which no refresh extends */
|
|
95
|
+
expiresAt: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** What `POST <prefix>bearer/claim` and `POST <prefix>bearer/refresh` answer with status 200. */
|
|
99
|
+
export interface IRelyingPartyBearerTokenAnswer {
|
|
100
|
+
tokenType: 'Bearer';
|
|
101
|
+
accessToken: string;
|
|
102
|
+
/** epoch milliseconds on the relying party's clock */
|
|
103
|
+
accessTokenExpiresAt: number;
|
|
104
|
+
/** seconds the access token lives from the answer, for a client whose clock differs */
|
|
105
|
+
expiresIn: number;
|
|
106
|
+
/** spent by the next refresh; it never comes back after that */
|
|
107
|
+
refreshToken: string;
|
|
108
|
+
/** epoch milliseconds: the end of the session */
|
|
109
|
+
refreshTokenExpiresAt: number;
|
|
110
|
+
session: IRelyingPartyBearerSessionInfo;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** What `GET <prefix>bearer/session` answers with status 200; `null` for any token that is not live. */
|
|
114
|
+
export interface IRelyingPartyBearerSessionAnswer {
|
|
115
|
+
session: IRelyingPartyBearerSessionInfo | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** What `POST <prefix>bearer/logout` answers with status 200; `true` only when this call ended a live session. */
|
|
119
|
+
export interface IRelyingPartyBearerLogoutAnswer {
|
|
120
|
+
endedLiveSession: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The `error` of a failed bearer route, answered as `{ error }`:
|
|
125
|
+
*
|
|
126
|
+
* - `invalid_bearer_request` (400): a login start or claim with a missing or malformed parameter
|
|
127
|
+
* - `return_target_not_allowed` (400): a login start naming a return target not configured for its kind
|
|
128
|
+
* - `invalid_bearer_handoff` (400): a claim with a code that is unknown, expired, already claimed or of the wrong verifier
|
|
129
|
+
* - `invalid_bearer_grant` (400): a refresh token that is unknown, spent, expired or of a session that is over
|
|
130
|
+
* - `authority_unavailable` (503): a refresh that could not reach the provider; nothing was spent, retry it
|
|
131
|
+
* - `authentication_unavailable` (503): any other failure on the relying party's side
|
|
132
|
+
* - `forbidden` (403): a CORS preflight from an origin that is no popup return target
|
|
133
|
+
*/
|
|
134
|
+
export type TRelyingPartyBearerErrorCode =
|
|
135
|
+
| 'invalid_bearer_request'
|
|
136
|
+
| 'return_target_not_allowed'
|
|
137
|
+
| 'invalid_bearer_handoff'
|
|
138
|
+
| 'invalid_bearer_grant'
|
|
139
|
+
| 'authority_unavailable'
|
|
140
|
+
| 'authentication_unavailable'
|
|
141
|
+
| 'forbidden';
|
|
142
|
+
|
|
143
|
+
export interface IRelyingPartyBearerErrorAnswer {
|
|
144
|
+
error: TRelyingPartyBearerErrorCode;
|
|
145
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPkceVerifier,
|
|
3
|
+
RELYING_PARTY_BEARER_MESSAGE_TYPE,
|
|
4
|
+
type IRelyingPartyBearerMessage,
|
|
5
|
+
type TRelyingPartyBearerClientKind,
|
|
6
|
+
} from './contract.bearer.js';
|
|
1
7
|
import { sha256, timingSafeEqualString } from './helpers.crypto.js';
|
|
2
8
|
import { sanitizeReturnPath } from './helpers.returnpath.js';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
TRelyingPartyBearerClientKind,
|
|
8
|
-
} from './interfaces.js';
|
|
9
|
+
import type { IRelyingPartyBearerDelivery, IRelyingPartyBearerReturnTargets } from './interfaces.js';
|
|
10
|
+
|
|
11
|
+
// the verifier check lives in the import-free contract, which the browser client shares
|
|
12
|
+
export { isPkceVerifier, RELYING_PARTY_BEARER_MESSAGE_TYPE };
|
|
9
13
|
|
|
10
14
|
export const RELYING_PARTY_BEARER_CLIENT_KINDS: readonly TRelyingPartyBearerClientKind[] = Object.freeze([
|
|
11
15
|
'web',
|
|
@@ -14,15 +18,10 @@ export const RELYING_PARTY_BEARER_CLIENT_KINDS: readonly TRelyingPartyBearerClie
|
|
|
14
18
|
'popup',
|
|
15
19
|
]);
|
|
16
20
|
|
|
17
|
-
/** The `type` of every message a popup delivery posts. */
|
|
18
|
-
export const RELYING_PARTY_BEARER_MESSAGE_TYPE = 'idp.global/relyingparty:bearer-handoff';
|
|
19
|
-
|
|
20
21
|
/** A return target is a location the application configured, not a place to park data. */
|
|
21
22
|
const MAX_RETURN_TARGET_LENGTH = 2_048;
|
|
22
23
|
/** BASE64URL of a SHA-256 digest, without padding (RFC 7636 §4.2). */
|
|
23
24
|
const PKCE_CHALLENGE = /^[A-Za-z0-9_-]{43}$/u;
|
|
24
|
-
/** RFC 7636 §4.1: 43 to 128 unreserved characters. */
|
|
25
|
-
const PKCE_VERIFIER = /^[A-Za-z0-9._~-]{43,128}$/u;
|
|
26
25
|
const CLIENT_STATE = /^[A-Za-z0-9._~-]{1,256}$/u;
|
|
27
26
|
const LOOPBACK_HOSTS: readonly string[] = ['127.0.0.1', '[::1]'];
|
|
28
27
|
/** A private-use scheme is a reverse domain name: it has a dot, and no web scheme has one (RFC 8252 §7.1). */
|
|
@@ -34,9 +33,6 @@ export const isBearerClientKind = (valueArg: unknown): valueArg is TRelyingParty
|
|
|
34
33
|
export const isPkceChallenge = (valueArg: unknown): valueArg is string =>
|
|
35
34
|
typeof valueArg === 'string' && PKCE_CHALLENGE.test(valueArg);
|
|
36
35
|
|
|
37
|
-
export const isPkceVerifier = (valueArg: unknown): valueArg is string =>
|
|
38
|
-
typeof valueArg === 'string' && PKCE_VERIFIER.test(valueArg);
|
|
39
|
-
|
|
40
36
|
export const isBearerClientState = (valueArg: unknown): valueArg is string =>
|
|
41
37
|
typeof valueArg === 'string' && CLIENT_STATE.test(valueArg);
|
|
42
38
|
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import type { IOidcCompletion, TOidcCompletionFailureStage, TOidcPrompt, TOidcTokenHint } from './classes.idpoidcprovider.js';
|
|
2
|
+
import type { TRelyingPartyBearerClientKind } from './contract.bearer.js';
|
|
3
|
+
|
|
4
|
+
export type {
|
|
5
|
+
IRelyingPartyBearerClaimRequest,
|
|
6
|
+
IRelyingPartyBearerErrorAnswer,
|
|
7
|
+
IRelyingPartyBearerLoginQuery,
|
|
8
|
+
IRelyingPartyBearerLogoutAnswer,
|
|
9
|
+
IRelyingPartyBearerLogoutRequest,
|
|
10
|
+
IRelyingPartyBearerMessage,
|
|
11
|
+
IRelyingPartyBearerRefreshRequest,
|
|
12
|
+
IRelyingPartyBearerSessionAnswer,
|
|
13
|
+
IRelyingPartyBearerSessionInfo,
|
|
14
|
+
IRelyingPartyBearerTokenAnswer,
|
|
15
|
+
TRelyingPartyBearerClientKind,
|
|
16
|
+
TRelyingPartyBearerDeliveryError,
|
|
17
|
+
TRelyingPartyBearerErrorCode,
|
|
18
|
+
} from './contract.bearer.js';
|
|
2
19
|
|
|
3
20
|
/** A session as the application reads it; no token and no sealed value is part of it. */
|
|
4
21
|
export interface IRelyingPartySession {
|
|
@@ -35,6 +52,21 @@ export interface IRelyingPartySessionOpening {
|
|
|
35
52
|
sessionCookie: string;
|
|
36
53
|
}
|
|
37
54
|
|
|
55
|
+
/** What `sessionsOfPrincipal` reads: how many sessions, and after which page. */
|
|
56
|
+
export interface IRelyingPartySessionsPageOptions {
|
|
57
|
+
/** 1 to `RELYING_PARTY_MAX_SESSIONS_PAGE_LIMIT`; `RELYING_PARTY_DEFAULT_SESSIONS_PAGE_LIMIT` when absent */
|
|
58
|
+
limit?: number;
|
|
59
|
+
/** the `nextCursor` of the page before; absent for the first page */
|
|
60
|
+
cursor?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One page of a principal's live sessions, newest first. */
|
|
64
|
+
export interface IRelyingPartySessionsPage {
|
|
65
|
+
sessions: IRelyingPartySession[];
|
|
66
|
+
/** opaque; reads the next page as `cursor`. Absent on the last page. */
|
|
67
|
+
nextCursor?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
38
70
|
/**
|
|
39
71
|
* What `startLogin` carries besides the return path. `intent` is the
|
|
40
72
|
* application's own text — the invitation a login accepts, the account it
|
|
@@ -62,16 +94,6 @@ export interface IRelyingPartyLoginStart {
|
|
|
62
94
|
intentCookie: string;
|
|
63
95
|
}
|
|
64
96
|
|
|
65
|
-
/**
|
|
66
|
-
* How a bearer client receives the outcome of its login:
|
|
67
|
-
*
|
|
68
|
-
* - `web`: a redirect to a same-origin path of the application
|
|
69
|
-
* - `loopback`: a redirect to `http://127.0.0.1:<port>/…` or `http://[::1]:<port>/…`, any port (RFC 8252)
|
|
70
|
-
* - `custom_scheme`: a redirect to a registered private-use URI scheme such as `com.example.app:/signed-in` (RFC 8252)
|
|
71
|
-
* - `popup`: a page that posts the outcome to `window.opener` at exactly one registered origin
|
|
72
|
-
*/
|
|
73
|
-
export type TRelyingPartyBearerClientKind = 'web' | 'loopback' | 'custom_scheme' | 'popup';
|
|
74
|
-
|
|
75
97
|
/**
|
|
76
98
|
* The exact return targets a bearer client may name, per client kind. A kind
|
|
77
99
|
* without targets is not offered. Matching is by equality, never by prefix
|
|
@@ -138,6 +160,37 @@ export interface IRelyingPartyBearerHandoff {
|
|
|
138
160
|
expiresAt: number;
|
|
139
161
|
}
|
|
140
162
|
|
|
163
|
+
/**
|
|
164
|
+
* A bearer session the application opened for a device it paired
|
|
165
|
+
* (`openBearerHandoff`): the session, which has no provider login of its own
|
|
166
|
+
* (`idpSubject` and `loginAttemptId` are absent), and the single-use code the
|
|
167
|
+
* device claims at `bearer/claim` with the verifier of its challenge. The
|
|
168
|
+
* code is no token; only its hash is stored.
|
|
169
|
+
*/
|
|
170
|
+
export interface IRelyingPartyBearerHandoffOpening {
|
|
171
|
+
session: IRelyingPartySession;
|
|
172
|
+
code: string;
|
|
173
|
+
/** epoch milliseconds, at most `BEARER_HANDOFF_MAX_AGE_SECONDS` after the opening and never past the session */
|
|
174
|
+
expiresAt: number;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* What `eraseSessionsOfPrincipal` removed of one principal: the sessions it
|
|
179
|
+
* ended first, and the rows it deleted.
|
|
180
|
+
*/
|
|
181
|
+
export interface IRelyingPartySessionsErasure {
|
|
182
|
+
/** sessions not revoked yet (an expired one too) that it ended, each with `onSessionEnded` and its provider tokens handed back */
|
|
183
|
+
endedSessions: number;
|
|
184
|
+
/** session rows, live or ended */
|
|
185
|
+
deletedSessions: number;
|
|
186
|
+
/** the sign-in transactions the provider sessions came out of */
|
|
187
|
+
deletedLoginAttempts: number;
|
|
188
|
+
/** bearer hand-offs, claimed or not */
|
|
189
|
+
deletedBearerHandoffs: number;
|
|
190
|
+
/** bearer token generations, current or rotated */
|
|
191
|
+
deletedBearerTokens: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
141
194
|
/**
|
|
142
195
|
* The relying party's own tokens of a bearer session. The refresh token
|
|
143
196
|
* rotates on every use; a rotated one coming back ends the session.
|
|
@@ -154,27 +207,17 @@ export interface IRelyingPartyBearerTokens {
|
|
|
154
207
|
refreshTokenExpiresAt: number;
|
|
155
208
|
}
|
|
156
209
|
|
|
157
|
-
/**
|
|
158
|
-
* What the popup page of a `popup` delivery posts to `window.opener`. The
|
|
159
|
-
* receiver accepts it only when `event.origin` is the relying party's public
|
|
160
|
-
* origin, `event.source` is the popup it opened, `type` is
|
|
161
|
-
* `RELYING_PARTY_BEARER_MESSAGE_TYPE` and `state` is its own.
|
|
162
|
-
*/
|
|
163
|
-
export interface IRelyingPartyBearerMessage {
|
|
164
|
-
type: string;
|
|
165
|
-
/** the hand-off code; absent when the login failed */
|
|
166
|
-
code?: string;
|
|
167
|
-
/** why the login failed; absent when it succeeded */
|
|
168
|
-
error?: string;
|
|
169
|
-
state?: string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
210
|
/** A provider access token usable right now, with the subject it belongs to. */
|
|
173
211
|
export interface IProviderToken {
|
|
174
212
|
accessToken: string;
|
|
175
213
|
subject: string;
|
|
176
214
|
/** epoch milliseconds; `0` when the provider named no lifetime */
|
|
177
215
|
expiresAt: number;
|
|
216
|
+
/**
|
|
217
|
+
* `true` only on the answer to `rejectedAccessToken`, and only when a
|
|
218
|
+
* rotation that this call started issued the token.
|
|
219
|
+
*/
|
|
220
|
+
rotatedAfterRejection?: boolean;
|
|
178
221
|
}
|
|
179
222
|
|
|
180
223
|
/** What an authority observer needs from the session owner. `RelyingPartySessions` implements it. */
|
|
@@ -182,8 +225,21 @@ export interface IAuthorityTokenSource {
|
|
|
182
225
|
/**
|
|
183
226
|
* The access token of a login session, rotated first when it is due. The
|
|
184
227
|
* session must belong to `expectedPrincipalIdArg`. Throws `AuthorityTokenError`.
|
|
228
|
+
*
|
|
229
|
+
* `rejectedAccessToken` is a token idp.global answered inactive for. The
|
|
230
|
+
* source must rotate the session's token then, whatever is stored, and set
|
|
231
|
+
* `rotatedAfterRejection` only when a rotation that this call started issued
|
|
232
|
+
* the token. A refused refresh ends the session and throws
|
|
233
|
+
* `authority_login_required`. A rotation that started before the call, one
|
|
234
|
+
* another replica holds, or a session without a refresh token marks
|
|
235
|
+
* nothing. A source that never rotates or never marks its answer can never
|
|
236
|
+
* refuse: the observer answers `authority_unavailable` (fail-closed).
|
|
185
237
|
*/
|
|
186
|
-
liveProviderToken(
|
|
238
|
+
liveProviderToken(
|
|
239
|
+
sessionIdArg: string,
|
|
240
|
+
expectedPrincipalIdArg: string,
|
|
241
|
+
optionsArg?: { rejectedAccessToken?: string },
|
|
242
|
+
): Promise<IProviderToken>;
|
|
187
243
|
}
|
|
188
244
|
|
|
189
245
|
/**
|
|
@@ -250,6 +306,8 @@ export type TRelyingPartyEventName =
|
|
|
250
306
|
| 'login_attempt_sweep_failed'
|
|
251
307
|
/** expired bearer hand-offs and token generations could not be swept */
|
|
252
308
|
| 'bearer_sweep_failed'
|
|
309
|
+
/** sessions an hour past their end could not be swept */
|
|
310
|
+
| 'session_sweep_failed'
|
|
253
311
|
/** a bearer hand-off code or refresh token came back after its use; `reason` names which, the session ended */
|
|
254
312
|
| 'bearer_credential_reused'
|
|
255
313
|
/** an application hook threw; the step it belonged to ran on regardless */
|
|
@@ -275,20 +333,22 @@ export interface IRelyingPartyHooks {
|
|
|
275
333
|
* A provider login opened a session, linked to its attempt. Runs before the
|
|
276
334
|
* login answers; a throw fails the login: the session is revoked, the
|
|
277
335
|
* provider tokens are handed back and the original error is rethrown.
|
|
336
|
+
* `delivery` is where a bearer login's outcome goes (its client kind, return
|
|
337
|
+
* target and the client's `state`); a cookie login has none.
|
|
278
338
|
*/
|
|
279
|
-
onProviderSessionOpened?(eventArg: { session: IRelyingPartySession }): Promise<void>;
|
|
339
|
+
onProviderSessionOpened?(eventArg: { session: IRelyingPartySession; delivery?: IRelyingPartyBearerDelivery }): Promise<void>;
|
|
280
340
|
/**
|
|
281
341
|
* A session ended, or a caller tried to end one that was already over
|
|
282
342
|
* (`revokedHere: false`). Close its live connections when `revokedHere`,
|
|
283
343
|
* drop cached authority either way. Must not wait. A throw (or a rejected
|
|
284
344
|
* promise) is reported as a `hook_failed` event and never stops the end:
|
|
285
|
-
* the provider tokens go back regardless.
|
|
345
|
+
* the provider tokens go back regardless. An end that revoked the session
|
|
346
|
+
* here names its principal (`principalId`); one that found it over already
|
|
347
|
+
* does not.
|
|
286
348
|
*/
|
|
287
|
-
onSessionEnded?(eventArg:
|
|
288
|
-
sessionId: string;
|
|
289
|
-
reason: TRelyingPartySessionEndReason;
|
|
290
|
-
revokedHere: boolean;
|
|
291
|
-
}): void;
|
|
349
|
+
onSessionEnded?(eventArg:
|
|
350
|
+
| { sessionId: string; reason: TRelyingPartySessionEndReason; revokedHere: true; principalId: string }
|
|
351
|
+
| { sessionId: string; reason: TRelyingPartySessionEndReason; revokedHere: false }): void;
|
|
292
352
|
/**
|
|
293
353
|
* Structured diagnostics; the default writes one JSON line to
|
|
294
354
|
* `console.error`. A throwing sink never interrupts the step that reported:
|