@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCredentials.js","sourceRoot":"","sources":["../../src/clientCredentials.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAkC,MAAM,oBAAoB,CAAC;AACrH,OAAO,EAAE,wBAAwB,EAAsB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientCredentials.js","sourceRoot":"","sources":["../../src/clientCredentials.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CA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
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/esm/credentials.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConfigurationError } from "./errors.js";
|
|
2
|
+
/** Reports whether `credential` provides `clientAuthentication`. */
|
|
3
|
+
export function providesClientAuthentication(credential) {
|
|
4
|
+
return typeof credential.clientAuthentication === "function";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns `credential` when it provides `clientAuthentication` and its
|
|
8
|
+
* `checkClientAuthentication` passes. Throws `ConfigurationError` otherwise.
|
|
9
|
+
* Call it before sending any request, including discovery.
|
|
10
|
+
*/
|
|
11
|
+
export function requireClientAuthentication(credential, operation) {
|
|
12
|
+
if (!providesClientAuthentication(credential)) {
|
|
13
|
+
throw new ConfigurationError(`${operation} requires a credential that provides clientAuthentication`);
|
|
14
|
+
}
|
|
15
|
+
credential.checkClientAuthentication?.();
|
|
16
|
+
return credential;
|
|
17
|
+
}
|
|
2
18
|
//# 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":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAoDjD,oEAAoE;AACpE,MAAM,UAAU,4BAA4B,CAC1C,UAAiC;IAEjC,OAAO,OAAO,UAAU,CAAC,oBAAoB,KAAK,UAAU,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,UAAiC,EACjC,SAAiB;IAEjB,IAAI,CAAC,4BAA4B,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,kBAAkB,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/deviceAuthor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