@idp.global/sdk 18.0.1 → 18.1.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.
Files changed (50) hide show
  1. package/changelog.md +17 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts_relyingparty/classes.actorscope.d.ts +23 -0
  4. package/dist_ts_relyingparty/classes.actorscope.js +22 -0
  5. package/dist_ts_relyingparty/classes.authorityobserver.d.ts +81 -0
  6. package/dist_ts_relyingparty/classes.authorityobserver.js +185 -0
  7. package/dist_ts_relyingparty/classes.errors.d.ts +33 -0
  8. package/dist_ts_relyingparty/classes.errors.js +53 -0
  9. package/dist_ts_relyingparty/classes.idpoidcprovider.d.ts +142 -0
  10. package/dist_ts_relyingparty/classes.idpoidcprovider.js +255 -0
  11. package/dist_ts_relyingparty/classes.relyingpartyroutes.d.ts +84 -0
  12. package/dist_ts_relyingparty/classes.relyingpartyroutes.js +232 -0
  13. package/dist_ts_relyingparty/classes.relyingpartysessions.d.ts +210 -0
  14. package/dist_ts_relyingparty/classes.relyingpartysessions.js +786 -0
  15. package/dist_ts_relyingparty/classes.rpmodels.d.ts +79 -0
  16. package/dist_ts_relyingparty/classes.rpmodels.js +283 -0
  17. package/dist_ts_relyingparty/classes.secretbox.d.ts +14 -0
  18. package/dist_ts_relyingparty/classes.secretbox.js +45 -0
  19. package/dist_ts_relyingparty/classes.socketbinding.d.ts +75 -0
  20. package/dist_ts_relyingparty/classes.socketbinding.js +94 -0
  21. package/dist_ts_relyingparty/helpers.cookies.d.ts +11 -0
  22. package/dist_ts_relyingparty/helpers.cookies.js +62 -0
  23. package/dist_ts_relyingparty/helpers.crypto.d.ts +12 -0
  24. package/dist_ts_relyingparty/helpers.crypto.js +40 -0
  25. package/dist_ts_relyingparty/helpers.returnpath.d.ts +9 -0
  26. package/dist_ts_relyingparty/helpers.returnpath.js +39 -0
  27. package/dist_ts_relyingparty/index.d.ts +13 -0
  28. package/dist_ts_relyingparty/index.js +14 -0
  29. package/dist_ts_relyingparty/interfaces.d.ts +113 -0
  30. package/dist_ts_relyingparty/interfaces.js +2 -0
  31. package/dist_ts_relyingparty/plugins.d.ts +10 -0
  32. package/dist_ts_relyingparty/plugins.js +11 -0
  33. package/package.json +13 -10
  34. package/readme.md +158 -4
  35. package/ts/00_commitinfo_data.ts +1 -1
  36. package/ts_relyingparty/classes.actorscope.ts +39 -0
  37. package/ts_relyingparty/classes.authorityobserver.ts +253 -0
  38. package/ts_relyingparty/classes.errors.ts +69 -0
  39. package/ts_relyingparty/classes.idpoidcprovider.ts +386 -0
  40. package/ts_relyingparty/classes.relyingpartyroutes.ts +286 -0
  41. package/ts_relyingparty/classes.relyingpartysessions.ts +970 -0
  42. package/ts_relyingparty/classes.rpmodels.ts +146 -0
  43. package/ts_relyingparty/classes.secretbox.ts +49 -0
  44. package/ts_relyingparty/classes.socketbinding.ts +142 -0
  45. package/ts_relyingparty/helpers.cookies.ts +79 -0
  46. package/ts_relyingparty/helpers.crypto.ts +49 -0
  47. package/ts_relyingparty/helpers.returnpath.ts +44 -0
  48. package/ts_relyingparty/index.ts +13 -0
  49. package/ts_relyingparty/interfaces.ts +133 -0
  50. package/ts_relyingparty/plugins.ts +17 -0
