@idp.global/sdk 18.0.1 → 18.2.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 +28 -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 +37 -0
  8. package/dist_ts_relyingparty/classes.errors.js +60 -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 +102 -0
  12. package/dist_ts_relyingparty/classes.relyingpartyroutes.js +248 -0
  13. package/dist_ts_relyingparty/classes.relyingpartysessions.d.ts +223 -0
  14. package/dist_ts_relyingparty/classes.relyingpartysessions.js +825 -0
  15. package/dist_ts_relyingparty/classes.rpmodels.d.ts +87 -0
  16. package/dist_ts_relyingparty/classes.rpmodels.js +302 -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 +84 -0
  20. package/dist_ts_relyingparty/classes.socketbinding.js +100 -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 +142 -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 +215 -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 +77 -0
  39. package/ts_relyingparty/classes.idpoidcprovider.ts +386 -0
  40. package/ts_relyingparty/classes.relyingpartyroutes.ts +319 -0
  41. package/ts_relyingparty/classes.relyingpartysessions.ts +1017 -0
  42. package/ts_relyingparty/classes.rpmodels.ts +170 -0
  43. package/ts_relyingparty/classes.secretbox.ts +49 -0
  44. package/ts_relyingparty/classes.socketbinding.ts +156 -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 +165 -0
  50. package/ts_relyingparty/plugins.ts +17 -0
