axiam-sdk 1.1.0 → 1.1.2
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 +27 -2
- package/dist/amqp/index.d.cts +3 -2
- package/dist/amqp/index.d.ts +3 -2
- package/dist/{authzCore-BQfX9qxN.d.cts → authzCore-CqXzLNmT.d.cts} +4 -3
- package/dist/{authzCore-BlSHwGnW.d.ts → authzCore-D-hquWSI.d.ts} +4 -3
- package/dist/browser/index.d.cts +8 -7
- package/dist/browser/index.d.ts +8 -7
- package/dist/{client-7ZKtfXW-.d.cts → client-BGFn1VQh.d.cts} +34 -24
- package/dist/{client-Putxo-yi.d.ts → client-DrQZZ1js.d.ts} +34 -24
- package/dist/{cookieJar-Cw6Zdeec.d.ts → cookieJar-BTmpjXZe.d.ts} +9 -3
- package/dist/{cookieJar-DkGcIr-i.d.cts → cookieJar-BqYOnNN-.d.cts} +9 -3
- package/dist/{errors-DMIlw2lN.d.ts → errors-DZ3k8a8i.d.cts} +2 -1
- package/dist/{errors-DMIlw2lN.d.cts → errors-DZ3k8a8i.d.ts} +2 -1
- package/dist/{errors-VpViVRSx.d.ts → errors-RvGlTyUj.d.cts} +3 -2
- package/dist/{errors-CtP_lviy.d.cts → errors-dlGXAsbh.d.ts} +3 -2
- package/dist/grpc/index.d.cts +10 -9
- package/dist/grpc/index.d.ts +10 -9
- package/dist/grpc/index.js +68 -7
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +68 -7
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +60 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{jwks-BR55d7-Z.d.cts → jwks-CTVpOWzI.d.cts} +2 -1
- package/dist/{jwks-BR55d7-Z.d.ts → jwks-CTVpOWzI.d.ts} +2 -1
- package/dist/middleware/index.d.cts +13 -12
- package/dist/middleware/index.d.ts +13 -12
- package/dist/middleware/index.js +176 -31
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +176 -31
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +5 -4
- package/dist/nestjs/index.d.ts +5 -4
- package/dist/node/index.d.cts +10 -9
- package/dist/node/index.d.ts +10 -9
- package/dist/node/index.js +215 -29
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +215 -29
- package/dist/node/index.mjs.map +1 -1
- package/dist/{oidcState-Cz6erz0g.d.cts → oidcState-BaJ-SM_R.d.cts} +41 -9
- package/dist/{oidcState-zGt6VU6v.d.ts → oidcState-C3VLn3eD.d.ts} +41 -9
- package/dist/rest/index.d.cts +10 -9
- package/dist/rest/index.d.ts +10 -9
- package/dist/rest/index.js +60 -7
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +60 -7
- package/dist/rest/index.mjs.map +1 -1
- package/dist/{revocationFeed-CDoD7Twr.d.cts → revocationFeed-KQhvMMl8.d.cts} +2 -1
- package/dist/{revocationFeed-CDoD7Twr.d.ts → revocationFeed-KQhvMMl8.d.ts} +2 -1
- package/dist/{session-CeG6P9GO.d.ts → session-B03NsqVs.d.ts} +19 -2
- package/dist/{session-BmjEMowX.d.cts → session-plDr4lFu.d.cts} +19 -2
- package/dist/{telemetry--0DwnNjV.d.cts → telemetry-Du0-zS5f.d.cts} +2 -1
- package/dist/{telemetry--0DwnNjV.d.ts → telemetry-Du0-zS5f.d.ts} +2 -1
- package/dist/{webauthnErrors-fLgfOflO.d.cts → webauthnErrors-m1LZiaRy.d.cts} +2 -1
- package/dist/{webauthnErrors-fLgfOflO.d.ts → webauthnErrors-m1LZiaRy.d.ts} +2 -1
- package/package.json +2 -2
|
@@ -521,7 +521,7 @@ function protectedResourceMetadata(options) {
|
|
|
521
521
|
if (documentation !== void 0) {
|
|
522
522
|
requireAbsoluteUri(op, "resource_documentation", documentation, LOCATOR);
|
|
523
523
|
}
|
|
524
|
-
const
|
|
524
|
+
const document2 = Object.freeze({
|
|
525
525
|
resource,
|
|
526
526
|
authorization_servers: Object.freeze(authorizationServers),
|
|
527
527
|
...scopesSupported.length > 0 ? { scopes_supported: Object.freeze(scopesSupported) } : {},
|
|
@@ -530,7 +530,7 @@ function protectedResourceMetadata(options) {
|
|
|
530
530
|
});
|
|
531
531
|
const metadataPath = deriveMetadataPath(parsed.path);
|
|
532
532
|
return Object.freeze({
|
|
533
|
-
document,
|
|
533
|
+
document: document2,
|
|
534
534
|
metadataPath,
|
|
535
535
|
metadataUrl: `${parsed.scheme}://${parsed.authority}${metadataPath}`
|
|
536
536
|
});
|
|
@@ -1388,6 +1388,24 @@ function retryableNetworkError(message, response) {
|
|
|
1388
1388
|
return error;
|
|
1389
1389
|
}
|
|
1390
1390
|
|
|
1391
|
+
// src/rest/interceptors.ts
|
|
1392
|
+
function isOAuth2Endpoint(url, baseUrl) {
|
|
1393
|
+
if (!url) {
|
|
1394
|
+
return false;
|
|
1395
|
+
}
|
|
1396
|
+
try {
|
|
1397
|
+
const base = new URL(baseUrl);
|
|
1398
|
+
let path = new URL(url, base).pathname;
|
|
1399
|
+
const prefix = base.pathname.replace(/\/+$/, "");
|
|
1400
|
+
if (prefix !== "" && path.startsWith(`${prefix}/`)) {
|
|
1401
|
+
path = path.slice(prefix.length);
|
|
1402
|
+
}
|
|
1403
|
+
return path.startsWith("/oauth2/");
|
|
1404
|
+
} catch {
|
|
1405
|
+
return false;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1391
1409
|
// src/rest/retry.ts
|
|
1392
1410
|
var MAX_ATTEMPTS = 3;
|
|
1393
1411
|
var BASE_DELAY_MS = 200;
|
|
@@ -1406,7 +1424,7 @@ function delayMs(attempt, retryAfterMs2, fraction) {
|
|
|
1406
1424
|
return retryAfterMs2 === void 0 ? jittered : Math.max(jittered, retryAfterMs2);
|
|
1407
1425
|
}
|
|
1408
1426
|
async function withRetry(fn, options) {
|
|
1409
|
-
const retryable = options.enabled !== false;
|
|
1427
|
+
const retryable = options.idempotent && options.enabled !== false;
|
|
1410
1428
|
const maxAttempts = retryable ? MAX_ATTEMPTS : 1;
|
|
1411
1429
|
const sleep2 = options.sleepFn ?? defaultSleep;
|
|
1412
1430
|
const random = options.randomFn ?? Math.random;
|
|
@@ -1420,6 +1438,7 @@ async function withRetry(fn, options) {
|
|
|
1420
1438
|
}
|
|
1421
1439
|
const retryAfterMs2 = isRetryAfterCarrier(err) ? err.retryAfterMs : void 0;
|
|
1422
1440
|
const delay = delayMs(attempt, retryAfterMs2, random());
|
|
1441
|
+
options.admit?.(delay);
|
|
1423
1442
|
options.telemetry?.emit({
|
|
1424
1443
|
type: "retry",
|
|
1425
1444
|
operation: options.operation ?? "unknown",
|
|
@@ -1482,6 +1501,8 @@ var MAX_LOGOUT_TOKEN_AGE_SECS = 300;
|
|
|
1482
1501
|
var PollSchedule = class {
|
|
1483
1502
|
#intervalSecs;
|
|
1484
1503
|
#remainingSecs;
|
|
1504
|
+
/** A `Retry-After` still to be served by the next wait (§14.2 rule 9, contract 1.64). */
|
|
1505
|
+
#retryAfterSecs = 0;
|
|
1485
1506
|
constructor(intervalSecs, expiresInSecs) {
|
|
1486
1507
|
this.#intervalSecs = intervalSecs > 0 ? intervalSecs : DEFAULT_POLL_INTERVAL_SECS;
|
|
1487
1508
|
this.#remainingSecs = expiresInSecs;
|
|
@@ -1490,6 +1511,21 @@ var PollSchedule = class {
|
|
|
1490
1511
|
get intervalSecs() {
|
|
1491
1512
|
return this.#intervalSecs;
|
|
1492
1513
|
}
|
|
1514
|
+
/**
|
|
1515
|
+
* The delay before the next poll, in seconds: the interval, or the pending
|
|
1516
|
+
* `Retry-After` when that is longer (a minimum, §14.2 rule 9).
|
|
1517
|
+
*/
|
|
1518
|
+
get waitSecs() {
|
|
1519
|
+
return Math.max(this.#intervalSecs, this.#retryAfterSecs);
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Record a `429 rate_limit_exceeded` (§14.2 rule 9, contract 1.64): the next
|
|
1523
|
+
* wait lasts at least `retryAfterSecs` and stands in for one interval. The
|
|
1524
|
+
* interval itself is **not** raised — only the `400 slow_down` does that.
|
|
1525
|
+
*/
|
|
1526
|
+
rateLimited(retryAfterSecs) {
|
|
1527
|
+
this.#retryAfterSecs = retryAfterSecs !== void 0 && retryAfterSecs > 0 ? retryAfterSecs : 0;
|
|
1528
|
+
}
|
|
1493
1529
|
/** Apply one `slow_down` (§14.2 rule 1): **cumulative, never reset.** */
|
|
1494
1530
|
slowDown() {
|
|
1495
1531
|
this.#intervalSecs += SLOW_DOWN_INCREMENT_SECS;
|
|
@@ -1502,14 +1538,27 @@ var PollSchedule = class {
|
|
|
1502
1538
|
* the server is still answering `authorization_pending`.
|
|
1503
1539
|
*/
|
|
1504
1540
|
tick() {
|
|
1505
|
-
|
|
1541
|
+
const waitSecs = this.waitSecs;
|
|
1542
|
+
this.#retryAfterSecs = 0;
|
|
1543
|
+
if (waitSecs >= this.#remainingSecs) {
|
|
1506
1544
|
this.#remainingSecs = 0;
|
|
1507
1545
|
return false;
|
|
1508
1546
|
}
|
|
1509
|
-
this.#remainingSecs -=
|
|
1547
|
+
this.#remainingSecs -= waitSecs;
|
|
1510
1548
|
return true;
|
|
1511
1549
|
}
|
|
1512
1550
|
};
|
|
1551
|
+
var POLL_RETRY_AFTER_MS = /* @__PURE__ */ new WeakMap();
|
|
1552
|
+
function pollRateLimit(err) {
|
|
1553
|
+
if (axiosStatus(err) !== 429) return void 0;
|
|
1554
|
+
const body = axiosBody(err);
|
|
1555
|
+
const description = body !== null && typeof body === "object" && typeof body.error_description === "string" ? body.error_description : "";
|
|
1556
|
+
const limited = new OAuthProtocolError("rate_limit_exceeded", description);
|
|
1557
|
+
const response = err.response;
|
|
1558
|
+
const retryAfter = response ? retryAfterMs(response) : void 0;
|
|
1559
|
+
if (retryAfter !== void 0) POLL_RETRY_AFTER_MS.set(limited, retryAfter);
|
|
1560
|
+
return limited;
|
|
1561
|
+
}
|
|
1513
1562
|
function sleep(ms) {
|
|
1514
1563
|
return new Promise((resolve) => {
|
|
1515
1564
|
setTimeout(resolve, ms);
|
|
@@ -1543,9 +1592,9 @@ var DiscoveryCache = class {
|
|
|
1543
1592
|
if (pending) {
|
|
1544
1593
|
return pending;
|
|
1545
1594
|
}
|
|
1546
|
-
const fetch = fetcher().then((
|
|
1547
|
-
this.#documents.set(originKey, { document, expiresAt: Date.now() + this.#ttlMs });
|
|
1548
|
-
return
|
|
1595
|
+
const fetch = fetcher().then((document2) => {
|
|
1596
|
+
this.#documents.set(originKey, { document: document2, expiresAt: Date.now() + this.#ttlMs });
|
|
1597
|
+
return document2;
|
|
1549
1598
|
}).finally(() => {
|
|
1550
1599
|
this.#inFlight.delete(originKey);
|
|
1551
1600
|
});
|
|
@@ -1643,6 +1692,19 @@ function transient(error) {
|
|
|
1643
1692
|
return error;
|
|
1644
1693
|
}
|
|
1645
1694
|
var SYSTEM_CIBA_CLOCK = { now: () => Date.now(), sleep };
|
|
1695
|
+
function deadlineBoundedRetry(bound, what) {
|
|
1696
|
+
return {
|
|
1697
|
+
admit: (ms) => {
|
|
1698
|
+
if (bound.clock.now() + ms >= bound.deadline) {
|
|
1699
|
+
throw new OAuthProtocolError(
|
|
1700
|
+
"expired_token",
|
|
1701
|
+
`the ${what} expired before it was decided (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4, \xA734.2 P10)`
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
},
|
|
1705
|
+
sleepFn: (ms) => bound.clock.sleep(ms)
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1646
1708
|
function isAccessDenied(err) {
|
|
1647
1709
|
return err instanceof OAuthProtocolError && err.error === "access_denied";
|
|
1648
1710
|
}
|
|
@@ -2427,26 +2489,36 @@ var OidcClient = class {
|
|
|
2427
2489
|
* The raw single call, so an application driving its own loop (a UI
|
|
2428
2490
|
* rendering a countdown, say) can. The five RFC 8628 §3.5 answers surface as
|
|
2429
2491
|
* {@link OAuthProtocolError} — `authorization_pending` and `slow_down`
|
|
2430
|
-
* included — so a hand-rolled loop
|
|
2431
|
-
*
|
|
2492
|
+
* included — so a hand-rolled loop dispatches on the same answers
|
|
2493
|
+
* {@link deviceLogin} does. Most callers want {@link deviceLogin}.
|
|
2432
2494
|
*
|
|
2433
2495
|
* Client authentication is the one {@link deviceAuthorize} describes
|
|
2434
2496
|
* (contract 1.62, §14.1 rule 2): a configured `clientSecret` is sent as
|
|
2435
2497
|
* `client_secret` in the form body, never as `Authorization: Basic`; a public
|
|
2436
2498
|
* client sends none; `client_id` is sent on **every** poll (§14.1 rule 3). A
|
|
2437
2499
|
* `401 invalid_client` surfaces as {@link OAuthProtocolError}, is not retried
|
|
2438
|
-
* and does not enter the §9 refresh guard (§14.2 rule 5).
|
|
2500
|
+
* and does not enter the §9 refresh guard (§14.2 rule 5). Any `429`
|
|
2501
|
+
* is an {@link OAuthProtocolError} with `error == 'rate_limit_exceeded'` too
|
|
2502
|
+
* (rule 9, whatever its body names) — never `slow_down`; {@link deviceLogin}
|
|
2503
|
+
* waits it out. Its `Retry-After` is not exposed, so a hand-rolled loop
|
|
2504
|
+
* should wait at least one interval on it without raising the interval, or
|
|
2505
|
+
* use {@link deviceLogin}. This SDK ships no
|
|
2439
2506
|
* DPoP proof generator, so it cannot drive a client registered for DPoP; it
|
|
2440
2507
|
* surfaces that client's refusal as the same `invalid_client`.
|
|
2441
2508
|
*/
|
|
2442
2509
|
async devicePoll(params) {
|
|
2510
|
+
return this.#devicePoll(params, void 0);
|
|
2511
|
+
}
|
|
2512
|
+
/** {@link devicePoll}; `bound` is the loop's deadline, which a §16 retry inside the poll must not pass. */
|
|
2513
|
+
async #devicePoll(params, bound) {
|
|
2443
2514
|
const configuration = params.configuration ?? await this.oidcDiscover();
|
|
2444
2515
|
const form = new URLSearchParams();
|
|
2445
2516
|
form.set("grant_type", DEVICE_CODE_GRANT_TYPE);
|
|
2446
2517
|
form.set("device_code", exposeSecret(params.deviceCode));
|
|
2447
2518
|
form.set("client_id", this.#options.clientId);
|
|
2448
2519
|
this.#appendClientSecret(form);
|
|
2449
|
-
const
|
|
2520
|
+
const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), params.tenantId);
|
|
2521
|
+
const wire = await this.#postDevicePoll(url, form, bound);
|
|
2450
2522
|
return this.#toTokenSet(wire, configuration, void 0);
|
|
2451
2523
|
}
|
|
2452
2524
|
/**
|
|
@@ -2467,31 +2539,44 @@ var OidcClient = class {
|
|
|
2467
2539
|
* even if the server has not yet said `expired_token`. A 5xx or transport
|
|
2468
2540
|
* failure mid-poll is **not** terminal (rule 6) — the loop absorbs it and
|
|
2469
2541
|
* tries again, bounded by the same deadline, because a server restart must
|
|
2470
|
-
* not lose a grant the user has already approved
|
|
2542
|
+
* not lose a grant the user has already approved: that bound holds for the
|
|
2543
|
+
* §16 retry inside a poll too, whose waits are served on the loop's clock and
|
|
2544
|
+
* never reach the deadline (`Retry-After` included; the typed `expired_token`
|
|
2545
|
+
* is raised at once, C164-36). A `429
|
|
2546
|
+
* rate_limit_exceeded` (rule 9, contract 1.64) is not terminal either: the
|
|
2547
|
+
* loop waits `Retry-After` as a minimum (capped at the `expires_in`
|
|
2548
|
+
* deadline), counts the wait as one interval, does **not** raise the
|
|
2549
|
+
* interval, and polls again.
|
|
2471
2550
|
*/
|
|
2472
2551
|
async deviceLogin(params) {
|
|
2473
2552
|
const configuration = params.configuration ?? await this.oidcDiscover();
|
|
2553
|
+
const clock = params.clock ?? SYSTEM_CIBA_CLOCK;
|
|
2474
2554
|
const authorization = await this.deviceAuthorize({
|
|
2475
2555
|
...params.scope !== void 0 ? { scope: params.scope } : {},
|
|
2476
2556
|
...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
|
|
2477
2557
|
configuration
|
|
2478
2558
|
});
|
|
2559
|
+
const deadline = clock.now() + authorization.expiresIn * 1e3;
|
|
2479
2560
|
await params.onUserCode(authorization);
|
|
2480
2561
|
const schedule = new PollSchedule(authorization.interval, authorization.expiresIn);
|
|
2481
2562
|
for (; ; ) {
|
|
2482
|
-
|
|
2563
|
+
const waitSecs = schedule.waitSecs;
|
|
2564
|
+
if (!schedule.tick() || clock.now() + waitSecs * 1e3 >= deadline) {
|
|
2483
2565
|
throw new OAuthProtocolError(
|
|
2484
2566
|
"expired_token",
|
|
2485
2567
|
"the device authorization expired before the user completed it (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4)"
|
|
2486
2568
|
);
|
|
2487
2569
|
}
|
|
2488
|
-
await sleep(
|
|
2570
|
+
await clock.sleep(waitSecs * 1e3);
|
|
2489
2571
|
try {
|
|
2490
|
-
return await this
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2572
|
+
return await this.#devicePoll(
|
|
2573
|
+
{
|
|
2574
|
+
deviceCode: authorization.deviceCode,
|
|
2575
|
+
...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
|
|
2576
|
+
configuration
|
|
2577
|
+
},
|
|
2578
|
+
{ deadline, clock }
|
|
2579
|
+
);
|
|
2495
2580
|
} catch (err) {
|
|
2496
2581
|
if (err instanceof OAuthProtocolError) {
|
|
2497
2582
|
if (err.error === "authorization_pending") {
|
|
@@ -2501,6 +2586,11 @@ var OidcClient = class {
|
|
|
2501
2586
|
schedule.slowDown();
|
|
2502
2587
|
continue;
|
|
2503
2588
|
}
|
|
2589
|
+
if (err.error === "rate_limit_exceeded") {
|
|
2590
|
+
const pollWaitMs = POLL_RETRY_AFTER_MS.get(err);
|
|
2591
|
+
schedule.rateLimited(pollWaitMs === void 0 ? void 0 : pollWaitMs / 1e3);
|
|
2592
|
+
continue;
|
|
2593
|
+
}
|
|
2504
2594
|
throw err;
|
|
2505
2595
|
}
|
|
2506
2596
|
if (err instanceof NetworkError) {
|
|
@@ -3021,6 +3111,10 @@ var OidcClient = class {
|
|
|
3021
3111
|
* this client's credential.
|
|
3022
3112
|
*/
|
|
3023
3113
|
async cibaPoll(params) {
|
|
3114
|
+
return this.#cibaPoll(params, void 0);
|
|
3115
|
+
}
|
|
3116
|
+
/** {@link cibaPoll}; `bound` is `cibaAwait`'s deadline, which a §16 retry inside the poll must not pass. */
|
|
3117
|
+
async #cibaPoll(params, bound) {
|
|
3024
3118
|
const operation = "ciba_poll";
|
|
3025
3119
|
const auth = this.#cibaClientAuth(operation);
|
|
3026
3120
|
const configuration = params.configuration ?? await this.oidcDiscover();
|
|
@@ -3051,9 +3145,11 @@ var OidcClient = class {
|
|
|
3051
3145
|
return { error: mapHttpStatusToError(response.status, `${operation}: HTTP ${response.status}`) };
|
|
3052
3146
|
},
|
|
3053
3147
|
{
|
|
3148
|
+
idempotent: true,
|
|
3054
3149
|
operation,
|
|
3055
3150
|
enabled: this.#session.retryEnabled,
|
|
3056
|
-
telemetry: this.#session.telemetry.dispatcher
|
|
3151
|
+
telemetry: this.#session.telemetry.dispatcher,
|
|
3152
|
+
...bound !== void 0 ? deadlineBoundedRetry(bound, "CIBA request") : {}
|
|
3057
3153
|
}
|
|
3058
3154
|
);
|
|
3059
3155
|
if (outcome.error) throw outcome.error;
|
|
@@ -3073,7 +3169,9 @@ var OidcClient = class {
|
|
|
3073
3169
|
* the interval and polls again.
|
|
3074
3170
|
* - Polling stops at `receivedAt + expiresIn`, even if the server has not
|
|
3075
3171
|
* said `expired_token`: when the next wait would reach the deadline, the
|
|
3076
|
-
* same `expired_token` is raised locally, without a request.
|
|
3172
|
+
* same `expired_token` is raised locally, without a request. A §16 retry
|
|
3173
|
+
* inside {@link cibaPoll} is bounded the same way (§34.2 P10): a wait that
|
|
3174
|
+
* would reach the deadline is not served and nothing is sent after it.
|
|
3077
3175
|
* - `access_denied`, `expired_token`, `invalid_grant` and any other answer
|
|
3078
3176
|
* end the loop.
|
|
3079
3177
|
*
|
|
@@ -3101,11 +3199,14 @@ var OidcClient = class {
|
|
|
3101
3199
|
}
|
|
3102
3200
|
await clock.sleep(waitMs);
|
|
3103
3201
|
try {
|
|
3104
|
-
return await this
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3202
|
+
return await this.#cibaPoll(
|
|
3203
|
+
{
|
|
3204
|
+
authReqId: initiated.authReqId,
|
|
3205
|
+
configuration,
|
|
3206
|
+
...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {}
|
|
3207
|
+
},
|
|
3208
|
+
{ deadline, clock }
|
|
3209
|
+
);
|
|
3109
3210
|
} catch (err) {
|
|
3110
3211
|
if (err instanceof OAuthProtocolError) {
|
|
3111
3212
|
if (err.error === "authorization_pending" || err.error === "rate_limit_exceeded") continue;
|
|
@@ -3201,6 +3302,46 @@ var OidcClient = class {
|
|
|
3201
3302
|
throw transient(new NetworkError(`${operation}: the request failed before any response arrived${code}`));
|
|
3202
3303
|
}
|
|
3203
3304
|
}
|
|
3305
|
+
/**
|
|
3306
|
+
* One device-poll attempt under §16 (CONTRACT.md §14.2 rule 6, §16.2; C164-25): a `5xx` or
|
|
3307
|
+
* a transport failure is retried **inside** the poll (three requests in all, the `Retry-After`
|
|
3308
|
+
* a floor) before it surfaces as a `NetworkError`; the loop then takes its next interval. A
|
|
3309
|
+
* `429` is never retried here — it is rule 9's wait, the loop's — nor is any answer the
|
|
3310
|
+
* server decided (`400`, `401`).
|
|
3311
|
+
*/
|
|
3312
|
+
async #postDevicePoll(url, form, bound) {
|
|
3313
|
+
const operation = "device_poll";
|
|
3314
|
+
const outcome = await withRetry(
|
|
3315
|
+
async () => {
|
|
3316
|
+
try {
|
|
3317
|
+
const response = await this.#session.axios.post(url, form.toString(), {
|
|
3318
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
3319
|
+
});
|
|
3320
|
+
return { wire: response.data };
|
|
3321
|
+
} catch (err) {
|
|
3322
|
+
if (err instanceof AxiamError) return { error: err };
|
|
3323
|
+
const status = axiosStatus(err);
|
|
3324
|
+
const response = err.response;
|
|
3325
|
+
if (status === void 0) {
|
|
3326
|
+
throw new NetworkError(`${operation}: the request failed before any response arrived`, sanitizeAxiosError(err));
|
|
3327
|
+
}
|
|
3328
|
+
if (status >= 500) {
|
|
3329
|
+
throw retryableNetworkError(`${operation}: HTTP ${status}`, response);
|
|
3330
|
+
}
|
|
3331
|
+
return { error: pollRateLimit(err) ?? mapOidcError(err, url, "token request failed") };
|
|
3332
|
+
}
|
|
3333
|
+
},
|
|
3334
|
+
{
|
|
3335
|
+
idempotent: true,
|
|
3336
|
+
operation,
|
|
3337
|
+
enabled: this.#session.retryEnabled,
|
|
3338
|
+
telemetry: this.#session.telemetry.dispatcher,
|
|
3339
|
+
...bound !== void 0 ? deadlineBoundedRetry(bound, "device authorization") : {}
|
|
3340
|
+
}
|
|
3341
|
+
);
|
|
3342
|
+
if (outcome.error) throw outcome.error;
|
|
3343
|
+
return outcome.wire;
|
|
3344
|
+
}
|
|
3204
3345
|
/** POST a form body to the token endpoint from the discovery document. */
|
|
3205
3346
|
async #postToken(configuration, form, tenantId) {
|
|
3206
3347
|
const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), tenantId);
|
|
@@ -3363,7 +3504,7 @@ var OidcClient = class {
|
|
|
3363
3504
|
this.#session.axios.interceptors.request.use((config) => {
|
|
3364
3505
|
const adopted = this.#adoptedCredential;
|
|
3365
3506
|
const url = config.url ?? "";
|
|
3366
|
-
if (!adopted || this.#session.isForeignHost(url) || url.
|
|
3507
|
+
if (!adopted || this.#session.isForeignHost(url) || isOAuth2Endpoint(url, this.#session.baseUrl)) {
|
|
3367
3508
|
return config;
|
|
3368
3509
|
}
|
|
3369
3510
|
config.headers = config.headers ?? {};
|
|
@@ -3387,6 +3528,10 @@ var OidcClient = class {
|
|
|
3387
3528
|
try {
|
|
3388
3529
|
return await this.#session.axios.post(url, form.toString(), config);
|
|
3389
3530
|
} catch (err) {
|
|
3531
|
+
if (axiosStatus(err) === 429) {
|
|
3532
|
+
const protocol = oauth2ErrorFromBody(axiosBody(err));
|
|
3533
|
+
if (protocol) throw protocol;
|
|
3534
|
+
}
|
|
3390
3535
|
throw mapOidcError(err, url, fallbackMessage);
|
|
3391
3536
|
}
|
|
3392
3537
|
}
|
|
@@ -3535,11 +3680,11 @@ var RevocationFeed = class _RevocationFeed {
|
|
|
3535
3680
|
if (!response.ok) {
|
|
3536
3681
|
return void 0;
|
|
3537
3682
|
}
|
|
3538
|
-
const
|
|
3539
|
-
if (typeof
|
|
3683
|
+
const document2 = await response.json();
|
|
3684
|
+
if (typeof document2 !== "object" || document2 === null) {
|
|
3540
3685
|
return void 0;
|
|
3541
3686
|
}
|
|
3542
|
-
const { alg, revoked } =
|
|
3687
|
+
const { alg, revoked } = document2;
|
|
3543
3688
|
if (alg !== SUPPORTED_ALG) {
|
|
3544
3689
|
return void 0;
|
|
3545
3690
|
}
|