@@ -0,0 +1,210 @@
1
+ import { type IOidcProvider } from './classes.idpoidcprovider.js';
2
+ import type { IRelyingPartyModels } from './classes.rpmodels.js';
3
+ import type { IAuthorityTokenSource, IProviderToken, IRelyingPartyHooks, IRelyingPartyLoginStart, IRelyingPartyPrincipals, IRelyingPartySession, IRelyingPartySessionOpening, IResolvedRelyingPartySession, TRelyingPartySessionEndReason } from './interfaces.js';
4
+ export declare const RELYING_PARTY_DEFAULT_SESSION_MAX_AGE_SECONDS: number;
5
+ export declare const RELYING_PARTY_DEFAULT_LOGIN_PATH_PREFIX = "/auth/";
6
+ /** The label the CSRF HMAC starts with unless the application names its own. */
7
+ export declare const RELYING_PARTY_DEFAULT_CSRF_LABEL: string;
8
+ /** A sign-in transaction has to survive an interactive login at the provider, not a working day. */
9
+ export declare const LOGIN_ATTEMPT_MAX_AGE_SECONDS: number;
10
+ /**
11
+ * How long ending a session waits for the provider to take its tokens back.
12
+ * The local session is already revoked when that call runs.
13
+ */
14
+ export declare const TOKEN_REVOCATION_BUDGET_MS = 3000;
15
+ /** How long before its expiry the provider access token is rotated. */
16
+ export declare const ACCESS_TOKEN_REFRESH_SKEW_MS = 60000;
17
+ /**
18
+ * What the refresh lock adds on top of the provider request it has to cover:
19
+ * the claim and the store around it, and clock disagreement between replicas.
20
+ */
21
+ export declare const REFRESH_LOCK_MARGIN_MS = 20000;
22
+ export interface IRelyingPartySessionsOptions {
23
+ models: IRelyingPartyModels;
24
+ principals: IRelyingPartyPrincipals;
25
+ /** absent: no provider login; sessions are opened by the application only */
26
+ provider?: IOidcProvider;
27
+ /** the application's public origin, e.g. `https://app.example`; cookies are `Secure` exactly on https */
28
+ publicOrigin: string;
29
+ /** 32 bytes; seals the PKCE verifier and the provider tokens at rest */
30
+ sessionEncryptionKey: Buffer;
31
+ /** 32 bytes; the CSRF HMAC key */
32
+ csrfKey: Buffer;
33
+ /** the label the CSRF HMAC starts with; an application with live sessions keeps its own */
34
+ csrfLabel?: string;
35
+ sessionMaxAgeSeconds?: number;
36
+ /**
37
+ * defaults: `__Host-idp_rp_session` / `__Host-idp_rp_intent` on https,
38
+ * without the prefix otherwise. A `__Host-` or `__Secure-` name needs an
39
+ * https origin and is refused on http.
40
+ */
41
+ cookieNames?: {
42
+ session?: string;
43
+ intent?: string;
44
+ };
45
+ /** the prefix of the login routes; a login never returns into it */
46
+ loginPathPrefix?: string;
47
+ hooks?: IRelyingPartyHooks;
48
+ /** the clock every comparison reads; tests step it instead of sleeping */
49
+ now?: () => number;
50
+ }
51
+ /**
52
+ * The relying-party session layer: provider logins through the authorization
53
+ * code flow with PKCE, HttpOnly cookie sessions with a session-bound CSRF
54
+ * token, provider tokens sealed at rest and rotated under a cross-replica
55
+ * lock, and session ends that hand the tokens back.
56
+ *
57
+ * Nothing here runs on a timer: expired login attempts are swept when the next
58
+ * login starts, and the only timer — the revocation budget — is unreferenced
59
+ * and cleared on every path.
60
+ */
61
+ export declare class RelyingPartySessions implements IAuthorityTokenSource {
62
+ #private;
63
+ readonly publicOrigin: string;
64
+ readonly secureCookies: boolean;
65
+ readonly sessionCookieName: string;
66
+ readonly intentCookieName: string;
67
+ readonly loginPathPrefix: string;
68
+ readonly sessionMaxAgeSeconds: number;
69
+ constructor(optionsArg: IRelyingPartySessionsOptions);
70
+ /** Whether provider logins are offered at all. */
71
+ get providerLoginEnabled(): boolean;
72
+ /**
73
+ * How long one replica holds the right to rotate a session's tokens. The
74
+ * provider detects reuse of a superseded refresh token and kills the family,
75
+ * so the lock strictly outlives its longest possible holder: one provider
76
+ * request at its full deadline plus the margin.
77
+ */
78
+ get refreshLockMs(): number;
79
+ /**
80
+ * Opens a session the application authenticated itself (a local password
81
+ * login). It carries no provider tokens.
82
+ */
83
+ openSession(optionsArg: {
84
+ principalId: string;
85
+ }): Promise<IRelyingPartySessionOpening>;
86
+ /** The live session behind the session cookie, or `null`. A read touches it at most once a minute. */
87
+ resolveCookieSession(cookieHeaderArg: string | null | undefined): Promise<IResolvedRelyingPartySession | null>;
88
+ /**
89
+ * Re-checks a session by its id with the same strength as a cookie request:
90
+ * live, its principal active, and touched under the liveness it was read
91
+ * with. What a pinned socket connection runs per request.
92
+ */
93
+ revalidateSession(sessionIdArg: string): Promise<IRelyingPartySession | null>;
94
+ /** Whether a session is live right now, without touching it; what a sweep asks. */
95
+ isSessionLive(sessionIdArg: string): Promise<boolean>;
96
+ validateCsrf(resolvedArg: IResolvedRelyingPartySession, candidateArg: unknown): boolean;
97
+ /** Ends one session; see `endSession`. */
98
+ logout(sessionIdArg: string): Promise<boolean>;
99
+ /**
100
+ * Revokes a session once, with one conditional update: a touch running
101
+ * beside it cannot write the revocation away, and a second call finds
102
+ * nothing. Its provider tokens go back within `TOKEN_REVOCATION_BUDGET_MS`,
103
+ * after the local revocation, which never depends on the provider. Answers
104
+ * whether this call ended it.
105
+ */
106
+ endSession(sessionIdArg: string, reasonArg?: TRelyingPartySessionEndReason): Promise<boolean>;
107
+ /**
108
+ * Ends every live session of a principal but `keepSessionId` (a password
109
+ * change keeps the session that asked for it) and answers how many ended.
110
+ */
111
+ endSessionsOfPrincipal(principalIdArg: string, optionsArg?: {
112
+ keepSessionId?: string;
113
+ }): Promise<number>;
114
+ clearSessionCookie(): string;
115
+ clearIntentCookie(): string;
116
+ /**
117
+ * Starts a sign-in transaction: one attempt document with the PKCE verifier
118
+ * sealed next to it, and an intent cookie that binds the callback to this
119
+ * browser.
120
+ */
121
+ startLogin(returnPathArg: unknown): Promise<IRelyingPartyLoginStart>;
122
+ /**
123
+ * Consumes the attempt exactly once, exchanges the code, admits the
124
+ * principal and opens a session. A replayed callback, a foreign intent
125
+ * cookie and an expired attempt all find nothing to consume. Nothing of a
126
+ * failed login survives: its tokens are handed back before the failure
127
+ * leaves.
128
+ */
129
+ completeLogin(callbackUrlArg: URL, cookieHeaderArg: string | null | undefined): Promise<IRelyingPartySessionOpening>;
130
+ /**
131
+ * The provider sent the browser back without a code. The attempt is
132
+ * consumed so its state can never complete afterwards; a callback that
133
+ * matches no open attempt leaves nothing to do.
134
+ */
135
+ abandonLogin(callbackUrlArg: URL, cookieHeaderArg: string | null | undefined): Promise<void>;
136
+ /**
137
+ * The last step of a login: the browser arrives with both cookies, and the
138
+ * return path is released only when the session cookie belongs to the
139
+ * session this very attempt created.
140
+ */
141
+ finalizeLogin(cookieHeaderArg: string | null | undefined): Promise<string>;
142
+ /**
143
+ * An access token of this login session that is usable right now. A token
144
+ * within `ACCESS_TOKEN_REFRESH_SKEW_MS` of its expiry — or one whose expiry
145
+ * is unknown — is rotated first. The session has to belong to
146
+ * `expectedPrincipalIdArg`, so a credential is never evaluated with another
147
+ * person's tokens.
148
+ */
149
+ liveProviderToken(sessionIdArg: string, expectedPrincipalIdArg: string): Promise<IProviderToken>;
150
+ private refreshProviderToken;
151
+ private runProviderRefresh;
152
+ /**
153
+ * Another replica is rotating this session right now. Whatever it has
154
+ * written by the time this request looks again is used; otherwise the
155
+ * request fails closed and the next one finds the rotated pair.
156
+ */
157
+ private tokenAfterForeignRefresh;
158
+ private requireProvider;
159
+ private newSessionDoc;
160
+ private csrfTokenOf;
161
+ private opening;
162
+ private snapshot;
163
+ /** A session document that is live right now with an active principal, touched at most once a minute. */
164
+ private liveSession;
165
+ private createProviderSession;
166
+ /** Revokes a session that was never handed out and erases its sealed tokens. */
167
+ private discardUnopenedSession;
168
+ /**
169
+ * Tells the application a session ended. Its hook never stands between the
170
+ * local revocation and the provider revocation: a throw or a rejection is
171
+ * reported as `hook_failed` and the end runs on.
172
+ */
173
+ private notifySessionEnded;
174
+ /**
175
+ * The conditional revocation every end of a session runs. Answers the
176
+ * sealed tokens it took off the session when this call revoked it, `null`
177
+ * when the session was already over.
178
+ */
179
+ private revokeSession;
180
+ /** The provider says the login is over: the session ends here without asking it anything more. */
181
+ private endProviderSession;
182
+ /**
183
+ * Hands the tokens of an ended session back, best-effort and within the
184
+ * budget. A sealed value this deployment can no longer open is skipped.
185
+ */
186
+ private revokeSealedTokens;
187
+ private revokeRotatedTokens;
188
+ private revokeCompletionTokens;
189
+ private revokeToken;
190
+ /**
191
+ * Runs a best-effort provider step under `TOKEN_REVOCATION_BUDGET_MS`. What
192
+ * is still in flight at the deadline keeps running and ends on the provider
193
+ * client's own request timeout; only the waiting stops. The timer is cleared
194
+ * on every path and unreferenced.
195
+ */
196
+ private withinRevocationBudget;
197
+ /** A sealed value this deployment can still open, or `undefined`. */
198
+ private openSealed;
199
+ /**
200
+ * Removes attempts an hour past their expiry, one bounded page per login
201
+ * start. A sweep that cannot run never blocks a sign-in.
202
+ */
203
+ private sweepExpiredAttempts;
204
+ /**
205
+ * Reports one diagnostic. Every cleanup step reports through here, so a
206
+ * throwing sink must not end it: the event and the sink's failure go to
207
+ * `console.error` instead.
208
+ */
209
+ private emit;
210
+ }