@keycardai/oauth 0.26.6 → 0.28.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 +82 -2
- package/dist/cjs/basicAuthorization.d.ts +11 -0
- package/dist/cjs/basicAuthorization.d.ts.map +1 -0
- package/dist/cjs/basicAuthorization.js +16 -0
- package/dist/cjs/basicAuthorization.js.map +1 -0
- package/dist/cjs/clientCredentials.d.ts +3 -4
- package/dist/cjs/clientCredentials.d.ts.map +1 -1
- package/dist/cjs/clientCredentials.js +2 -2
- package/dist/cjs/clientCredentials.js.map +1 -1
- package/dist/cjs/credentials.d.ts +35 -0
- package/dist/cjs/credentials.d.ts.map +1 -1
- package/dist/cjs/credentials.js +19 -0
- package/dist/cjs/credentials.js.map +1 -1
- package/dist/cjs/deviceAuthorization.d.ts +166 -0
- package/dist/cjs/deviceAuthorization.d.ts.map +1 -0
- package/dist/cjs/deviceAuthorization.js +440 -0
- package/dist/cjs/deviceAuthorization.js.map +1 -0
- package/dist/cjs/discovery.d.ts +1 -0
- package/dist/cjs/discovery.d.ts.map +1 -1
- package/dist/cjs/discovery.js +5 -1
- package/dist/cjs/discovery.js.map +1 -1
- package/dist/cjs/errors.d.ts +61 -3
- package/dist/cjs/errors.d.ts.map +1 -1
- package/dist/cjs/errors.js +75 -4
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/pkce.d.ts +23 -1
- package/dist/cjs/pkce.d.ts.map +1 -1
- package/dist/cjs/pkce.js +38 -6
- package/dist/cjs/pkce.js.map +1 -1
- package/dist/cjs/server/clientSecret.d.ts +7 -1
- package/dist/cjs/server/clientSecret.d.ts.map +1 -1
- package/dist/cjs/server/clientSecret.js +17 -0
- package/dist/cjs/server/clientSecret.js.map +1 -1
- package/dist/cjs/server/webIdentity.d.ts +11 -1
- package/dist/cjs/server/webIdentity.d.ts.map +1 -1
- package/dist/cjs/server/webIdentity.js +35 -2
- package/dist/cjs/server/webIdentity.js.map +1 -1
- package/dist/cjs/server/workloadIdentity.d.ts +23 -9
- package/dist/cjs/server/workloadIdentity.d.ts.map +1 -1
- package/dist/cjs/server/workloadIdentity.js +29 -3
- package/dist/cjs/server/workloadIdentity.js.map +1 -1
- package/dist/cjs/tokenExchange.d.ts +2 -2
- package/dist/cjs/tokenExchange.d.ts.map +1 -1
- package/dist/cjs/tokenExchange.js +2 -2
- package/dist/cjs/tokenExchange.js.map +1 -1
- package/dist/cjs/webApp.d.ts +57 -18
- package/dist/cjs/webApp.d.ts.map +1 -1
- package/dist/cjs/webApp.js +52 -13
- package/dist/cjs/webApp.js.map +1 -1
- package/dist/esm/basicAuthorization.d.ts +11 -0
- package/dist/esm/basicAuthorization.d.ts.map +1 -0
- package/dist/esm/basicAuthorization.js +13 -0
- package/dist/esm/basicAuthorization.js.map +1 -0
- package/dist/esm/clientCredentials.d.ts +3 -4
- package/dist/esm/clientCredentials.d.ts.map +1 -1
- package/dist/esm/clientCredentials.js +2 -2
- package/dist/esm/clientCredentials.js.map +1 -1
- package/dist/esm/credentials.d.ts +35 -0
- package/dist/esm/credentials.d.ts.map +1 -1
- package/dist/esm/credentials.js +17 -1
- package/dist/esm/credentials.js.map +1 -1
- package/dist/esm/deviceAuthorization.d.ts +166 -0
- package/dist/esm/deviceAuthorization.d.ts.map +1 -0
- package/dist/esm/deviceAuthorization.js +434 -0
- package/dist/esm/deviceAuthorization.js.map +1 -0
- package/dist/esm/discovery.d.ts +1 -0
- package/dist/esm/discovery.d.ts.map +1 -1
- package/dist/esm/discovery.js +5 -1
- package/dist/esm/discovery.js.map +1 -1
- package/dist/esm/errors.d.ts +61 -3
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/errors.js +71 -3
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pkce.d.ts +23 -1
- package/dist/esm/pkce.d.ts.map +1 -1
- package/dist/esm/pkce.js +38 -6
- package/dist/esm/pkce.js.map +1 -1
- package/dist/esm/server/clientSecret.d.ts +7 -1
- package/dist/esm/server/clientSecret.d.ts.map +1 -1
- package/dist/esm/server/clientSecret.js +17 -0
- package/dist/esm/server/clientSecret.js.map +1 -1
- package/dist/esm/server/webIdentity.d.ts +11 -1
- package/dist/esm/server/webIdentity.d.ts.map +1 -1
- package/dist/esm/server/webIdentity.js +35 -2
- package/dist/esm/server/webIdentity.js.map +1 -1
- package/dist/esm/server/workloadIdentity.d.ts +23 -9
- package/dist/esm/server/workloadIdentity.d.ts.map +1 -1
- package/dist/esm/server/workloadIdentity.js +29 -3
- package/dist/esm/server/workloadIdentity.js.map +1 -1
- package/dist/esm/tokenExchange.d.ts +2 -2
- package/dist/esm/tokenExchange.d.ts.map +1 -1
- package/dist/esm/tokenExchange.js +2 -2
- package/dist/esm/tokenExchange.js.map +1 -1
- package/dist/esm/webApp.d.ts +57 -18
- package/dist/esm/webApp.d.ts.map +1 -1
- package/dist/esm/webApp.js +52 -13
- package/dist/esm/webApp.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -222,6 +222,71 @@ code at authorize time, so completion sends no `resource` parameter. A callback
|
|
|
222
222
|
carrying `error` throws `AuthorizationDeniedError` and a missing or non-matching
|
|
223
223
|
`state` throws `StateMismatchError`, both before any token request.
|
|
224
224
|
|
|
225
|
+
A confidential client can authenticate the code exchange with a `credential` in
|
|
226
|
+
place of `clientId` and `clientSecret`, such as a keyless `WorkloadIdentity`. Pass
|
|
227
|
+
its `clientId` to `beginAuthorization`; the code is bound to that client.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const credential = new WorkloadIdentity(new FileTokenSource(), { clientId: "my-client" });
|
|
231
|
+
const tokens = await completeAuthorization("https://your-zone.keycard.cloud", {
|
|
232
|
+
callbackParams: new URL(request.url).searchParams,
|
|
233
|
+
state: session.get("state"),
|
|
234
|
+
codeVerifier: session.get("codeVerifier"),
|
|
235
|
+
redirectUri: "https://app.example.com/callback",
|
|
236
|
+
credential,
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Device Authorization Grant (RFC 8628)
|
|
241
|
+
|
|
242
|
+
For a process with no browser and no redirect URI, such as a headless agent
|
|
243
|
+
host. The device asks the zone for a user code, shows it to a person, and polls
|
|
244
|
+
until the person approves or denies.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { fetchAuthorizationServerMetadata } from "@keycardai/oauth/discovery";
|
|
248
|
+
import { requestDeviceAuthorization, waitForDeviceToken } from "@keycardai/oauth/deviceAuthorization";
|
|
249
|
+
import { DevicePollError } from "@keycardai/oauth/errors";
|
|
250
|
+
import { WorkloadIdentity, FileTokenSource } from "@keycardai/oauth/server";
|
|
251
|
+
import type { TokenResponse } from "@keycardai/oauth/tokenExchange";
|
|
252
|
+
|
|
253
|
+
const issuer = "https://your-zone.keycard.cloud";
|
|
254
|
+
const credential = new WorkloadIdentity(new FileTokenSource(), { clientId: "my-client" });
|
|
255
|
+
const metadata = await fetchAuthorizationServerMetadata(issuer);
|
|
256
|
+
|
|
257
|
+
const authorization = await requestDeviceAuthorization(issuer, {
|
|
258
|
+
credential, // or `clientId` for a public client
|
|
259
|
+
metadata,
|
|
260
|
+
scopes: ["openid"],
|
|
261
|
+
resources: ["https://api.example.com"],
|
|
262
|
+
});
|
|
263
|
+
console.log(`Visit ${authorization.verificationUriComplete ?? authorization.verificationUri}`);
|
|
264
|
+
console.log(`and confirm the code ${authorization.userCode}`);
|
|
265
|
+
|
|
266
|
+
let tokens: TokenResponse | undefined;
|
|
267
|
+
let interval: number | undefined;
|
|
268
|
+
while (!tokens) {
|
|
269
|
+
try {
|
|
270
|
+
tokens = await waitForDeviceToken(issuer, { credential, metadata, authorization, interval });
|
|
271
|
+
} catch (error) {
|
|
272
|
+
if (!(error instanceof DevicePollError)) throw error;
|
|
273
|
+
interval = error.interval;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The doc comment on `waitForDeviceToken` lists the poll loop rules and when it
|
|
279
|
+
throws `DevicePollError`. The loop above resumes it after that error.
|
|
280
|
+
`DeviceAuthorization` is a plain value, so you can persist it and poll from
|
|
281
|
+
another process that authenticates as the same client. `pollDeviceToken` polls
|
|
282
|
+
once. Pass `metadata` so it does not discover on every poll. If you call it in
|
|
283
|
+
your own loop, wait longer after a timeout or other network error
|
|
284
|
+
(RFC 8628 §3.5).
|
|
285
|
+
|
|
286
|
+
When the request names more than one resource, the token is not for any one of
|
|
287
|
+
them. To get a token for one resource, call `refreshAuthorization` with
|
|
288
|
+
`resources` set to it and the same `credential`.
|
|
289
|
+
|
|
225
290
|
### UserInfo (OIDC Core 1.0 §5.3)
|
|
226
291
|
|
|
227
292
|
```typescript
|
|
@@ -270,12 +335,23 @@ issuer's `userinfo_endpoint`. Pass `{ metadata }` to skip discovery.
|
|
|
270
335
|
| `generateCodeVerifier` | `@keycardai/oauth/pkce` | Generates a 43-char random code verifier (RFC 7636 §4.1) |
|
|
271
336
|
| `generateCodeChallenge` | `@keycardai/oauth/pkce` | Computes S256 or plain code challenge from a verifier (RFC 7636 §4.2) |
|
|
272
337
|
| `generatePkcePair` | `@keycardai/oauth/pkce` | Convenience: generates verifier + challenge in one call |
|
|
273
|
-
| `exchangeAuthorizationCode` | `@keycardai/oauth/pkce` | Exchanges an authorization code with code_verifier at the token endpoint |
|
|
338
|
+
| `exchangeAuthorizationCode` | `@keycardai/oauth/pkce` | Exchanges an authorization code with code_verifier at the token endpoint, as a public client, with a client secret, or with a `credential` |
|
|
274
339
|
| `authenticate` | `@keycardai/oauth/pkce` | Full browser-launch and loopback-callback flow. **Node.js only** |
|
|
275
340
|
| `Pkce` (type) | `@keycardai/oauth/pkce` | `{ codeVerifier, codeChallenge, codeChallengeMethod }` |
|
|
276
341
|
| `beginAuthorization` | `@keycardai/oauth/webApp` | Web-app flow: builds the authorize URL and returns `{ url, state, codeVerifier, resources }` |
|
|
277
342
|
| `completeAuthorization` | `@keycardai/oauth/webApp` | Web-app flow: validates the callback and exchanges the code |
|
|
278
343
|
| `AuthorizationRedirect` (type) | `@keycardai/oauth/webApp` | Begin-step result the application stores until the callback |
|
|
344
|
+
| `refreshAuthorization` | `@keycardai/oauth/webApp` | Renews a grant with its `refresh_token`, as a public client, with a client secret, or with a `credential` |
|
|
345
|
+
|
|
346
|
+
### Device Authorization Grant (RFC 8628)
|
|
347
|
+
|
|
348
|
+
| Export | Import Path | Description |
|
|
349
|
+
|---|---|---|
|
|
350
|
+
| `requestDeviceAuthorization` | `@keycardai/oauth/deviceAuthorization` | Asks the zone for a device code and a user code |
|
|
351
|
+
| `pollDeviceToken` | `@keycardai/oauth/deviceAuthorization` | Polls the token endpoint once |
|
|
352
|
+
| `waitForDeviceToken` | `@keycardai/oauth/deviceAuthorization` | Polls until the person approves or denies, per RFC 8628 §3.5 |
|
|
353
|
+
| `DeviceAuthorization` (type) | `@keycardai/oauth/deviceAuthorization` | The device authorization response, with `expiresAt` computed from the clock |
|
|
354
|
+
| `Clock` (type), `systemClock` | `@keycardai/oauth/deviceAuthorization` | Time source and timer; inject a fake in tests |
|
|
279
355
|
|
|
280
356
|
### UserInfo (OIDC Core 1.0)
|
|
281
357
|
|
|
@@ -297,7 +373,8 @@ issuer's `userinfo_endpoint`. Pass `{ metadata }` to skip discovery.
|
|
|
297
373
|
| `GCPMetadataTokenSource` | `@keycardai/oauth/server` | Token source for the GCP metadata server (GKE, GCE, Cloud Run) |
|
|
298
374
|
| `FlyTokenSource` | `@keycardai/oauth/server` | Token source for the Fly.io Machines API Unix socket. **Node.js only** |
|
|
299
375
|
| `EKSWorkloadIdentity` | `@keycardai/oauth/server` | Deprecated: `WorkloadIdentity` with a `FileTokenSource` limited to EKS env discovery |
|
|
300
|
-
| `ApplicationCredential` (type) | `@keycardai/oauth/credentials` | Interface for credential providers |
|
|
376
|
+
| `ApplicationCredential` (type) | `@keycardai/oauth/credentials` | Interface for credential providers. The optional `clientAuthentication(issuer, endpoint)` returns the headers and form fields that authenticate one request. The optional `checkClientAuthentication()` throws `ConfigurationError` before any request when the credential cannot do so |
|
|
377
|
+
| `providesClientAuthentication` | `@keycardai/oauth/credentials` | Reports whether a credential provides `clientAuthentication` |
|
|
301
378
|
|
|
302
379
|
### Errors
|
|
303
380
|
|
|
@@ -313,6 +390,9 @@ issuer's `userinfo_endpoint`. Pass `{ metadata }` to skip discovery.
|
|
|
313
390
|
| `AuthProviderConfigurationError` | `@keycardai/oauth/errors` | Configuration guard for auth providers |
|
|
314
391
|
| `AuthorizationDeniedError` | `@keycardai/oauth/errors` | Web-app callback carried an OAuth `error` (e.g. `access_denied`) |
|
|
315
392
|
| `StateMismatchError` | `@keycardai/oauth/errors` | Web-app callback `state` is absent or does not match the stored value |
|
|
393
|
+
| `DeviceGrantError` | `@keycardai/oauth/errors` | Device grant failure, with `errorCode`, `errorDescription`, `status`, and `retryable` |
|
|
394
|
+
| `DevicePollError` | `@keycardai/oauth/errors` | `waitForDeviceToken` stopped on a network error, 5xx, or 429; has `interval` and the original failure as `cause` |
|
|
395
|
+
| `PERMANENT_ERROR_CODES`, `isPermanentErrorCode` | `@keycardai/oauth/errors` | OAuth error codes that are not retryable, except on HTTP 429 or 5xx; classifies a bare error code |
|
|
316
396
|
|
|
317
397
|
### Utilities
|
|
318
398
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP Basic `Authorization` header value that authenticates a client
|
|
3
|
+
* (RFC 6749 §2.3.1). The client ID and secret are each encoded with
|
|
4
|
+
* `encodeURIComponent` before base64. Letters, digits and `-_.!~*'()` are
|
|
5
|
+
* kept. Every other byte of the UTF-8 encoding becomes `%HH`, and a space
|
|
6
|
+
* becomes `%20`. Each half decodes to the original value with an RFC 6749
|
|
7
|
+
* Appendix B form decoder, and with the `decodeURIComponent` that Keycard
|
|
8
|
+
* zones use.
|
|
9
|
+
*/
|
|
10
|
+
export declare function basicAuthorization(clientId: string, clientSecret: string): string;
|
|
11
|
+
//# sourceMappingURL=basicAuthorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicAuthorization.d.ts","sourceRoot":"","sources":["../../src/basicAuthorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAEjF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.basicAuthorization = basicAuthorization;
|
|
4
|
+
/**
|
|
5
|
+
* The HTTP Basic `Authorization` header value that authenticates a client
|
|
6
|
+
* (RFC 6749 §2.3.1). The client ID and secret are each encoded with
|
|
7
|
+
* `encodeURIComponent` before base64. Letters, digits and `-_.!~*'()` are
|
|
8
|
+
* kept. Every other byte of the UTF-8 encoding becomes `%HH`, and a space
|
|
9
|
+
* becomes `%20`. Each half decodes to the original value with an RFC 6749
|
|
10
|
+
* Appendix B form decoder, and with the `decodeURIComponent` that Keycard
|
|
11
|
+
* zones use.
|
|
12
|
+
*/
|
|
13
|
+
function basicAuthorization(clientId, clientSecret) {
|
|
14
|
+
return `Basic ${btoa(`${encodeURIComponent(clientId)}:${encodeURIComponent(clientSecret)}`)}`;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=basicAuthorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicAuthorization.js","sourceRoot":"","sources":["../../src/basicAuthorization.ts"],"names":[],"mappings":";;AASA,gDAEC;AAXD;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAAC,QAAgB,EAAE,YAAoB;IACvE,OAAO,SAAS,IAAI,CAAC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -7,10 +7,9 @@ export interface ClientCredentialsRequest {
|
|
|
7
7
|
clientAssertion?: string;
|
|
8
8
|
clientAssertionType?: string;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* layer, such as Basic auth.
|
|
10
|
+
* Names the application credential the client authenticates as, sent beside
|
|
11
|
+
* a jwt-bearer `clientAssertion`, such as a v2 token credential's public ID.
|
|
12
|
+
* Never sent with HTTP Basic.
|
|
14
13
|
*/
|
|
15
14
|
clientId?: string;
|
|
16
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCredentials.d.ts","sourceRoot":"","sources":["../../src/clientCredentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientCredentials.d.ts","sourceRoot":"","sources":["../../src/clientCredentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAmD,KAAK,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACrH,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMlF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,8BAA+B,SAAQ,yBAAyB;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAwBD,qBAAa,uBAAuB;;gBAQtB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,8BAA8B;IAS9D,YAAY,CAChB,OAAO,CAAC,EAAE,wBAAwB,EAClC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,aAAa,CAAC;IA2DzB;;;;;OAKG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;CAG1C"}
|
|
@@ -14,6 +14,7 @@ var _ClientCredentialsClient_instances, _ClientCredentialsClient_issuer, _Client
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ClientCredentialsClient = void 0;
|
|
16
16
|
const errors_js_1 = require("./errors.js");
|
|
17
|
+
const basicAuthorization_js_1 = require("./basicAuthorization.js");
|
|
17
18
|
const tokenEndpoint_js_1 = require("./tokenEndpoint.js");
|
|
18
19
|
const tokenExchange_js_1 = require("./tokenExchange.js");
|
|
19
20
|
// =============================================================================
|
|
@@ -61,8 +62,7 @@ class ClientCredentialsClient {
|
|
|
61
62
|
};
|
|
62
63
|
const basicAuth = __classPrivateFieldGet(this, _ClientCredentialsClient_instances, "m", _ClientCredentialsClient_resolveBasicAuth).call(this, options?.issuer);
|
|
63
64
|
if (basicAuth) {
|
|
64
|
-
|
|
65
|
-
headers["Authorization"] = `Basic ${credentials}`;
|
|
65
|
+
headers["Authorization"] = (0, basicAuthorization_js_1.basicAuthorization)(basicAuth.clientId, basicAuth.clientSecret);
|
|
66
66
|
}
|
|
67
67
|
const response = await fetch(tokenEndpoint, {
|
|
68
68
|
method: "POST",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCredentials.js","sourceRoot":"","sources":["../../src/clientCredentials.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyC;AAEzC,yDAAqH;AACrH,yDAAkF;
|
|
1
|
+
{"version":3,"file":"clientCredentials.js","sourceRoot":"","sources":["../../src/clientCredentials.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyC;AAEzC,mEAA6D;AAC7D,yDAAqH;AACrH,yDAAkF;AAwClF,gFAAgF;AAChF,iEAAiE;AACjE,gFAAgF;AAEhF,SAAS,gBAAgB,CAAC,OAAiC;IACzD,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IAErC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAE/C,IAAI,OAAO,CAAC,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/D,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,OAAO,CAAC,eAAe;QAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACrF,IAAI,OAAO,CAAC,mBAAmB;QAAE,MAAM,CAAC,GAAG,CAAC,uBAAuB,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAClG,IAAI,OAAO,CAAC,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gFAAgF;AAChF,4BAA4B;AAC5B,gFAAgF;AAEhF,MAAa,uBAAuB;IAQlC,YAAY,MAAc,EAAE,OAAwC;;QAPpE,kDAAgB;QAChB,oDAAmB;QACnB,wDAAuB;QACvB,sDAAoC;QACpC,yDAA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uBAAA,IAAI,yCAAU,EAAE,YAAY,EAAE,uBAAA,IAAI,6CAAc,EAAE,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { TokenExchangeRequest } from "./tokenExchange.js";
|
|
2
|
+
/**
|
|
3
|
+
* The headers and form fields that authenticate the client on one request to
|
|
4
|
+
* the authorization server. Keys are wire names, such as `Authorization` or
|
|
5
|
+
* `client_assertion`. It never includes a grant parameter such as
|
|
6
|
+
* `grant_type` or `subject_token_type`. The caller merges it into its own
|
|
7
|
+
* request.
|
|
8
|
+
*/
|
|
9
|
+
export interface ClientAuthentication {
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
form: Record<string, string>;
|
|
12
|
+
}
|
|
2
13
|
/**
|
|
3
14
|
* Common interface for application-level credentials used in token exchange.
|
|
4
15
|
*
|
|
@@ -19,5 +30,29 @@ export interface ApplicationCredential {
|
|
|
19
30
|
authInfo?: Record<string, string>;
|
|
20
31
|
issuer?: string;
|
|
21
32
|
}): Promise<TokenExchangeRequest>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the client authentication for one request to `endpoint` on the
|
|
35
|
+
* zone `issuer`. Optional. Operations that need it throw
|
|
36
|
+
* `ConfigurationError` before any request when it is missing. Call it once
|
|
37
|
+
* per request: assertion-based credentials sign or fetch a new assertion on
|
|
38
|
+
* every call.
|
|
39
|
+
*/
|
|
40
|
+
clientAuthentication?(issuer: string, endpoint: string): Promise<ClientAuthentication>;
|
|
41
|
+
/**
|
|
42
|
+
* Throws `ConfigurationError` when the credential's configuration does not
|
|
43
|
+
* allow `clientAuthentication`, such as a `WebIdentity` without `clientId`.
|
|
44
|
+
* Optional.
|
|
45
|
+
*/
|
|
46
|
+
checkClientAuthentication?(): void;
|
|
22
47
|
}
|
|
48
|
+
/** An `ApplicationCredential` that provides `clientAuthentication`. */
|
|
49
|
+
export type ClientAuthenticator = ApplicationCredential & Required<Pick<ApplicationCredential, "clientAuthentication">>;
|
|
50
|
+
/** Reports whether `credential` provides `clientAuthentication`. */
|
|
51
|
+
export declare function providesClientAuthentication(credential: ApplicationCredential): credential is ClientAuthenticator;
|
|
52
|
+
/**
|
|
53
|
+
* Returns `credential` when it provides `clientAuthentication` and its
|
|
54
|
+
* `checkClientAuthentication` passes. Throws `ConfigurationError` otherwise.
|
|
55
|
+
* Call it before sending any request, including discovery.
|
|
56
|
+
*/
|
|
57
|
+
export declare function requireClientAuthentication(credential: ApplicationCredential, operation: string): ClientAuthenticator;
|
|
23
58
|
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC5E,2BAA2B,CACzB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACvF,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACjC;;;;;;OAMG;IACH,oBAAoB,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACvF;;;;OAIG;IACH,yBAAyB,CAAC,IAAI,IAAI,CAAC;CACpC;AAED,uEAAuE;AACvE,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,GACrD,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAEhE,oEAAoE;AACpE,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,qBAAqB,GAChC,UAAU,IAAI,mBAAmB,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,MAAM,GAChB,mBAAmB,CAQrB"}
|
package/dist/cjs/credentials.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.providesClientAuthentication = providesClientAuthentication;
|
|
4
|
+
exports.requireClientAuthentication = requireClientAuthentication;
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
/** Reports whether `credential` provides `clientAuthentication`. */
|
|
7
|
+
function providesClientAuthentication(credential) {
|
|
8
|
+
return typeof credential.clientAuthentication === "function";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns `credential` when it provides `clientAuthentication` and its
|
|
12
|
+
* `checkClientAuthentication` passes. Throws `ConfigurationError` otherwise.
|
|
13
|
+
* Call it before sending any request, including discovery.
|
|
14
|
+
*/
|
|
15
|
+
function requireClientAuthentication(credential, operation) {
|
|
16
|
+
if (!providesClientAuthentication(credential)) {
|
|
17
|
+
throw new errors_js_1.ConfigurationError(`${operation} requires a credential that provides clientAuthentication`);
|
|
18
|
+
}
|
|
19
|
+
credential.checkClientAuthentication?.();
|
|
20
|
+
return credential;
|
|
21
|
+
}
|
|
3
22
|
//# sourceMappingURL=credentials.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":";;AAqDA,oEAIC;AAOD,kEAWC;AA3ED,2CAAiD;AAoDjD,oEAAoE;AACpE,SAAgB,4BAA4B,CAC1C,UAAiC;IAEjC,OAAO,OAAO,UAAU,CAAC,oBAAoB,KAAK,UAAU,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,SAAgB,2BAA2B,CACzC,UAAiC,EACjC,SAAiB;IAEjB,IAAI,CAAC,4BAA4B,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,8BAAkB,CAC1B,GAAG,SAAS,2DAA2D,CACxE,CAAC;IACJ,CAAC;IACD,UAAU,CAAC,yBAAyB,EAAE,EAAE,CAAC;IACzC,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { type ApplicationCredential } from "./credentials.js";
|
|
2
|
+
import { type OAuthAuthorizationServerMetadata } from "./discovery.js";
|
|
3
|
+
import { type TokenResponse } from "./tokenExchange.js";
|
|
4
|
+
/**
|
|
5
|
+
* The time source and timer for the device grant. Inject a fake in tests so
|
|
6
|
+
* that `expiresAt` and the waits between polls do not depend on real time.
|
|
7
|
+
*/
|
|
8
|
+
export interface Clock {
|
|
9
|
+
/** The current time in milliseconds since the Unix epoch. */
|
|
10
|
+
now(): number;
|
|
11
|
+
/** Resolves after `ms` milliseconds. Rejects with `signal.reason` when `signal` aborts. */
|
|
12
|
+
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/** The real clock: `Date.now` and `setTimeout`. */
|
|
15
|
+
export declare const systemClock: Clock;
|
|
16
|
+
/**
|
|
17
|
+
* Options every device grant operation shares. Set exactly one of
|
|
18
|
+
* `credential` and `clientId`, and use the same one for every operation in
|
|
19
|
+
* a flow: the zone binds the device code to the client and how it
|
|
20
|
+
* authenticated.
|
|
21
|
+
*/
|
|
22
|
+
export type DeviceClientOptions = ({
|
|
23
|
+
/**
|
|
24
|
+
* Authenticates each request with the credential's
|
|
25
|
+
* `clientAuthentication`, called once per request with the URL of the
|
|
26
|
+
* endpoint the request goes to.
|
|
27
|
+
*/
|
|
28
|
+
credential: ApplicationCredential;
|
|
29
|
+
clientId?: never;
|
|
30
|
+
} | {
|
|
31
|
+
/** Public client. Sent as `client_id` in the body, with no other authentication. */
|
|
32
|
+
clientId: string;
|
|
33
|
+
credential?: never;
|
|
34
|
+
}) & {
|
|
35
|
+
/** Pre-discovered metadata. When set, no discovery request is made. */
|
|
36
|
+
metadata?: OAuthAuthorizationServerMetadata;
|
|
37
|
+
/** Aborting it rejects with `signal.reason`. No request is sent after the abort. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
/** Timeout in milliseconds for each request to the authorization server (default 10 seconds; 0 disables). */
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
};
|
|
42
|
+
export type RequestDeviceAuthorizationOptions = DeviceClientOptions & {
|
|
43
|
+
/** Sent as one space-joined `scope` parameter. */
|
|
44
|
+
scopes?: readonly string[];
|
|
45
|
+
/** RFC 8707 resource indicators, sent as one `resource` parameter each. */
|
|
46
|
+
resources?: readonly string[];
|
|
47
|
+
/** Sets `expiresAt`. Default: `systemClock`. */
|
|
48
|
+
clock?: Clock;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The device authorization response (RFC 8628 §3.2). A plain value: the
|
|
52
|
+
* caller may persist it and poll from another process that authenticates as
|
|
53
|
+
* the same client.
|
|
54
|
+
*/
|
|
55
|
+
export interface DeviceAuthorization {
|
|
56
|
+
/** The code the device polls with. NEVER show it to the person. */
|
|
57
|
+
deviceCode: string;
|
|
58
|
+
/** The code the person confirms. Always show it, so the person can compare it with the confirmation page. */
|
|
59
|
+
userCode: string;
|
|
60
|
+
/** Where the person enters `userCode`. */
|
|
61
|
+
verificationUri: string;
|
|
62
|
+
/** `verificationUri` with `userCode` filled in. Show it in place of `verificationUri` when it is set. */
|
|
63
|
+
verificationUriComplete?: string;
|
|
64
|
+
/** Lifetime of `deviceCode` and `userCode`, in seconds. */
|
|
65
|
+
expiresIn: number;
|
|
66
|
+
/** Minimum wait between polls, in seconds. 5 when the response omits it. */
|
|
67
|
+
interval: number;
|
|
68
|
+
/** The time the response was received plus `expiresIn`, in milliseconds since the Unix epoch, read from the clock. */
|
|
69
|
+
expiresAt: number;
|
|
70
|
+
}
|
|
71
|
+
export type PollDeviceTokenOptions = DeviceClientOptions & {
|
|
72
|
+
/** The response from `requestDeviceAuthorization`. `pollDeviceToken` reads only `deviceCode`. */
|
|
73
|
+
authorization: DeviceAuthorization;
|
|
74
|
+
};
|
|
75
|
+
export type WaitForDeviceTokenOptions = DeviceClientOptions & {
|
|
76
|
+
/** The response from `requestDeviceAuthorization`, or a copy persisted from it. */
|
|
77
|
+
authorization: DeviceAuthorization;
|
|
78
|
+
/**
|
|
79
|
+
* The wait in seconds before the first poll, and the starting interval.
|
|
80
|
+
* Default: `authorization.interval`. A value that is not a positive integer,
|
|
81
|
+
* or is below `authorization.interval`, throws `ConfigurationError`.
|
|
82
|
+
*/
|
|
83
|
+
interval?: number;
|
|
84
|
+
/** Reads the time for the expiry check and waits between polls. Default: `systemClock`. */
|
|
85
|
+
clock?: Clock;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Ask the zone for a device code and a user code (RFC 8628 §3.1).
|
|
89
|
+
*
|
|
90
|
+
* The SDK does not deliver the user code. Show the person
|
|
91
|
+
* `verificationUriComplete` when it is set, and `verificationUri`
|
|
92
|
+
* otherwise, together with `userCode`.
|
|
93
|
+
*
|
|
94
|
+
* Throws `ConfigurationError` before any request when the client options
|
|
95
|
+
* are not exactly one of `credential` and `clientId`, when the credential
|
|
96
|
+
* has no `clientAuthentication`, or when `metadata` is not set and `issuer`
|
|
97
|
+
* is not an http or https URL. Throws `ConfigurationError` before the
|
|
98
|
+
* device authorization request when the metadata has no
|
|
99
|
+
* `device_authorization_endpoint` or it is not an http or https URL. An error
|
|
100
|
+
* from the credential's `clientAuthentication` is thrown as is. Every other
|
|
101
|
+
* failure throws `DeviceGrantError`, including a failed discovery request.
|
|
102
|
+
* A response that is missing a required
|
|
103
|
+
* field, or has an `interval` that is not a positive integer, throws
|
|
104
|
+
* `DeviceGrantError` `invalid_response`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function requestDeviceAuthorization(issuer: string, options: RequestDeviceAuthorizationOptions): Promise<DeviceAuthorization>;
|
|
107
|
+
/**
|
|
108
|
+
* Poll the token endpoint once (RFC 8628 §3.4) with
|
|
109
|
+
* `authorization.deviceCode`. Returns the token once the person approves.
|
|
110
|
+
*
|
|
111
|
+
* Without `metadata`, each call discovers it first. If you call it in your
|
|
112
|
+
* own loop, fetch the metadata once with `fetchAuthorizationServerMetadata`
|
|
113
|
+
* and pass it to every poll. Also wait longer after a timeout or other
|
|
114
|
+
* network error (RFC 8628 §3.5).
|
|
115
|
+
*
|
|
116
|
+
* Throws `ConfigurationError` before any request when the client options
|
|
117
|
+
* are not exactly one of `credential` and `clientId`, when `authorization`
|
|
118
|
+
* has no `deviceCode`, or when `metadata` is not set and `issuer` is not an
|
|
119
|
+
* http or https URL. Throws `ConfigurationError` before the poll when the
|
|
120
|
+
* metadata has no `token_endpoint` or it is not an http or https URL. An
|
|
121
|
+
* error from the credential's `clientAuthentication` is thrown as is. Every
|
|
122
|
+
* other failure throws `DeviceGrantError`, including a failed discovery
|
|
123
|
+
* request, `authorization_pending`, and `slow_down`.
|
|
124
|
+
*/
|
|
125
|
+
export declare function pollDeviceToken(issuer: string, options: PollDeviceTokenOptions): Promise<TokenResponse>;
|
|
126
|
+
/**
|
|
127
|
+
* Poll until the person approves or denies the request, following
|
|
128
|
+
* RFC 8628 §3.5.
|
|
129
|
+
*
|
|
130
|
+
* - It waits the interval before each poll, including the first.
|
|
131
|
+
* - On `authorization_pending` it polls again.
|
|
132
|
+
* - On `slow_down` it adds 5 seconds to the interval for this poll and every later one.
|
|
133
|
+
* - On a network error, a timeout, an HTTP 5xx, or an HTTP 429 it stops and
|
|
134
|
+
* throws `DevicePollError`, also when the 5xx or 429 has an OAuth error
|
|
135
|
+
* body. It does not poll again. After a network error or a timeout, the
|
|
136
|
+
* error's `interval` is double the current interval.
|
|
137
|
+
* - On any other failure it stops and throws that error as is: a
|
|
138
|
+
* `DeviceGrantError` for any other OAuth error or HTTP error, or the error
|
|
139
|
+
* from the credential's `clientAuthentication`.
|
|
140
|
+
* - If the next poll would start after `authorization.expiresAt`, it stops
|
|
141
|
+
* without waiting or polling and throws `DeviceGrantError` with code
|
|
142
|
+
* `expired_token`.
|
|
143
|
+
*
|
|
144
|
+
* To resume after a `DevicePollError`, call it again before `expiresAt` with
|
|
145
|
+
* the same `authorization` and `interval` set to the error's `interval`.
|
|
146
|
+
*
|
|
147
|
+
* Polling again on `authorization_pending` and `slow_down` follows
|
|
148
|
+
* RFC 8628 §3.5 and is not a retry. `timeoutMs` bounds each request. It does
|
|
149
|
+
* not bound the waits or the whole loop, and it applies even when `signal`
|
|
150
|
+
* has a longer deadline.
|
|
151
|
+
*
|
|
152
|
+
* Throws `ConfigurationError` before any request when the client options
|
|
153
|
+
* are not exactly one of `credential` and `clientId`, when `authorization`
|
|
154
|
+
* has no `deviceCode`, no `expiresAt`, or an `interval` that is not a
|
|
155
|
+
* positive integer, when `interval` is not a positive integer or is below
|
|
156
|
+
* `authorization.interval`, or
|
|
157
|
+
* when `metadata` is not set and `issuer` is not an http or https URL. A
|
|
158
|
+
* failed discovery request throws `DeviceGrantError` before the first wait.
|
|
159
|
+
*
|
|
160
|
+
* When the device authorization request named more than one resource, the
|
|
161
|
+
* token is not for any one of them. NEVER store it as the token for one
|
|
162
|
+
* resource. To get a token for one resource, call `refreshAuthorization`
|
|
163
|
+
* with `resources` set to it.
|
|
164
|
+
*/
|
|
165
|
+
export declare function waitForDeviceToken(issuer: string, options: WaitForDeviceTokenOptions): Promise<TokenResponse>;
|
|
166
|
+
//# sourceMappingURL=deviceAuthorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceAuthorization.d.ts","sourceRoot":"","sources":["../../src/deviceAuthorization.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,qBAAqB,EAA4B,MAAM,kBAAkB,CAAC;AACrH,OAAO,EAAoC,KAAK,gCAAgC,EAAE,MAAM,gBAAgB,CAAC;AAEzG,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAUlF;;;GAGG;AACH,MAAM,WAAW,KAAK;IACpB,6DAA6D;IAC7D,GAAG,IAAI,MAAM,CAAC;IACd,2FAA2F;IAC3F,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED,mDAAmD;AACnD,eAAO,MAAM,WAAW,EAAE,KAkBzB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAC9B;IACE;;;;OAIG;IACH,UAAU,EAAE,qBAAqB,CAAC;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,oFAAoF;IACpF,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,KAAK,CAAC;CACpB,CACJ,GAAG;IACF,uEAAuE;IACvE,QAAQ,CAAC,EAAE,gCAAgC,CAAC;IAC5C,oFAAoF;IACpF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,6GAA6G;IAC7G,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,mBAAmB,GAAG;IACpE,kDAAkD;IAClD,MAAM,CAAC,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