@cboxdk/id-js 0.15.1 → 0.17.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/README.md +237 -2
- package/dist/chunk-ASOQN47M.js +81 -0
- package/dist/chunk-ASOQN47M.js.map +1 -0
- package/dist/{chunk-3V6OKRWF.js → chunk-G3CD7X4U.js} +321 -90
- package/dist/chunk-G3CD7X4U.js.map +1 -0
- package/dist/chunk-WYTGLCMF.js +154 -0
- package/dist/chunk-WYTGLCMF.js.map +1 -0
- package/dist/{client-CecDIu_N.d.cts → client-CEXddiCR.d.cts} +81 -136
- package/dist/{client-CecDIu_N.d.ts → client-CdwdigzG.d.ts} +81 -136
- package/dist/index.cjs +384 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.js +63 -25
- package/dist/index.js.map +1 -1
- package/dist/nextjs.cjs +517 -42
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.d.cts +29 -8
- package/dist/nextjs.d.ts +29 -8
- package/dist/nextjs.js +41 -12
- package/dist/nextjs.js.map +1 -1
- package/dist/server.cjs +220 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +105 -0
- package/dist/server.d.ts +105 -0
- package/dist/server.js +4 -0
- package/dist/server.js.map +1 -0
- package/dist/types-BYZldock.d.cts +316 -0
- package/dist/types-BYZldock.d.ts +316 -0
- package/package.json +6 -1
- package/dist/chunk-3V6OKRWF.js.map +0 -1
|
@@ -1,130 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
interface CboxIdConfig {
|
|
3
|
-
/**
|
|
4
|
-
* Base URL (issuer) of the Cbox ID instance, e.g. `https://id.acme.com`. Every
|
|
5
|
-
* endpoint is discovered from `{issuer}/.well-known/openid-configuration`, so this
|
|
6
|
-
* is usually the only endpoint you configure.
|
|
7
|
-
*/
|
|
8
|
-
issuer: string;
|
|
9
|
-
/** Your registered OAuth client id. */
|
|
10
|
-
clientId: string;
|
|
11
|
-
/**
|
|
12
|
-
* Your client secret. Required for confidential (server-side) apps, machine
|
|
13
|
-
* tokens and introspection. Omit for public clients (SPA/native) that only do
|
|
14
|
-
* PKCE login.
|
|
15
|
-
*/
|
|
16
|
-
clientSecret?: string;
|
|
17
|
-
/** Your callback URL — must exactly match one registered on the client. */
|
|
18
|
-
redirectUri: string;
|
|
19
|
-
/** Scopes requested at login. Defaults to `['openid', 'profile', 'email']`. */
|
|
20
|
-
scopes?: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Path of the instance's hosted account page that {@link CboxIdClient.profileUrl}
|
|
23
|
-
* points at. Defaults to `/settings`.
|
|
24
|
-
*/
|
|
25
|
-
accountPath?: string;
|
|
26
|
-
/** Timeout (ms) for back-channel HTTP calls. Defaults to `10000`. */
|
|
27
|
-
timeoutMs?: number;
|
|
28
|
-
/** How long (ms) the discovery document is cached. Defaults to `3600000` (1h). */
|
|
29
|
-
cacheTtlMs?: number;
|
|
30
|
-
/**
|
|
31
|
-
* Leeway (seconds) when checking the id_token's `auth_time` against the `maxAge` you
|
|
32
|
-
* requested at login. Defaults to `60`.
|
|
33
|
-
*
|
|
34
|
-
* Some slack is required, not optional: `maxAge` bounds the age of the
|
|
35
|
-
* AUTHENTICATION, but `auth_time` is read after a browser redirect and a token
|
|
36
|
-
* exchange, so even a just-completed re-authentication is already several seconds
|
|
37
|
-
* old — and the RP's clock and the instance's need not agree. Sixty seconds absorbs
|
|
38
|
-
* that while still catching what this check exists for: a session hours or days old
|
|
39
|
-
* being passed off as fresh.
|
|
40
|
-
*/
|
|
41
|
-
authTimeToleranceSeconds?: number;
|
|
42
|
-
}
|
|
43
|
-
/** The OIDC discovery document fields this SDK uses. */
|
|
44
|
-
interface DiscoveryDocument {
|
|
45
|
-
issuer: string;
|
|
46
|
-
authorization_endpoint: string;
|
|
47
|
-
token_endpoint: string;
|
|
48
|
-
jwks_uri: string;
|
|
49
|
-
userinfo_endpoint?: string;
|
|
50
|
-
introspection_endpoint?: string;
|
|
51
|
-
revocation_endpoint?: string;
|
|
52
|
-
end_session_endpoint?: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* RFC 7009 `token_type_hint`: which token store the server should search first.
|
|
56
|
-
* Only a hint — the server must still find the token if the hint is wrong.
|
|
57
|
-
*/
|
|
58
|
-
type TokenTypeHint = 'access_token' | 'refresh_token';
|
|
59
|
-
/**
|
|
60
|
-
* The values {@link CboxIdClient.createAuthorizationRequest} returns. Persist
|
|
61
|
-
* `state`, `codeVerifier` and `nonce` (e.g. in signed, httpOnly cookies) and hand
|
|
62
|
-
* them back to {@link CboxIdClient.authenticate} on the callback.
|
|
63
|
-
*/
|
|
64
|
-
interface AuthorizationRequest {
|
|
65
|
-
/** The URL to redirect the user to. */
|
|
66
|
-
url: string;
|
|
67
|
-
state: string;
|
|
68
|
-
codeVerifier: string;
|
|
69
|
-
nonce: string;
|
|
70
|
-
/**
|
|
71
|
-
* Echoed back when you passed `maxAge`. Persist it with the rest and hand it to
|
|
72
|
-
* {@link CboxIdClient.authenticate}, which then verifies the id_token's `auth_time`
|
|
73
|
-
* against it — a step-up nobody checks is not a step-up.
|
|
74
|
-
*/
|
|
75
|
-
maxAge?: number;
|
|
76
|
-
}
|
|
77
|
-
/** The raw token-endpoint response. */
|
|
78
|
-
interface TokenResponse {
|
|
79
|
-
access_token: string;
|
|
80
|
-
token_type?: string;
|
|
81
|
-
id_token?: string;
|
|
82
|
-
refresh_token?: string;
|
|
83
|
-
expires_in?: number;
|
|
84
|
-
scope?: string;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The tokens returned by {@link CboxIdClient.refresh}. Cbox ID ROTATES refresh
|
|
88
|
-
* tokens and detects reuse, so `refreshToken` is a NEW value — store it and discard
|
|
89
|
-
* the one you presented; replaying a rotated token revokes the whole family.
|
|
90
|
-
*/
|
|
91
|
-
interface RefreshedTokens {
|
|
92
|
-
accessToken: string;
|
|
93
|
-
refreshToken: string;
|
|
94
|
-
idToken: string | null;
|
|
95
|
-
expiresIn: number;
|
|
96
|
-
scope: string | null;
|
|
97
|
-
}
|
|
98
|
-
/** One organization a user belongs to, from the `organizations` claim when present. */
|
|
99
|
-
interface CboxOrganization {
|
|
100
|
-
id: string;
|
|
101
|
-
name: string;
|
|
102
|
-
/** The member's role in this organization, when the claim carries it. */
|
|
103
|
-
role?: string | null;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* The authenticated Cbox ID user. `id` is the stable opaque subject (`sub`) you key
|
|
107
|
-
* your local account on. `claims` is the full verified id_token + userinfo claim
|
|
108
|
-
* set; the named fields are conveniences over it.
|
|
109
|
-
*/
|
|
110
|
-
interface CboxUser {
|
|
111
|
-
id: string;
|
|
112
|
-
email: string | null;
|
|
113
|
-
name: string | null;
|
|
114
|
-
/** The active organization's id (`org` claim). */
|
|
115
|
-
organizationId: string | null;
|
|
116
|
-
/**
|
|
117
|
-
* The organizations this user belongs to, when the instance emits an
|
|
118
|
-
* `organizations` claim. Undefined when the claim is absent (single-org apps, or
|
|
119
|
-
* an instance that doesn't include it). Pass straight to `<OrganizationSwitcher>`.
|
|
120
|
-
*/
|
|
121
|
-
organizations?: CboxOrganization[];
|
|
122
|
-
claims: Record<string, unknown>;
|
|
123
|
-
accessToken: string;
|
|
124
|
-
refreshToken: string | null;
|
|
125
|
-
idToken: string | null;
|
|
126
|
-
expiresIn: number;
|
|
127
|
-
}
|
|
1
|
+
import { a as CboxIdConfig, A as AuthorizationRequestOptions, b as AuthorizationRequest, C as CboxUser, D as DeviceAuthorization, R as RefreshedTokens, T as TokenTypeHint } from './types-BYZldock.cjs';
|
|
128
2
|
|
|
129
3
|
/** A stored vault secret's metadata (never its plaintext). */
|
|
130
4
|
interface VaultSecretRef {
|
|
@@ -219,6 +93,16 @@ interface StoredAuthState {
|
|
|
219
93
|
nonce: string;
|
|
220
94
|
/** The `maxAge` this login demanded, if any. See {@link AuthorizationRequest.maxAge}. */
|
|
221
95
|
maxAge?: number;
|
|
96
|
+
/**
|
|
97
|
+
* The organization this sign-in was bound to, if any. See
|
|
98
|
+
* {@link AuthorizationRequest.organization}.
|
|
99
|
+
*
|
|
100
|
+
* Checked, not trusted: a binding nobody verifies is a binding in name only. An
|
|
101
|
+
* instance that predates the `organization` parameter ignores it and returns tokens for
|
|
102
|
+
* whichever organization the session already had — and an app that switched to "Globex"
|
|
103
|
+
* would then show Globex's name over Acme's data.
|
|
104
|
+
*/
|
|
105
|
+
organization?: string;
|
|
222
106
|
/**
|
|
223
107
|
* The scopes THIS authorization asked for, when you overrode the configured set.
|
|
224
108
|
*
|
|
@@ -256,14 +140,22 @@ declare class CboxIdClient {
|
|
|
256
140
|
* `nonce` — persist those (signed, httpOnly cookies are ideal) and hand them back
|
|
257
141
|
* to {@link authenticate} on the callback.
|
|
258
142
|
*/
|
|
259
|
-
createAuthorizationRequest(options?:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
143
|
+
createAuthorizationRequest(options?: AuthorizationRequestOptions): Promise<AuthorizationRequest>;
|
|
144
|
+
/**
|
|
145
|
+
* Switch the signed-in person to another organization: a new authorization bound to
|
|
146
|
+
* `organizationId`. Persist and redirect exactly as for
|
|
147
|
+
* {@link createAuthorizationRequest} — it is one, with `organization` set.
|
|
148
|
+
*
|
|
149
|
+
* Cbox ID already holds the person's session, so this is normally a redirect there and
|
|
150
|
+
* straight back with no sign-in form. The tokens that come back carry the new `org`,
|
|
151
|
+
* `org_role`, `roles` and `permissions`; replace your session with them rather than
|
|
152
|
+
* patching the old one, because every one of those can differ between organizations.
|
|
153
|
+
*
|
|
154
|
+
* A person who is not (or is no longer) an active member of that organization comes
|
|
155
|
+
* back with `error=access_denied`, which {@link authenticate} throws as an
|
|
156
|
+
* `AuthenticationError` with `error === 'access_denied'`.
|
|
157
|
+
*/
|
|
158
|
+
switchOrganization(organizationId: string, options?: Omit<AuthorizationRequestOptions, 'organization' | 'organizationHint'>): Promise<AuthorizationRequest>;
|
|
267
159
|
/**
|
|
268
160
|
* Complete login on your callback route: verify state, exchange the code with the
|
|
269
161
|
* PKCE verifier, verify the id_token, and return the authenticated user.
|
|
@@ -276,6 +168,45 @@ declare class CboxIdClient {
|
|
|
276
168
|
stored: StoredAuthState;
|
|
277
169
|
redirectUri?: string;
|
|
278
170
|
}): Promise<CboxUser>;
|
|
171
|
+
/**
|
|
172
|
+
* Turn a token response into the verified {@link CboxUser} every flow returns.
|
|
173
|
+
*
|
|
174
|
+
* Shared by the browser flow and the device flow rather than written twice: the checks
|
|
175
|
+
* in here — the UserInfo subject matching the id_token's, the merge that lets UserInfo
|
|
176
|
+
* enrich but never overwrite signed claims — are the ones that decide whether an
|
|
177
|
+
* identity is trustworthy. A second copy is a second place for one of them to be
|
|
178
|
+
* quietly missing, and the flow it was missing from would look exactly as correct.
|
|
179
|
+
*/
|
|
180
|
+
private identityFrom;
|
|
181
|
+
/**
|
|
182
|
+
* Start the device authorization grant (RFC 8628) — the flow for a program with no
|
|
183
|
+
* browser of its own: a CLI, a CI job, a container, a TV.
|
|
184
|
+
*
|
|
185
|
+
* Print `userCode` and `verificationUri`, then call
|
|
186
|
+
* {@link CboxIdClient.pollDeviceToken}. If the machine has a desktop you may also open
|
|
187
|
+
* `verificationUriComplete`, which fills the code in — but print the code anyway: the
|
|
188
|
+
* machine running your program is often not the one the person is looking at.
|
|
189
|
+
*
|
|
190
|
+
* The scopes are bounded by what the app is REGISTERED for. A device request naming one
|
|
191
|
+
* outside that ceiling is refused with `invalid_scope` rather than quietly reduced,
|
|
192
|
+
* because no browser is in front of it to notice a smaller grant.
|
|
193
|
+
*
|
|
194
|
+
* @throws ConfigurationError when the instance advertises no device endpoint.
|
|
195
|
+
*/
|
|
196
|
+
requestDeviceAuthorization(scopes?: string[]): Promise<DeviceAuthorization>;
|
|
197
|
+
/**
|
|
198
|
+
* Poll until the person approves, and return them.
|
|
199
|
+
*
|
|
200
|
+
* Blocks. It honours the server's `interval`, backs off permanently by five seconds on
|
|
201
|
+
* `slow_down` (RFC 8628 §3.5), and stops on the three answers that are final: they
|
|
202
|
+
* declined, the code expired, or tokens arrived. Pass an `AbortSignal` to give up
|
|
203
|
+
* early — a CLI should let Ctrl-C work.
|
|
204
|
+
*
|
|
205
|
+
* @throws AuthenticationError when the person declines or the code expires.
|
|
206
|
+
*/
|
|
207
|
+
pollDeviceToken(authorization: DeviceAuthorization, options?: {
|
|
208
|
+
signal?: AbortSignal;
|
|
209
|
+
}): Promise<CboxUser>;
|
|
279
210
|
/**
|
|
280
211
|
* Exchange a refresh token for a fresh access token (OAuth 2.0 `refresh_token`
|
|
281
212
|
* grant). Cbox ID rotates refresh tokens and detects reuse, so ALWAYS persist the
|
|
@@ -291,6 +222,20 @@ declare class CboxIdClient {
|
|
|
291
222
|
* ID session; `returnTo` is passed so the page can link back to your app.
|
|
292
223
|
*/
|
|
293
224
|
profileUrl(returnTo?: string): string;
|
|
225
|
+
/**
|
|
226
|
+
* The hosted page where a person creates and revokes API keys for your API — Cbox ID's
|
|
227
|
+
* `/account/api-keys`, preselected to this app (or `clientId`). Keys made there are
|
|
228
|
+
* checked with `ApiKeyVerifier` from `@cboxdk/id-js/server`.
|
|
229
|
+
*
|
|
230
|
+
* `returnTo` becomes a link back to your app, honoured only for an origin the app
|
|
231
|
+
* registered. `organization` picks which of the person's organizations the keys act in;
|
|
232
|
+
* omitted, the page uses the one they are in.
|
|
233
|
+
*/
|
|
234
|
+
apiKeysUrl(options?: {
|
|
235
|
+
clientId?: string;
|
|
236
|
+
returnTo?: string;
|
|
237
|
+
organization?: string;
|
|
238
|
+
}): string;
|
|
294
239
|
/**
|
|
295
240
|
* The RP-initiated logout URL, or null when the instance advertises none.
|
|
296
241
|
*
|
|
@@ -365,4 +310,4 @@ declare class CboxIdClient {
|
|
|
365
310
|
private fetchWithTimeout;
|
|
366
311
|
}
|
|
367
312
|
|
|
368
|
-
export {
|
|
313
|
+
export { CboxIdClient as C, type StoreSecretInput as S, VaultClient as V, type CallbackParams as a, type StoredAuthState as b, type VaultLease as c, type VaultSecretRef as d, type VerifyWebhookOptions as e, verifyWebhook as v };
|
|
@@ -1,130 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
interface CboxIdConfig {
|
|
3
|
-
/**
|
|
4
|
-
* Base URL (issuer) of the Cbox ID instance, e.g. `https://id.acme.com`. Every
|
|
5
|
-
* endpoint is discovered from `{issuer}/.well-known/openid-configuration`, so this
|
|
6
|
-
* is usually the only endpoint you configure.
|
|
7
|
-
*/
|
|
8
|
-
issuer: string;
|
|
9
|
-
/** Your registered OAuth client id. */
|
|
10
|
-
clientId: string;
|
|
11
|
-
/**
|
|
12
|
-
* Your client secret. Required for confidential (server-side) apps, machine
|
|
13
|
-
* tokens and introspection. Omit for public clients (SPA/native) that only do
|
|
14
|
-
* PKCE login.
|
|
15
|
-
*/
|
|
16
|
-
clientSecret?: string;
|
|
17
|
-
/** Your callback URL — must exactly match one registered on the client. */
|
|
18
|
-
redirectUri: string;
|
|
19
|
-
/** Scopes requested at login. Defaults to `['openid', 'profile', 'email']`. */
|
|
20
|
-
scopes?: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Path of the instance's hosted account page that {@link CboxIdClient.profileUrl}
|
|
23
|
-
* points at. Defaults to `/settings`.
|
|
24
|
-
*/
|
|
25
|
-
accountPath?: string;
|
|
26
|
-
/** Timeout (ms) for back-channel HTTP calls. Defaults to `10000`. */
|
|
27
|
-
timeoutMs?: number;
|
|
28
|
-
/** How long (ms) the discovery document is cached. Defaults to `3600000` (1h). */
|
|
29
|
-
cacheTtlMs?: number;
|
|
30
|
-
/**
|
|
31
|
-
* Leeway (seconds) when checking the id_token's `auth_time` against the `maxAge` you
|
|
32
|
-
* requested at login. Defaults to `60`.
|
|
33
|
-
*
|
|
34
|
-
* Some slack is required, not optional: `maxAge` bounds the age of the
|
|
35
|
-
* AUTHENTICATION, but `auth_time` is read after a browser redirect and a token
|
|
36
|
-
* exchange, so even a just-completed re-authentication is already several seconds
|
|
37
|
-
* old — and the RP's clock and the instance's need not agree. Sixty seconds absorbs
|
|
38
|
-
* that while still catching what this check exists for: a session hours or days old
|
|
39
|
-
* being passed off as fresh.
|
|
40
|
-
*/
|
|
41
|
-
authTimeToleranceSeconds?: number;
|
|
42
|
-
}
|
|
43
|
-
/** The OIDC discovery document fields this SDK uses. */
|
|
44
|
-
interface DiscoveryDocument {
|
|
45
|
-
issuer: string;
|
|
46
|
-
authorization_endpoint: string;
|
|
47
|
-
token_endpoint: string;
|
|
48
|
-
jwks_uri: string;
|
|
49
|
-
userinfo_endpoint?: string;
|
|
50
|
-
introspection_endpoint?: string;
|
|
51
|
-
revocation_endpoint?: string;
|
|
52
|
-
end_session_endpoint?: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* RFC 7009 `token_type_hint`: which token store the server should search first.
|
|
56
|
-
* Only a hint — the server must still find the token if the hint is wrong.
|
|
57
|
-
*/
|
|
58
|
-
type TokenTypeHint = 'access_token' | 'refresh_token';
|
|
59
|
-
/**
|
|
60
|
-
* The values {@link CboxIdClient.createAuthorizationRequest} returns. Persist
|
|
61
|
-
* `state`, `codeVerifier` and `nonce` (e.g. in signed, httpOnly cookies) and hand
|
|
62
|
-
* them back to {@link CboxIdClient.authenticate} on the callback.
|
|
63
|
-
*/
|
|
64
|
-
interface AuthorizationRequest {
|
|
65
|
-
/** The URL to redirect the user to. */
|
|
66
|
-
url: string;
|
|
67
|
-
state: string;
|
|
68
|
-
codeVerifier: string;
|
|
69
|
-
nonce: string;
|
|
70
|
-
/**
|
|
71
|
-
* Echoed back when you passed `maxAge`. Persist it with the rest and hand it to
|
|
72
|
-
* {@link CboxIdClient.authenticate}, which then verifies the id_token's `auth_time`
|
|
73
|
-
* against it — a step-up nobody checks is not a step-up.
|
|
74
|
-
*/
|
|
75
|
-
maxAge?: number;
|
|
76
|
-
}
|
|
77
|
-
/** The raw token-endpoint response. */
|
|
78
|
-
interface TokenResponse {
|
|
79
|
-
access_token: string;
|
|
80
|
-
token_type?: string;
|
|
81
|
-
id_token?: string;
|
|
82
|
-
refresh_token?: string;
|
|
83
|
-
expires_in?: number;
|
|
84
|
-
scope?: string;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The tokens returned by {@link CboxIdClient.refresh}. Cbox ID ROTATES refresh
|
|
88
|
-
* tokens and detects reuse, so `refreshToken` is a NEW value — store it and discard
|
|
89
|
-
* the one you presented; replaying a rotated token revokes the whole family.
|
|
90
|
-
*/
|
|
91
|
-
interface RefreshedTokens {
|
|
92
|
-
accessToken: string;
|
|
93
|
-
refreshToken: string;
|
|
94
|
-
idToken: string | null;
|
|
95
|
-
expiresIn: number;
|
|
96
|
-
scope: string | null;
|
|
97
|
-
}
|
|
98
|
-
/** One organization a user belongs to, from the `organizations` claim when present. */
|
|
99
|
-
interface CboxOrganization {
|
|
100
|
-
id: string;
|
|
101
|
-
name: string;
|
|
102
|
-
/** The member's role in this organization, when the claim carries it. */
|
|
103
|
-
role?: string | null;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* The authenticated Cbox ID user. `id` is the stable opaque subject (`sub`) you key
|
|
107
|
-
* your local account on. `claims` is the full verified id_token + userinfo claim
|
|
108
|
-
* set; the named fields are conveniences over it.
|
|
109
|
-
*/
|
|
110
|
-
interface CboxUser {
|
|
111
|
-
id: string;
|
|
112
|
-
email: string | null;
|
|
113
|
-
name: string | null;
|
|
114
|
-
/** The active organization's id (`org` claim). */
|
|
115
|
-
organizationId: string | null;
|
|
116
|
-
/**
|
|
117
|
-
* The organizations this user belongs to, when the instance emits an
|
|
118
|
-
* `organizations` claim. Undefined when the claim is absent (single-org apps, or
|
|
119
|
-
* an instance that doesn't include it). Pass straight to `<OrganizationSwitcher>`.
|
|
120
|
-
*/
|
|
121
|
-
organizations?: CboxOrganization[];
|
|
122
|
-
claims: Record<string, unknown>;
|
|
123
|
-
accessToken: string;
|
|
124
|
-
refreshToken: string | null;
|
|
125
|
-
idToken: string | null;
|
|
126
|
-
expiresIn: number;
|
|
127
|
-
}
|
|
1
|
+
import { a as CboxIdConfig, A as AuthorizationRequestOptions, b as AuthorizationRequest, C as CboxUser, D as DeviceAuthorization, R as RefreshedTokens, T as TokenTypeHint } from './types-BYZldock.js';
|
|
128
2
|
|
|
129
3
|
/** A stored vault secret's metadata (never its plaintext). */
|
|
130
4
|
interface VaultSecretRef {
|
|
@@ -219,6 +93,16 @@ interface StoredAuthState {
|
|
|
219
93
|
nonce: string;
|
|
220
94
|
/** The `maxAge` this login demanded, if any. See {@link AuthorizationRequest.maxAge}. */
|
|
221
95
|
maxAge?: number;
|
|
96
|
+
/**
|
|
97
|
+
* The organization this sign-in was bound to, if any. See
|
|
98
|
+
* {@link AuthorizationRequest.organization}.
|
|
99
|
+
*
|
|
100
|
+
* Checked, not trusted: a binding nobody verifies is a binding in name only. An
|
|
101
|
+
* instance that predates the `organization` parameter ignores it and returns tokens for
|
|
102
|
+
* whichever organization the session already had — and an app that switched to "Globex"
|
|
103
|
+
* would then show Globex's name over Acme's data.
|
|
104
|
+
*/
|
|
105
|
+
organization?: string;
|
|
222
106
|
/**
|
|
223
107
|
* The scopes THIS authorization asked for, when you overrode the configured set.
|
|
224
108
|
*
|
|
@@ -256,14 +140,22 @@ declare class CboxIdClient {
|
|
|
256
140
|
* `nonce` — persist those (signed, httpOnly cookies are ideal) and hand them back
|
|
257
141
|
* to {@link authenticate} on the callback.
|
|
258
142
|
*/
|
|
259
|
-
createAuthorizationRequest(options?:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
143
|
+
createAuthorizationRequest(options?: AuthorizationRequestOptions): Promise<AuthorizationRequest>;
|
|
144
|
+
/**
|
|
145
|
+
* Switch the signed-in person to another organization: a new authorization bound to
|
|
146
|
+
* `organizationId`. Persist and redirect exactly as for
|
|
147
|
+
* {@link createAuthorizationRequest} — it is one, with `organization` set.
|
|
148
|
+
*
|
|
149
|
+
* Cbox ID already holds the person's session, so this is normally a redirect there and
|
|
150
|
+
* straight back with no sign-in form. The tokens that come back carry the new `org`,
|
|
151
|
+
* `org_role`, `roles` and `permissions`; replace your session with them rather than
|
|
152
|
+
* patching the old one, because every one of those can differ between organizations.
|
|
153
|
+
*
|
|
154
|
+
* A person who is not (or is no longer) an active member of that organization comes
|
|
155
|
+
* back with `error=access_denied`, which {@link authenticate} throws as an
|
|
156
|
+
* `AuthenticationError` with `error === 'access_denied'`.
|
|
157
|
+
*/
|
|
158
|
+
switchOrganization(organizationId: string, options?: Omit<AuthorizationRequestOptions, 'organization' | 'organizationHint'>): Promise<AuthorizationRequest>;
|
|
267
159
|
/**
|
|
268
160
|
* Complete login on your callback route: verify state, exchange the code with the
|
|
269
161
|
* PKCE verifier, verify the id_token, and return the authenticated user.
|
|
@@ -276,6 +168,45 @@ declare class CboxIdClient {
|
|
|
276
168
|
stored: StoredAuthState;
|
|
277
169
|
redirectUri?: string;
|
|
278
170
|
}): Promise<CboxUser>;
|
|
171
|
+
/**
|
|
172
|
+
* Turn a token response into the verified {@link CboxUser} every flow returns.
|
|
173
|
+
*
|
|
174
|
+
* Shared by the browser flow and the device flow rather than written twice: the checks
|
|
175
|
+
* in here — the UserInfo subject matching the id_token's, the merge that lets UserInfo
|
|
176
|
+
* enrich but never overwrite signed claims — are the ones that decide whether an
|
|
177
|
+
* identity is trustworthy. A second copy is a second place for one of them to be
|
|
178
|
+
* quietly missing, and the flow it was missing from would look exactly as correct.
|
|
179
|
+
*/
|
|
180
|
+
private identityFrom;
|
|
181
|
+
/**
|
|
182
|
+
* Start the device authorization grant (RFC 8628) — the flow for a program with no
|
|
183
|
+
* browser of its own: a CLI, a CI job, a container, a TV.
|
|
184
|
+
*
|
|
185
|
+
* Print `userCode` and `verificationUri`, then call
|
|
186
|
+
* {@link CboxIdClient.pollDeviceToken}. If the machine has a desktop you may also open
|
|
187
|
+
* `verificationUriComplete`, which fills the code in — but print the code anyway: the
|
|
188
|
+
* machine running your program is often not the one the person is looking at.
|
|
189
|
+
*
|
|
190
|
+
* The scopes are bounded by what the app is REGISTERED for. A device request naming one
|
|
191
|
+
* outside that ceiling is refused with `invalid_scope` rather than quietly reduced,
|
|
192
|
+
* because no browser is in front of it to notice a smaller grant.
|
|
193
|
+
*
|
|
194
|
+
* @throws ConfigurationError when the instance advertises no device endpoint.
|
|
195
|
+
*/
|
|
196
|
+
requestDeviceAuthorization(scopes?: string[]): Promise<DeviceAuthorization>;
|
|
197
|
+
/**
|
|
198
|
+
* Poll until the person approves, and return them.
|
|
199
|
+
*
|
|
200
|
+
* Blocks. It honours the server's `interval`, backs off permanently by five seconds on
|
|
201
|
+
* `slow_down` (RFC 8628 §3.5), and stops on the three answers that are final: they
|
|
202
|
+
* declined, the code expired, or tokens arrived. Pass an `AbortSignal` to give up
|
|
203
|
+
* early — a CLI should let Ctrl-C work.
|
|
204
|
+
*
|
|
205
|
+
* @throws AuthenticationError when the person declines or the code expires.
|
|
206
|
+
*/
|
|
207
|
+
pollDeviceToken(authorization: DeviceAuthorization, options?: {
|
|
208
|
+
signal?: AbortSignal;
|
|
209
|
+
}): Promise<CboxUser>;
|
|
279
210
|
/**
|
|
280
211
|
* Exchange a refresh token for a fresh access token (OAuth 2.0 `refresh_token`
|
|
281
212
|
* grant). Cbox ID rotates refresh tokens and detects reuse, so ALWAYS persist the
|
|
@@ -291,6 +222,20 @@ declare class CboxIdClient {
|
|
|
291
222
|
* ID session; `returnTo` is passed so the page can link back to your app.
|
|
292
223
|
*/
|
|
293
224
|
profileUrl(returnTo?: string): string;
|
|
225
|
+
/**
|
|
226
|
+
* The hosted page where a person creates and revokes API keys for your API — Cbox ID's
|
|
227
|
+
* `/account/api-keys`, preselected to this app (or `clientId`). Keys made there are
|
|
228
|
+
* checked with `ApiKeyVerifier` from `@cboxdk/id-js/server`.
|
|
229
|
+
*
|
|
230
|
+
* `returnTo` becomes a link back to your app, honoured only for an origin the app
|
|
231
|
+
* registered. `organization` picks which of the person's organizations the keys act in;
|
|
232
|
+
* omitted, the page uses the one they are in.
|
|
233
|
+
*/
|
|
234
|
+
apiKeysUrl(options?: {
|
|
235
|
+
clientId?: string;
|
|
236
|
+
returnTo?: string;
|
|
237
|
+
organization?: string;
|
|
238
|
+
}): string;
|
|
294
239
|
/**
|
|
295
240
|
* The RP-initiated logout URL, or null when the instance advertises none.
|
|
296
241
|
*
|
|
@@ -365,4 +310,4 @@ declare class CboxIdClient {
|
|
|
365
310
|
private fetchWithTimeout;
|
|
366
311
|
}
|
|
367
312
|
|
|
368
|
-
export {
|
|
313
|
+
export { CboxIdClient as C, type StoreSecretInput as S, VaultClient as V, type CallbackParams as a, type StoredAuthState as b, type VaultLease as c, type VaultSecretRef as d, type VerifyWebhookOptions as e, verifyWebhook as v };
|