@udibo/oauth2 0.21.1 → 0.21.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/dist/identity/external/_shared.d.ts +8 -0
- package/dist/identity/external/_shared.js +8 -0
- package/dist/identity/external/_token-exchange.d.ts +1 -3
- package/dist/identity/external/_token-exchange.js +2 -4
- package/dist/identity/external/apple.js +3 -2
- package/dist/identity/external/github.js +3 -2
- package/dist/identity/external/oauth2.js +3 -2
- package/dist/identity/external/oidc.js +3 -2
- package/package.json +1 -1
|
@@ -24,6 +24,14 @@ export declare const ID_TOKEN_EXPIRY_LEEWAY_SECONDS = 120;
|
|
|
24
24
|
* OAuth2 error carries a description the provider wrote.
|
|
25
25
|
*/
|
|
26
26
|
export declare function describeError(error: unknown): string;
|
|
27
|
+
/**
|
|
28
|
+
* Deadline, in milliseconds, on each request a connector sends to a provider —
|
|
29
|
+
* the token exchange and the profile, UserInfo and key-set reads. Send it as
|
|
30
|
+
* `signal: packageDeadlineSignal(AbortSignal.timeout(...))` on the `fetch`
|
|
31
|
+
* init: that one signal covers the connect, the headers and the whole body, so
|
|
32
|
+
* the body read after it needs no deadline of its own.
|
|
33
|
+
*/
|
|
34
|
+
export declare const PROVIDER_REQUEST_TIMEOUT_MS = 10000;
|
|
27
35
|
/**
|
|
28
36
|
* Response bytes a connector reads from a provider endpoint — token, profile,
|
|
29
37
|
* UserInfo, or key set — before refusing the response.
|
|
@@ -37,6 +37,14 @@ export function describeError(error) {
|
|
|
37
37
|
}
|
|
38
38
|
return sanitizeProviderText(error instanceof Error ? error.message : String(error));
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Deadline, in milliseconds, on each request a connector sends to a provider —
|
|
42
|
+
* the token exchange and the profile, UserInfo and key-set reads. Send it as
|
|
43
|
+
* `signal: packageDeadlineSignal(AbortSignal.timeout(...))` on the `fetch`
|
|
44
|
+
* init: that one signal covers the connect, the headers and the whole body, so
|
|
45
|
+
* the body read after it needs no deadline of its own.
|
|
46
|
+
*/
|
|
47
|
+
export const PROVIDER_REQUEST_TIMEOUT_MS = 10_000;
|
|
40
48
|
/**
|
|
41
49
|
* Response bytes a connector reads from a provider endpoint — token, profile,
|
|
42
50
|
* UserInfo, or key set — before refusing the response.
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
*/
|
|
11
11
|
/** Response bytes accepted from a token endpoint before the exchange is refused. */
|
|
12
12
|
export declare const MAX_TOKEN_RESPONSE_BYTES: number;
|
|
13
|
-
/** Wall-clock budget for the exchange, covering the connect and the body read. */
|
|
14
|
-
export declare const TOKEN_EXCHANGE_TIMEOUT_MS = 10000;
|
|
15
13
|
/** Input for {@link runTokenExchange}. */
|
|
16
14
|
export interface TokenExchangeInput {
|
|
17
15
|
/** Provider id carried on every thrown {@link ExternalAuthError}. */
|
|
@@ -39,7 +37,7 @@ export interface TokenExchangeInput {
|
|
|
39
37
|
httpErrorHint: string;
|
|
40
38
|
/** Guidance appended for the OAuth2 error code the provider reported. */
|
|
41
39
|
tokenErrorHint: (code: string | undefined) => string;
|
|
42
|
-
/** Exchange deadline. Defaults to {@link
|
|
40
|
+
/** Exchange deadline. Defaults to {@link PROVIDER_REQUEST_TIMEOUT_MS}. */
|
|
43
41
|
timeoutMs?: number;
|
|
44
42
|
}
|
|
45
43
|
/** A token response that cleared every step of {@link runTokenExchange}. */
|
|
@@ -9,12 +9,10 @@
|
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
11
|
import { packageDeadlineSignal } from "../../utils/_default-fetch.js";
|
|
12
|
-
import { describeError, MAX_PROVIDER_RESPONSE_BYTES, sanitizeProviderText, } from "./_shared.js";
|
|
12
|
+
import { describeError, MAX_PROVIDER_RESPONSE_BYTES, PROVIDER_REQUEST_TIMEOUT_MS, sanitizeProviderText, } from "./_shared.js";
|
|
13
13
|
import { ExternalAuthError } from "./errors.js";
|
|
14
14
|
/** Response bytes accepted from a token endpoint before the exchange is refused. */
|
|
15
15
|
export const MAX_TOKEN_RESPONSE_BYTES = MAX_PROVIDER_RESPONSE_BYTES;
|
|
16
|
-
/** Wall-clock budget for the exchange, covering the connect and the body read. */
|
|
17
|
-
export const TOKEN_EXCHANGE_TIMEOUT_MS = 10_000;
|
|
18
16
|
/**
|
|
19
17
|
* Posts the authorization code and returns a token response known to be a JSON
|
|
20
18
|
* object carrying `requiredField`. Every failure throws
|
|
@@ -34,7 +32,7 @@ export async function runTokenExchange(input) {
|
|
|
34
32
|
},
|
|
35
33
|
body: input.body,
|
|
36
34
|
redirect: "manual",
|
|
37
|
-
signal: packageDeadlineSignal(AbortSignal.timeout(input.timeoutMs ??
|
|
35
|
+
signal: packageDeadlineSignal(AbortSignal.timeout(input.timeoutMs ?? PROVIDER_REQUEST_TIMEOUT_MS)),
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
38
|
catch (error) {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { toArrayBuffer } from "../../utils/_buffer.js";
|
|
19
19
|
import { base64urlDecode } from "../../utils/crypto.js";
|
|
20
|
-
import { defaultFetch } from "../../utils/_default-fetch.js";
|
|
21
|
-
import { assertIdTokenClaims, describeError, readProviderText, } from "./_shared.js";
|
|
20
|
+
import { defaultFetch, packageDeadlineSignal, } from "../../utils/_default-fetch.js";
|
|
21
|
+
import { assertIdTokenClaims, describeError, PROVIDER_REQUEST_TIMEOUT_MS, readProviderText, } from "./_shared.js";
|
|
22
22
|
import { runTokenExchange } from "./_token-exchange.js";
|
|
23
23
|
import { createAppleClientSecretFactory, } from "./apple-client-secret.js";
|
|
24
24
|
import { ExternalAuthError } from "./errors.js";
|
|
@@ -101,6 +101,7 @@ export function appleProvider(options) {
|
|
|
101
101
|
try {
|
|
102
102
|
res = await fetchImpl(APPLE_JWKS_URL, {
|
|
103
103
|
headers: { Accept: "application/json" },
|
|
104
|
+
signal: packageDeadlineSignal(AbortSignal.timeout(PROVIDER_REQUEST_TIMEOUT_MS)),
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
107
|
catch (error) {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import { defaultFetch } from "../../utils/_default-fetch.js";
|
|
8
|
-
import { describeError, readProviderText } from "./_shared.js";
|
|
7
|
+
import { defaultFetch, packageDeadlineSignal, } from "../../utils/_default-fetch.js";
|
|
8
|
+
import { describeError, PROVIDER_REQUEST_TIMEOUT_MS, readProviderText, } from "./_shared.js";
|
|
9
9
|
import { runTokenExchange } from "./_token-exchange.js";
|
|
10
10
|
import { ExternalAuthError } from "./errors.js";
|
|
11
11
|
const GITHUB_AUTHORIZE_URL = "https://github.com/login/oauth/authorize";
|
|
@@ -65,6 +65,7 @@ export function githubProvider(options) {
|
|
|
65
65
|
Authorization: `Bearer ${accessToken}`,
|
|
66
66
|
Accept: "application/vnd.github+json",
|
|
67
67
|
},
|
|
68
|
+
signal: packageDeadlineSignal(AbortSignal.timeout(PROVIDER_REQUEST_TIMEOUT_MS)),
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
catch (error) {
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
import { defaultFetch } from "../../utils/_default-fetch.js";
|
|
10
|
+
import { defaultFetch, packageDeadlineSignal, } from "../../utils/_default-fetch.js";
|
|
11
11
|
import { generateCodeChallenge } from "../../utils/pkce.js";
|
|
12
|
-
import { describeError, readErrorBody, readProviderText } from "./_shared.js";
|
|
12
|
+
import { describeError, PROVIDER_REQUEST_TIMEOUT_MS, readErrorBody, readProviderText, } from "./_shared.js";
|
|
13
13
|
import { runTokenExchange } from "./_token-exchange.js";
|
|
14
14
|
import { ExternalAuthError } from "./errors.js";
|
|
15
15
|
/**
|
|
@@ -73,6 +73,7 @@ export function oauth2Provider(options) {
|
|
|
73
73
|
Authorization: `Bearer ${accessToken}`,
|
|
74
74
|
Accept: "application/json",
|
|
75
75
|
},
|
|
76
|
+
signal: packageDeadlineSignal(AbortSignal.timeout(PROVIDER_REQUEST_TIMEOUT_MS)),
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
catch (error) {
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
import { DirectClient } from "../../client/direct-client.js";
|
|
8
8
|
import { MemoryAuthRequestStorage } from "../../client/storage.js";
|
|
9
9
|
import { isOAuth2Error } from "../../errors.js";
|
|
10
|
-
import { defaultFetch } from "../../utils/_default-fetch.js";
|
|
10
|
+
import { defaultFetch, packageDeadlineSignal, } from "../../utils/_default-fetch.js";
|
|
11
11
|
import { generateCodeChallenge } from "../../utils/pkce.js";
|
|
12
|
-
import { assertIdTokenClaims, describeError, readProviderText, stripTrailingSlash, } from "./_shared.js";
|
|
12
|
+
import { assertIdTokenClaims, describeError, PROVIDER_REQUEST_TIMEOUT_MS, readProviderText, stripTrailingSlash, } from "./_shared.js";
|
|
13
13
|
import { ExternalAuthError } from "./errors.js";
|
|
14
14
|
/**
|
|
15
15
|
* Creates a connector for any spec-compliant OpenID Connect provider.
|
|
@@ -148,6 +148,7 @@ export function oidcProvider(options) {
|
|
|
148
148
|
Authorization: `Bearer ${accessToken}`,
|
|
149
149
|
Accept: "application/json",
|
|
150
150
|
},
|
|
151
|
+
signal: packageDeadlineSignal(AbortSignal.timeout(PROVIDER_REQUEST_TIMEOUT_MS)),
|
|
151
152
|
});
|
|
152
153
|
if (!res.ok) {
|
|
153
154
|
await res.body?.cancel();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@udibo/oauth2",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.2",
|
|
4
4
|
"description": "A flexible OAuth2 toolkit: framework-agnostic authorization & resource servers, a typed client, Hono adapters (including a backend-for-frontend), and React bindings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authorization-server",
|