axiam-sdk 1.1.1 → 1.1.3
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 +20 -4
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/{client-D34sXV8p.d.cts → client-BGFn1VQh.d.cts} +7 -1
- package/dist/{client-BMNQi36J.d.ts → client-DrQZZ1js.d.ts} +7 -1
- package/dist/{cookieJar-DcrMe93Q.d.ts → cookieJar-BTmpjXZe.d.ts} +8 -2
- package/dist/{cookieJar-C_xPuniu.d.cts → cookieJar-BqYOnNN-.d.cts} +8 -2
- package/dist/grpc/index.d.cts +4 -4
- package/dist/grpc/index.d.ts +4 -4
- package/dist/grpc/index.js +32 -2
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +32 -2
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/index.d.cts +3 -3
- package/dist/middleware/index.d.ts +3 -3
- package/dist/middleware/index.js +149 -22
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +149 -22
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/node/index.d.cts +3 -3
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.js +178 -23
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +178 -23
- package/dist/node/index.mjs.map +1 -1
- package/dist/{oidcState-BFIHt7_Y.d.cts → oidcState-BaJ-SM_R.d.cts} +37 -6
- package/dist/{oidcState-qoy2vsYG.d.ts → oidcState-C3VLn3eD.d.ts} +37 -6
- package/dist/rest/index.d.cts +3 -3
- package/dist/rest/index.d.ts +3 -3
- package/dist/rest/index.js +24 -2
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +24 -2
- package/dist/rest/index.mjs.map +1 -1
- package/dist/{session-BbPFTpMZ.d.ts → session-B03NsqVs.d.ts} +16 -0
- package/dist/{session-C9WlP6DV.d.cts → session-plDr4lFu.d.cts} +16 -0
- package/package.json +18 -18
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, RequestHandler, Router } from 'express';
|
|
2
2
|
import { a as AuthzLogger, E as ErrorBody, b as AxiamIdentity, V as VerifiableSession, A as AuthzVerifiableSession, c as ResourceSpec, R as RequireAccessOptions } from '../authzCore-CqXzLNmT.cjs';
|
|
3
3
|
export { d as AuthzChecker, C as CheckOutcome, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, U as UmaChallenger, h as UmaTicketMinter, i as assertAuthzClient, j as authenticateRequest, k as evaluateAccess, l as fromParam, m as hasAnyRole, r as resolveResourceId } from '../authzCore-CqXzLNmT.cjs';
|
|
4
|
-
import { P as OidcClient, W as OidcStateStore, X as OidcTokenSet, V as OidcStateEntry } from '../oidcState-
|
|
5
|
-
export { a as AuthorizationRequest, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, L as LoginClientCredentialsParams, y as LogoutUrlParams, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, an as TokenExchangeParams, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken } from '../oidcState-
|
|
4
|
+
import { P as OidcClient, W as OidcStateStore, X as OidcTokenSet, V as OidcStateEntry } from '../oidcState-BaJ-SM_R.cjs';
|
|
5
|
+
export { a as AuthorizationRequest, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, L as LoginClientCredentialsParams, y as LogoutUrlParams, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, an as TokenExchangeParams, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken } from '../oidcState-BaJ-SM_R.cjs';
|
|
6
6
|
import { FastifyRequest, FastifyReply, FastifyPluginAsync, FastifyInstance } from 'fastify';
|
|
7
7
|
export { F as FieldError, V as ValidationError } from '../errors-RvGlTyUj.cjs';
|
|
8
8
|
import { P as PresentedProofs } from '../jwks-CTVpOWzI.cjs';
|
|
@@ -12,7 +12,7 @@ import '../sensitive-BC_s7Rrd.cjs';
|
|
|
12
12
|
import '../types-zXSpiQM-.cjs';
|
|
13
13
|
import 'node:crypto';
|
|
14
14
|
import '../errors-DZ3k8a8i.cjs';
|
|
15
|
-
import '../session-
|
|
15
|
+
import '../session-plDr4lFu.cjs';
|
|
16
16
|
import 'axios';
|
|
17
17
|
import '../telemetry-Du0-zS5f.cjs';
|
|
18
18
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, RequestHandler, Router } from 'express';
|
|
2
2
|
import { a as AuthzLogger, E as ErrorBody, b as AxiamIdentity, V as VerifiableSession, A as AuthzVerifiableSession, c as ResourceSpec, R as RequireAccessOptions } from '../authzCore-D-hquWSI.js';
|
|
3
3
|
export { d as AuthzChecker, C as CheckOutcome, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, U as UmaChallenger, h as UmaTicketMinter, i as assertAuthzClient, j as authenticateRequest, k as evaluateAccess, l as fromParam, m as hasAnyRole, r as resolveResourceId } from '../authzCore-D-hquWSI.js';
|
|
4
|
-
import { P as OidcClient, W as OidcStateStore, X as OidcTokenSet, V as OidcStateEntry } from '../oidcState-
|
|
5
|
-
export { a as AuthorizationRequest, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, L as LoginClientCredentialsParams, y as LogoutUrlParams, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, an as TokenExchangeParams, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken } from '../oidcState-
|
|
4
|
+
import { P as OidcClient, W as OidcStateStore, X as OidcTokenSet, V as OidcStateEntry } from '../oidcState-C3VLn3eD.js';
|
|
5
|
+
export { a as AuthorizationRequest, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, L as LoginClientCredentialsParams, y as LogoutUrlParams, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, an as TokenExchangeParams, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken } from '../oidcState-C3VLn3eD.js';
|
|
6
6
|
import { FastifyRequest, FastifyReply, FastifyPluginAsync, FastifyInstance } from 'fastify';
|
|
7
7
|
export { F as FieldError, V as ValidationError } from '../errors-dlGXAsbh.js';
|
|
8
8
|
import { P as PresentedProofs } from '../jwks-CTVpOWzI.js';
|
|
@@ -12,7 +12,7 @@ import '../sensitive-BC_s7Rrd.js';
|
|
|
12
12
|
import '../types-BOX-6Srv.js';
|
|
13
13
|
import 'node:crypto';
|
|
14
14
|
import '../errors-DZ3k8a8i.js';
|
|
15
|
-
import '../session-
|
|
15
|
+
import '../session-B03NsqVs.js';
|
|
16
16
|
import 'axios';
|
|
17
17
|
import '../telemetry-Du0-zS5f.js';
|
|
18
18
|
|
package/dist/middleware/index.js
CHANGED
|
@@ -1426,7 +1426,7 @@ function delayMs(attempt, retryAfterMs2, fraction) {
|
|
|
1426
1426
|
return retryAfterMs2 === void 0 ? jittered : Math.max(jittered, retryAfterMs2);
|
|
1427
1427
|
}
|
|
1428
1428
|
async function withRetry(fn, options) {
|
|
1429
|
-
const retryable = options.enabled !== false;
|
|
1429
|
+
const retryable = options.idempotent && options.enabled !== false;
|
|
1430
1430
|
const maxAttempts = retryable ? MAX_ATTEMPTS : 1;
|
|
1431
1431
|
const sleep2 = options.sleepFn ?? defaultSleep;
|
|
1432
1432
|
const random = options.randomFn ?? Math.random;
|
|
@@ -1440,6 +1440,7 @@ async function withRetry(fn, options) {
|
|
|
1440
1440
|
}
|
|
1441
1441
|
const retryAfterMs2 = isRetryAfterCarrier(err) ? err.retryAfterMs : void 0;
|
|
1442
1442
|
const delay = delayMs(attempt, retryAfterMs2, random());
|
|
1443
|
+
options.admit?.(delay);
|
|
1443
1444
|
options.telemetry?.emit({
|
|
1444
1445
|
type: "retry",
|
|
1445
1446
|
operation: options.operation ?? "unknown",
|
|
@@ -1502,6 +1503,8 @@ var MAX_LOGOUT_TOKEN_AGE_SECS = 300;
|
|
|
1502
1503
|
var PollSchedule = class {
|
|
1503
1504
|
#intervalSecs;
|
|
1504
1505
|
#remainingSecs;
|
|
1506
|
+
/** A `Retry-After` still to be served by the next wait (§14.2 rule 9, contract 1.64). */
|
|
1507
|
+
#retryAfterSecs = 0;
|
|
1505
1508
|
constructor(intervalSecs, expiresInSecs) {
|
|
1506
1509
|
this.#intervalSecs = intervalSecs > 0 ? intervalSecs : DEFAULT_POLL_INTERVAL_SECS;
|
|
1507
1510
|
this.#remainingSecs = expiresInSecs;
|
|
@@ -1510,6 +1513,21 @@ var PollSchedule = class {
|
|
|
1510
1513
|
get intervalSecs() {
|
|
1511
1514
|
return this.#intervalSecs;
|
|
1512
1515
|
}
|
|
1516
|
+
/**
|
|
1517
|
+
* The delay before the next poll, in seconds: the interval, or the pending
|
|
1518
|
+
* `Retry-After` when that is longer (a minimum, §14.2 rule 9).
|
|
1519
|
+
*/
|
|
1520
|
+
get waitSecs() {
|
|
1521
|
+
return Math.max(this.#intervalSecs, this.#retryAfterSecs);
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Record a `429 rate_limit_exceeded` (§14.2 rule 9, contract 1.64): the next
|
|
1525
|
+
* wait lasts at least `retryAfterSecs` and stands in for one interval. The
|
|
1526
|
+
* interval itself is **not** raised — only the `400 slow_down` does that.
|
|
1527
|
+
*/
|
|
1528
|
+
rateLimited(retryAfterSecs) {
|
|
1529
|
+
this.#retryAfterSecs = retryAfterSecs !== void 0 && retryAfterSecs > 0 ? retryAfterSecs : 0;
|
|
1530
|
+
}
|
|
1513
1531
|
/** Apply one `slow_down` (§14.2 rule 1): **cumulative, never reset.** */
|
|
1514
1532
|
slowDown() {
|
|
1515
1533
|
this.#intervalSecs += SLOW_DOWN_INCREMENT_SECS;
|
|
@@ -1522,14 +1540,27 @@ var PollSchedule = class {
|
|
|
1522
1540
|
* the server is still answering `authorization_pending`.
|
|
1523
1541
|
*/
|
|
1524
1542
|
tick() {
|
|
1525
|
-
|
|
1543
|
+
const waitSecs = this.waitSecs;
|
|
1544
|
+
this.#retryAfterSecs = 0;
|
|
1545
|
+
if (waitSecs >= this.#remainingSecs) {
|
|
1526
1546
|
this.#remainingSecs = 0;
|
|
1527
1547
|
return false;
|
|
1528
1548
|
}
|
|
1529
|
-
this.#remainingSecs -=
|
|
1549
|
+
this.#remainingSecs -= waitSecs;
|
|
1530
1550
|
return true;
|
|
1531
1551
|
}
|
|
1532
1552
|
};
|
|
1553
|
+
var POLL_RETRY_AFTER_MS = /* @__PURE__ */ new WeakMap();
|
|
1554
|
+
function pollRateLimit(err) {
|
|
1555
|
+
if (axiosStatus(err) !== 429) return void 0;
|
|
1556
|
+
const body = axiosBody(err);
|
|
1557
|
+
const description = body !== null && typeof body === "object" && typeof body.error_description === "string" ? body.error_description : "";
|
|
1558
|
+
const limited = new OAuthProtocolError("rate_limit_exceeded", description);
|
|
1559
|
+
const response = err.response;
|
|
1560
|
+
const retryAfter = response ? retryAfterMs(response) : void 0;
|
|
1561
|
+
if (retryAfter !== void 0) POLL_RETRY_AFTER_MS.set(limited, retryAfter);
|
|
1562
|
+
return limited;
|
|
1563
|
+
}
|
|
1533
1564
|
function sleep(ms) {
|
|
1534
1565
|
return new Promise((resolve) => {
|
|
1535
1566
|
setTimeout(resolve, ms);
|
|
@@ -1663,6 +1694,19 @@ function transient(error) {
|
|
|
1663
1694
|
return error;
|
|
1664
1695
|
}
|
|
1665
1696
|
var SYSTEM_CIBA_CLOCK = { now: () => Date.now(), sleep };
|
|
1697
|
+
function deadlineBoundedRetry(bound, what) {
|
|
1698
|
+
return {
|
|
1699
|
+
admit: (ms) => {
|
|
1700
|
+
if (bound.clock.now() + ms >= bound.deadline) {
|
|
1701
|
+
throw new OAuthProtocolError(
|
|
1702
|
+
"expired_token",
|
|
1703
|
+
`the ${what} expired before it was decided (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4, \xA734.2 P10)`
|
|
1704
|
+
);
|
|
1705
|
+
}
|
|
1706
|
+
},
|
|
1707
|
+
sleepFn: (ms) => bound.clock.sleep(ms)
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1666
1710
|
function isAccessDenied(err) {
|
|
1667
1711
|
return err instanceof OAuthProtocolError && err.error === "access_denied";
|
|
1668
1712
|
}
|
|
@@ -2447,26 +2491,36 @@ var OidcClient = class {
|
|
|
2447
2491
|
* The raw single call, so an application driving its own loop (a UI
|
|
2448
2492
|
* rendering a countdown, say) can. The five RFC 8628 §3.5 answers surface as
|
|
2449
2493
|
* {@link OAuthProtocolError} — `authorization_pending` and `slow_down`
|
|
2450
|
-
* included — so a hand-rolled loop
|
|
2451
|
-
*
|
|
2494
|
+
* included — so a hand-rolled loop dispatches on the same answers
|
|
2495
|
+
* {@link deviceLogin} does. Most callers want {@link deviceLogin}.
|
|
2452
2496
|
*
|
|
2453
2497
|
* Client authentication is the one {@link deviceAuthorize} describes
|
|
2454
2498
|
* (contract 1.62, §14.1 rule 2): a configured `clientSecret` is sent as
|
|
2455
2499
|
* `client_secret` in the form body, never as `Authorization: Basic`; a public
|
|
2456
2500
|
* client sends none; `client_id` is sent on **every** poll (§14.1 rule 3). A
|
|
2457
2501
|
* `401 invalid_client` surfaces as {@link OAuthProtocolError}, is not retried
|
|
2458
|
-
* and does not enter the §9 refresh guard (§14.2 rule 5).
|
|
2502
|
+
* and does not enter the §9 refresh guard (§14.2 rule 5). Any `429`
|
|
2503
|
+
* is an {@link OAuthProtocolError} with `error == 'rate_limit_exceeded'` too
|
|
2504
|
+
* (rule 9, whatever its body names) — never `slow_down`; {@link deviceLogin}
|
|
2505
|
+
* waits it out. Its `Retry-After` is not exposed, so a hand-rolled loop
|
|
2506
|
+
* should wait at least one interval on it without raising the interval, or
|
|
2507
|
+
* use {@link deviceLogin}. This SDK ships no
|
|
2459
2508
|
* DPoP proof generator, so it cannot drive a client registered for DPoP; it
|
|
2460
2509
|
* surfaces that client's refusal as the same `invalid_client`.
|
|
2461
2510
|
*/
|
|
2462
2511
|
async devicePoll(params) {
|
|
2512
|
+
return this.#devicePoll(params, void 0);
|
|
2513
|
+
}
|
|
2514
|
+
/** {@link devicePoll}; `bound` is the loop's deadline, which a §16 retry inside the poll must not pass. */
|
|
2515
|
+
async #devicePoll(params, bound) {
|
|
2463
2516
|
const configuration = params.configuration ?? await this.oidcDiscover();
|
|
2464
2517
|
const form = new URLSearchParams();
|
|
2465
2518
|
form.set("grant_type", DEVICE_CODE_GRANT_TYPE);
|
|
2466
2519
|
form.set("device_code", exposeSecret(params.deviceCode));
|
|
2467
2520
|
form.set("client_id", this.#options.clientId);
|
|
2468
2521
|
this.#appendClientSecret(form);
|
|
2469
|
-
const
|
|
2522
|
+
const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), params.tenantId);
|
|
2523
|
+
const wire = await this.#postDevicePoll(url, form, bound);
|
|
2470
2524
|
return this.#toTokenSet(wire, configuration, void 0);
|
|
2471
2525
|
}
|
|
2472
2526
|
/**
|
|
@@ -2487,31 +2541,44 @@ var OidcClient = class {
|
|
|
2487
2541
|
* even if the server has not yet said `expired_token`. A 5xx or transport
|
|
2488
2542
|
* failure mid-poll is **not** terminal (rule 6) — the loop absorbs it and
|
|
2489
2543
|
* tries again, bounded by the same deadline, because a server restart must
|
|
2490
|
-
* not lose a grant the user has already approved
|
|
2544
|
+
* not lose a grant the user has already approved: that bound holds for the
|
|
2545
|
+
* §16 retry inside a poll too, whose waits are served on the loop's clock and
|
|
2546
|
+
* never reach the deadline (`Retry-After` included; the typed `expired_token`
|
|
2547
|
+
* is raised at once, C164-36). A `429
|
|
2548
|
+
* rate_limit_exceeded` (rule 9, contract 1.64) is not terminal either: the
|
|
2549
|
+
* loop waits `Retry-After` as a minimum (capped at the `expires_in`
|
|
2550
|
+
* deadline), counts the wait as one interval, does **not** raise the
|
|
2551
|
+
* interval, and polls again.
|
|
2491
2552
|
*/
|
|
2492
2553
|
async deviceLogin(params) {
|
|
2493
2554
|
const configuration = params.configuration ?? await this.oidcDiscover();
|
|
2555
|
+
const clock = params.clock ?? SYSTEM_CIBA_CLOCK;
|
|
2494
2556
|
const authorization = await this.deviceAuthorize({
|
|
2495
2557
|
...params.scope !== void 0 ? { scope: params.scope } : {},
|
|
2496
2558
|
...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
|
|
2497
2559
|
configuration
|
|
2498
2560
|
});
|
|
2561
|
+
const deadline = clock.now() + authorization.expiresIn * 1e3;
|
|
2499
2562
|
await params.onUserCode(authorization);
|
|
2500
2563
|
const schedule = new PollSchedule(authorization.interval, authorization.expiresIn);
|
|
2501
2564
|
for (; ; ) {
|
|
2502
|
-
|
|
2565
|
+
const waitSecs = schedule.waitSecs;
|
|
2566
|
+
if (!schedule.tick() || clock.now() + waitSecs * 1e3 >= deadline) {
|
|
2503
2567
|
throw new OAuthProtocolError(
|
|
2504
2568
|
"expired_token",
|
|
2505
2569
|
"the device authorization expired before the user completed it (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4)"
|
|
2506
2570
|
);
|
|
2507
2571
|
}
|
|
2508
|
-
await sleep(
|
|
2572
|
+
await clock.sleep(waitSecs * 1e3);
|
|
2509
2573
|
try {
|
|
2510
|
-
return await this
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2574
|
+
return await this.#devicePoll(
|
|
2575
|
+
{
|
|
2576
|
+
deviceCode: authorization.deviceCode,
|
|
2577
|
+
...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
|
|
2578
|
+
configuration
|
|
2579
|
+
},
|
|
2580
|
+
{ deadline, clock }
|
|
2581
|
+
);
|
|
2515
2582
|
} catch (err) {
|
|
2516
2583
|
if (err instanceof OAuthProtocolError) {
|
|
2517
2584
|
if (err.error === "authorization_pending") {
|
|
@@ -2521,6 +2588,11 @@ var OidcClient = class {
|
|
|
2521
2588
|
schedule.slowDown();
|
|
2522
2589
|
continue;
|
|
2523
2590
|
}
|
|
2591
|
+
if (err.error === "rate_limit_exceeded") {
|
|
2592
|
+
const pollWaitMs = POLL_RETRY_AFTER_MS.get(err);
|
|
2593
|
+
schedule.rateLimited(pollWaitMs === void 0 ? void 0 : pollWaitMs / 1e3);
|
|
2594
|
+
continue;
|
|
2595
|
+
}
|
|
2524
2596
|
throw err;
|
|
2525
2597
|
}
|
|
2526
2598
|
if (err instanceof NetworkError) {
|
|
@@ -3041,6 +3113,10 @@ var OidcClient = class {
|
|
|
3041
3113
|
* this client's credential.
|
|
3042
3114
|
*/
|
|
3043
3115
|
async cibaPoll(params) {
|
|
3116
|
+
return this.#cibaPoll(params, void 0);
|
|
3117
|
+
}
|
|
3118
|
+
/** {@link cibaPoll}; `bound` is `cibaAwait`'s deadline, which a §16 retry inside the poll must not pass. */
|
|
3119
|
+
async #cibaPoll(params, bound) {
|
|
3044
3120
|
const operation = "ciba_poll";
|
|
3045
3121
|
const auth = this.#cibaClientAuth(operation);
|
|
3046
3122
|
const configuration = params.configuration ?? await this.oidcDiscover();
|
|
@@ -3071,9 +3147,11 @@ var OidcClient = class {
|
|
|
3071
3147
|
return { error: mapHttpStatusToError(response.status, `${operation}: HTTP ${response.status}`) };
|
|
3072
3148
|
},
|
|
3073
3149
|
{
|
|
3150
|
+
idempotent: true,
|
|
3074
3151
|
operation,
|
|
3075
3152
|
enabled: this.#session.retryEnabled,
|
|
3076
|
-
telemetry: this.#session.telemetry.dispatcher
|
|
3153
|
+
telemetry: this.#session.telemetry.dispatcher,
|
|
3154
|
+
...bound !== void 0 ? deadlineBoundedRetry(bound, "CIBA request") : {}
|
|
3077
3155
|
}
|
|
3078
3156
|
);
|
|
3079
3157
|
if (outcome.error) throw outcome.error;
|
|
@@ -3093,7 +3171,9 @@ var OidcClient = class {
|
|
|
3093
3171
|
* the interval and polls again.
|
|
3094
3172
|
* - Polling stops at `receivedAt + expiresIn`, even if the server has not
|
|
3095
3173
|
* said `expired_token`: when the next wait would reach the deadline, the
|
|
3096
|
-
* same `expired_token` is raised locally, without a request.
|
|
3174
|
+
* same `expired_token` is raised locally, without a request. A §16 retry
|
|
3175
|
+
* inside {@link cibaPoll} is bounded the same way (§34.2 P10): a wait that
|
|
3176
|
+
* would reach the deadline is not served and nothing is sent after it.
|
|
3097
3177
|
* - `access_denied`, `expired_token`, `invalid_grant` and any other answer
|
|
3098
3178
|
* end the loop.
|
|
3099
3179
|
*
|
|
@@ -3121,11 +3201,14 @@ var OidcClient = class {
|
|
|
3121
3201
|
}
|
|
3122
3202
|
await clock.sleep(waitMs);
|
|
3123
3203
|
try {
|
|
3124
|
-
return await this
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3204
|
+
return await this.#cibaPoll(
|
|
3205
|
+
{
|
|
3206
|
+
authReqId: initiated.authReqId,
|
|
3207
|
+
configuration,
|
|
3208
|
+
...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {}
|
|
3209
|
+
},
|
|
3210
|
+
{ deadline, clock }
|
|
3211
|
+
);
|
|
3129
3212
|
} catch (err) {
|
|
3130
3213
|
if (err instanceof OAuthProtocolError) {
|
|
3131
3214
|
if (err.error === "authorization_pending" || err.error === "rate_limit_exceeded") continue;
|
|
@@ -3221,6 +3304,46 @@ var OidcClient = class {
|
|
|
3221
3304
|
throw transient(new NetworkError(`${operation}: the request failed before any response arrived${code}`));
|
|
3222
3305
|
}
|
|
3223
3306
|
}
|
|
3307
|
+
/**
|
|
3308
|
+
* One device-poll attempt under §16 (CONTRACT.md §14.2 rule 6, §16.2; C164-25): a `5xx` or
|
|
3309
|
+
* a transport failure is retried **inside** the poll (three requests in all, the `Retry-After`
|
|
3310
|
+
* a floor) before it surfaces as a `NetworkError`; the loop then takes its next interval. A
|
|
3311
|
+
* `429` is never retried here — it is rule 9's wait, the loop's — nor is any answer the
|
|
3312
|
+
* server decided (`400`, `401`).
|
|
3313
|
+
*/
|
|
3314
|
+
async #postDevicePoll(url, form, bound) {
|
|
3315
|
+
const operation = "device_poll";
|
|
3316
|
+
const outcome = await withRetry(
|
|
3317
|
+
async () => {
|
|
3318
|
+
try {
|
|
3319
|
+
const response = await this.#session.axios.post(url, form.toString(), {
|
|
3320
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
3321
|
+
});
|
|
3322
|
+
return { wire: response.data };
|
|
3323
|
+
} catch (err) {
|
|
3324
|
+
if (err instanceof AxiamError) return { error: err };
|
|
3325
|
+
const status = axiosStatus(err);
|
|
3326
|
+
const response = err.response;
|
|
3327
|
+
if (status === void 0) {
|
|
3328
|
+
throw new NetworkError(`${operation}: the request failed before any response arrived`, sanitizeAxiosError(err));
|
|
3329
|
+
}
|
|
3330
|
+
if (status >= 500) {
|
|
3331
|
+
throw retryableNetworkError(`${operation}: HTTP ${status}`, response);
|
|
3332
|
+
}
|
|
3333
|
+
return { error: pollRateLimit(err) ?? mapOidcError(err, url, "token request failed") };
|
|
3334
|
+
}
|
|
3335
|
+
},
|
|
3336
|
+
{
|
|
3337
|
+
idempotent: true,
|
|
3338
|
+
operation,
|
|
3339
|
+
enabled: this.#session.retryEnabled,
|
|
3340
|
+
telemetry: this.#session.telemetry.dispatcher,
|
|
3341
|
+
...bound !== void 0 ? deadlineBoundedRetry(bound, "device authorization") : {}
|
|
3342
|
+
}
|
|
3343
|
+
);
|
|
3344
|
+
if (outcome.error) throw outcome.error;
|
|
3345
|
+
return outcome.wire;
|
|
3346
|
+
}
|
|
3224
3347
|
/** POST a form body to the token endpoint from the discovery document. */
|
|
3225
3348
|
async #postToken(configuration, form, tenantId) {
|
|
3226
3349
|
const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), tenantId);
|
|
@@ -3407,6 +3530,10 @@ var OidcClient = class {
|
|
|
3407
3530
|
try {
|
|
3408
3531
|
return await this.#session.axios.post(url, form.toString(), config);
|
|
3409
3532
|
} catch (err) {
|
|
3533
|
+
if (axiosStatus(err) === 429) {
|
|
3534
|
+
const protocol = oauth2ErrorFromBody(axiosBody(err));
|
|
3535
|
+
if (protocol) throw protocol;
|
|
3536
|
+
}
|
|
3410
3537
|
throw mapOidcError(err, url, fallbackMessage);
|
|
3411
3538
|
}
|
|
3412
3539
|
}
|