@@ -0,0 +1,165 @@
1
+ import type { IOidcCompletion, TOidcCompletionFailureStage, TOidcTokenHint } from './classes.idpoidcprovider.js';
2
+
3
+ /** A session as the application reads it; no token and no sealed value is part of it. */
4
+ export interface IRelyingPartySession {
5
+ id: string;
6
+ /** the application's principal (user) the session acts as */
7
+ principalId: string;
8
+ createdAt: number;
9
+ lastSeenAt: number;
10
+ expiresAt: number;
11
+ /** the provider subject; absent for a session the application opened itself */
12
+ idpSubject?: string;
13
+ loginAttemptId?: string;
14
+ }
15
+
16
+ /**
17
+ * A live session with the principal it acts as. `principal` is what
18
+ * `principals.resolve` answered for it in the same read; with `isActive`
19
+ * principals it is `undefined`.
20
+ */
21
+ export interface IRelyingPartyLiveSession<TPrincipal extends object | undefined = undefined> {
22
+ session: IRelyingPartySession;
23
+ principal: TPrincipal;
24
+ }
25
+
26
+ /** A live session behind a cookie, with its principal and the CSRF token derived for it. */
27
+ export interface IResolvedRelyingPartySession<TPrincipal extends object | undefined = undefined> extends IRelyingPartyLiveSession<TPrincipal> {
28
+ csrfToken: string;
29
+ }
30
+
31
+ /** A session just opened: the answer, the CSRF token and the `Set-Cookie` value that carries it. */
32
+ export interface IRelyingPartySessionOpening {
33
+ session: IRelyingPartySession;
34
+ csrfToken: string;
35
+ sessionCookie: string;
36
+ }
37
+
38
+ /** The redirect that starts a provider login, and the cookie that binds it to this browser. */
39
+ export interface IRelyingPartyLoginStart {
40
+ authorizationUrl: URL;
41
+ intentCookie: string;
42
+ }
43
+
44
+ /** A provider access token usable right now, with the subject it belongs to. */
45
+ export interface IProviderToken {
46
+ accessToken: string;
47
+ subject: string;
48
+ /** epoch milliseconds; `0` when the provider named no lifetime */
49
+ expiresAt: number;
50
+ }
51
+
52
+ /** What an authority observer needs from the session owner. `RelyingPartySessions` implements it. */
53
+ export interface IAuthorityTokenSource {
54
+ /**
55
+ * The access token of a login session, rotated first when it is due. The
56
+ * session must belong to `expectedPrincipalIdArg`. Throws `AuthorityTokenError`.
57
+ */
58
+ liveProviderToken(sessionIdArg: string, expectedPrincipalIdArg: string): Promise<IProviderToken>;
59
+ }
60
+
61
+ /**
62
+ * The application's side of a provider login: who the verified subject is
63
+ * here. `admit` creates or updates the local principal (and whatever the
64
+ * application projects from the organization claims) and answers its id, or
65
+ * throws `RelyingPartyRefusal` to refuse the login; the provider tokens are
66
+ * then handed back and the refusal reaches the caller unchanged.
67
+ */
68
+ export interface IRelyingPartyPrincipals {
69
+ admit(completionArg: IOidcCompletion): Promise<{ principalId: string }>;
70
+ /** Whether a principal may act right now; a session of an inactive principal resolves to nothing. */
71
+ isActive(principalIdArg: string): Promise<boolean>;
72
+ }
73
+
74
+ /**
75
+ * Principals that answer the principal itself instead of a yes or no, so a
76
+ * request reads its user once: `resolve` answers the principal when it may act
77
+ * right now and `null` otherwise, and every live session carries the answer as
78
+ * `principal`. Give either `isActive` or `resolve`, never both.
79
+ */
80
+ export interface IRelyingPartyPrincipalResolver<TPrincipal extends object | undefined> {
81
+ admit(completionArg: IOidcCompletion): Promise<{ principalId: string }>;
82
+ /** The principal object when it may act right now, `null` otherwise; any answer that is not an object (including `false`) resolves the session to nothing. */
83
+ resolve(principalIdArg: string): Promise<TPrincipal | null>;
84
+ }
85
+
86
+ /**
87
+ * What `RelyingPartySessions` accepts as its principals: a resolver whose
88
+ * principal type every live session carries, or — only while that type is
89
+ * left `undefined` — the `isActive` form.
90
+ */
91
+ export type TRelyingPartyPrincipals<TPrincipal extends object | undefined> =
92
+ | IRelyingPartyPrincipalResolver<TPrincipal>
93
+ | (undefined extends TPrincipal ? IRelyingPartyPrincipals : never);
94
+
95
+ export type TRelyingPartySessionEndReason =
96
+ /** the application or the user ended it */
97
+ | 'logout'
98
+ /** the provider refused to rotate its tokens: the login is over there */
99
+ | 'refresh_token_refused'
100
+ /** its refresh token was sealed under a key this deployment no longer has */
101
+ | 'sealed_refresh_token_unreadable'
102
+ /** its access token is dead and there is nothing to rotate it with */
103
+ | 'access_token_unusable'
104
+ /** a rotation found it revoked by someone else */
105
+ | 'revoked_elsewhere';
106
+
107
+ export type TRelyingPartyEventName =
108
+ | 'idp_token_refresh_failed'
109
+ | 'idp_token_store_failed'
110
+ | 'idp_session_ended'
111
+ | 'oidc_sealed_token_unreadable'
112
+ | 'oidc_token_revocation_failed'
113
+ | 'oidc_token_revocation_timed_out'
114
+ | 'login_attempt_sweep_failed'
115
+ /** an application hook threw; the step it belonged to ran on regardless */
116
+ | 'hook_failed'
117
+ /** a session whose opening failed could not be revoked; its provider tokens went back anyway */
118
+ | 'session_discard_failed';
119
+
120
+ /** The application hooks whose failures `hook_failed` names. */
121
+ export type TRelyingPartyHookName = 'onProviderSessionOpened' | 'onSessionEnded' | 'onEvent';
122
+
123
+ /** One structured diagnostic line. It never carries a token, a cookie or a sealed value. */
124
+ export interface IRelyingPartyEvent {
125
+ event: TRelyingPartyEventName;
126
+ sessionId?: string;
127
+ reason?: string;
128
+ hint?: TOidcTokenHint;
129
+ hook?: TRelyingPartyHookName;
130
+ message?: string;
131
+ }
132
+
133
+ export interface IRelyingPartyHooks {
134
+ /**
135
+ * A provider login opened a session, linked to its attempt. Runs before the
136
+ * login answers; a throw fails the login: the session is revoked, the
137
+ * provider tokens are handed back and the original error is rethrown.
138
+ */
139
+ onProviderSessionOpened?(eventArg: { session: IRelyingPartySession }): Promise<void>;
140
+ /**
141
+ * A session ended, or a caller tried to end one that was already over
142
+ * (`revokedHere: false`). Close its live connections when `revokedHere`,
143
+ * drop cached authority either way. Must not wait. A throw (or a rejected
144
+ * promise) is reported as a `hook_failed` event and never stops the end:
145
+ * the provider tokens go back regardless.
146
+ */
147
+ onSessionEnded?(eventArg: {
148
+ sessionId: string;
149
+ reason: TRelyingPartySessionEndReason;
150
+ revokedHere: boolean;
151
+ }): void;
152
+ /**
153
+ * Structured diagnostics; the default writes one JSON line to
154
+ * `console.error`. A throwing sink never interrupts the step that reported:
155
+ * the event and a `hook_failed` line go to `console.error` instead.
156
+ */
157
+ onEvent?(eventArg: IRelyingPartyEvent): void;
158
+ }
159
+
160
+ /** Where a failed login callback stopped; for the log, never for the browser. */
161
+ export type TLoginCallbackStage =
162
+ | TOidcCompletionFailureStage
163
+ | 'attempt_persistence'
164
+ | 'principal_admission'
165
+ | 'session_persistence';
@@ -0,0 +1,17 @@
1
+ import * as asyncHooks from 'node:async_hooks';
2
+ import * as crypto from 'node:crypto';
3
+
4
+ export { asyncHooks, crypto };
5
+
6
+ import * as typedrequest from '@api.global/typedrequest';
7
+ import * as typedsocket from '@api.global/typedsocket';
8
+
9
+ export { typedrequest, typedsocket };
10
+
11
+ import * as nosqldb from '@lossless.org/client/nosqldb';
12
+
13
+ export { nosqldb };
14
+
15
+ import * as openidClient from 'openid-client';
16
+
17
+ export { openidClient };