@hawcx/oauth-client 0.2.0 → 5.1.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 +587 -204
- package/dist/client-assertion.d.ts +45 -0
- package/dist/client-assertion.d.ts.map +1 -0
- package/dist/client-assertion.js +141 -0
- package/dist/client-assertion.js.map +1 -0
- package/dist/delegation/credentials.d.ts +92 -0
- package/dist/delegation/credentials.d.ts.map +1 -0
- package/dist/delegation/credentials.js +215 -0
- package/dist/delegation/credentials.js.map +1 -0
- package/dist/delegation/crypto.d.ts +2 -2
- package/dist/delegation/crypto.d.ts.map +1 -1
- package/dist/delegation/crypto.js +41 -32
- package/dist/delegation/crypto.js.map +1 -1
- package/dist/delegation/exceptions.d.ts +12 -5
- package/dist/delegation/exceptions.d.ts.map +1 -1
- package/dist/delegation/exceptions.js +12 -14
- package/dist/delegation/exceptions.js.map +1 -1
- package/dist/delegation/factory.d.ts +20 -0
- package/dist/delegation/factory.d.ts.map +1 -0
- package/dist/delegation/factory.js +49 -0
- package/dist/delegation/factory.js.map +1 -0
- package/dist/delegation/hawcx.d.ts +59 -224
- package/dist/delegation/hawcx.d.ts.map +1 -1
- package/dist/delegation/hawcx.js +99 -299
- package/dist/delegation/hawcx.js.map +1 -1
- package/dist/delegation/index.d.ts +4 -9
- package/dist/delegation/index.d.ts.map +1 -1
- package/dist/delegation/index.js +5 -17
- package/dist/delegation/index.js.map +1 -1
- package/dist/delegation/transport.d.ts +40 -0
- package/dist/delegation/transport.d.ts.map +1 -0
- package/dist/delegation/transport.js +120 -0
- package/dist/delegation/transport.js.map +1 -0
- package/dist/errors.d.ts +62 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +73 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -27
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +265 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +497 -0
- package/dist/oauth.js.map +1 -0
- package/dist/stepup/client.d.ts +26 -0
- package/dist/stepup/client.d.ts.map +1 -0
- package/dist/stepup/client.js +78 -0
- package/dist/stepup/client.js.map +1 -0
- package/dist/stepup/index.d.ts +3 -0
- package/dist/stepup/index.d.ts.map +1 -0
- package/dist/stepup/index.js +19 -0
- package/dist/stepup/index.js.map +1 -0
- package/dist/stepup/types.d.ts +35 -0
- package/dist/stepup/types.d.ts.map +1 -0
- package/dist/stepup/types.js +3 -0
- package/dist/stepup/types.js.map +1 -0
- package/package.json +13 -16
- package/dist/client.d.ts +0 -134
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -300
- package/dist/client.js.map +0 -1
- package/dist/delegation/client.d.ts +0 -116
- package/dist/delegation/client.d.ts.map +0 -1
- package/dist/delegation/client.js +0 -227
- package/dist/delegation/client.js.map +0 -1
- package/dist/exceptions.d.ts +0 -52
- package/dist/exceptions.d.ts.map +0 -1
- package/dist/exceptions.js +0 -81
- package/dist/exceptions.js.map +0 -1
- package/dist/utils.d.ts +0 -61
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -263
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAiC,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAyB,MAAM,oBAAoB,CAAC;AA6BlF,MAAM,WAAW,gBAAgB;IAC/B,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;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C;IAkF1B;;;;;;;;OAQG;IACG,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC;IA8ElF;;;;;;;;;OASG;IACH,OAAO,CAAC,OAAO;IAoBf;;;;;;OAMG;IACH,WAAW,IAAI,IAAI;IAInB;;;OAGG;IACH,UAAU,IAAI,IAAI;IAclB,OAAO,CAAC,gBAAgB,CAAS;CAClC"}
|
package/dist/oauth.js
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hawcx OAuth Client
|
|
4
|
+
*
|
|
5
|
+
* Two construction paths:
|
|
6
|
+
*
|
|
7
|
+
* 1. OIDC discovery (recommended) — `HawcxOAuth.fromIssuer(...)` fetches
|
|
8
|
+
* `<issuer>/.well-known/openid-configuration` once at startup and wires
|
|
9
|
+
* up a verifier that enforces signature + iss + aud + exp + nbf on every
|
|
10
|
+
* subsequent `verifyToken` call.
|
|
11
|
+
*
|
|
12
|
+
* 2. Legacy — `new HawcxOAuth({ configId, baseUrl })` hits the fixed
|
|
13
|
+
* endpoints `/oauth2/token` and `/keys` directly. Backward-compatible
|
|
14
|
+
* with v4.x callers, but does NOT verify `iss` or `aud` — the JWT's
|
|
15
|
+
* signature is the only check.
|
|
16
|
+
*
|
|
17
|
+
* Both modes are safe to share across requests.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.HawcxOAuth = void 0;
|
|
21
|
+
const jose_1 = require("jose");
|
|
22
|
+
const client_assertion_1 = require("./client-assertion");
|
|
23
|
+
const errors_1 = require("./errors");
|
|
24
|
+
const DEFAULT_BASE_URL = 'https://api.hawcx.com';
|
|
25
|
+
const DEFAULT_TIMEOUT_MS = 10000;
|
|
26
|
+
/** Bound the discovery fetch so an unreachable issuer fails fast at startup. */
|
|
27
|
+
const DEFAULT_DISCOVERY_TIMEOUT_MS = 5000;
|
|
28
|
+
/**
|
|
29
|
+
* Spec.md §3.3 recommends a default clock-tolerance of 10 seconds for
|
|
30
|
+
* `exp` / `nbf` checks during JWT verification. Without it jose defaults
|
|
31
|
+
* to 0 and tokens minted under normal NTP drift between issuer and verifier
|
|
32
|
+
* fail at the very first millisecond — the symptom that drove the
|
|
33
|
+
* `exchangeCodeTolerant` workaround in hawcx_admin_console pre-5.0.
|
|
34
|
+
*/
|
|
35
|
+
const DEFAULT_CLOCK_TOLERANCE_SECONDS = 10;
|
|
36
|
+
/**
|
|
37
|
+
* Closed id_token signing-algorithm allowlist (spec.md §3.3). Algorithms
|
|
38
|
+
* outside this set — including HS256 and the rest of the symmetric family,
|
|
39
|
+
* RS512, PS*, none — are refused even if a Hawcx issuer advertises them.
|
|
40
|
+
* Mirrors {@code JwtVerifier.DEFAULT_ALGORITHMS} in the Java SDK.
|
|
41
|
+
*/
|
|
42
|
+
const DEFAULT_ID_TOKEN_ALGS = Object.freeze([
|
|
43
|
+
'RS256',
|
|
44
|
+
'ES256',
|
|
45
|
+
'ES384',
|
|
46
|
+
'ES512',
|
|
47
|
+
'EdDSA',
|
|
48
|
+
]);
|
|
49
|
+
/**
|
|
50
|
+
* Require https on a discovery-related URL. Plaintext http is permitted only
|
|
51
|
+
* for loopback hosts (localhost / 127.0.0.1 / ::1) to support local dev and
|
|
52
|
+
* tests. OIDC Discovery §4 / OAuth 2.1 §7.4: an http issuer lets an on-path
|
|
53
|
+
* attacker swap the discovery doc and redirect token_endpoint / jwks_uri.
|
|
54
|
+
*/
|
|
55
|
+
function requireSecureUrl(label, url) {
|
|
56
|
+
let u;
|
|
57
|
+
try {
|
|
58
|
+
u = new URL(url);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new errors_1.DiscoveryError(`${label} is not a valid URL: ${url}`, { cause: err });
|
|
62
|
+
}
|
|
63
|
+
if (u.protocol === 'https:')
|
|
64
|
+
return;
|
|
65
|
+
const loopback = u.hostname === 'localhost' || u.hostname === '127.0.0.1' || u.hostname === '::1' || u.hostname === '[::1]';
|
|
66
|
+
if (u.protocol === 'http:' && loopback)
|
|
67
|
+
return;
|
|
68
|
+
throw new errors_1.DiscoveryError(`${label} must use https (got: ${url}). Plaintext http is permitted only for loopback hosts.`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Hawcx OAuth Client
|
|
72
|
+
*
|
|
73
|
+
* Discovery-mode usage (recommended):
|
|
74
|
+
*
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const oauth = await HawcxOAuth.fromIssuer({
|
|
77
|
+
* issuer: 'https://api.hawcx.com',
|
|
78
|
+
* configId: process.env.HAWCX_CONFIG_ID!,
|
|
79
|
+
* clientId: process.env.HAWCX_CLIENT_ID!,
|
|
80
|
+
* });
|
|
81
|
+
* const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* Legacy usage (no discovery; aud/iss are not checked):
|
|
85
|
+
*
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const oauth = new HawcxOAuth({ configId: process.env.HAWCX_CONFIG_ID! });
|
|
88
|
+
* const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
class HawcxOAuth {
|
|
92
|
+
constructor(config, discoveryInit) {
|
|
93
|
+
this.jwks = null;
|
|
94
|
+
this.clearCacheWarned = false;
|
|
95
|
+
if (!config.configId) {
|
|
96
|
+
throw new Error('configId is required');
|
|
97
|
+
}
|
|
98
|
+
this.configId = config.configId;
|
|
99
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
100
|
+
this.clockToleranceSeconds =
|
|
101
|
+
config.clockToleranceSeconds ?? DEFAULT_CLOCK_TOLERANCE_SECONDS;
|
|
102
|
+
if (discoveryInit) {
|
|
103
|
+
this.tokenEndpoint = discoveryInit.metadata.token_endpoint;
|
|
104
|
+
this.jwksUrl = discoveryInit.metadata.jwks_uri;
|
|
105
|
+
this.expectedAudience = discoveryInit.clientId;
|
|
106
|
+
this.expectedIssuer = discoveryInit.metadata.issuer;
|
|
107
|
+
this.discoveryMetadata = discoveryInit.metadata;
|
|
108
|
+
this.allowedAlgorithms = discoveryInit.allowedAlgorithms;
|
|
109
|
+
this.clientAssertionSigner = discoveryInit.signer ?? null;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, '');
|
|
113
|
+
this.tokenEndpoint = `${baseUrl}/oauth2/token`;
|
|
114
|
+
this.jwksUrl = `${baseUrl}/keys`;
|
|
115
|
+
this.expectedAudience = null;
|
|
116
|
+
this.expectedIssuer = null;
|
|
117
|
+
this.discoveryMetadata = null;
|
|
118
|
+
this.allowedAlgorithms = null;
|
|
119
|
+
this.clientAssertionSigner = null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Construct a client via OIDC discovery.
|
|
124
|
+
*
|
|
125
|
+
* Fetches `<issuer>/.well-known/openid-configuration`, reads the token
|
|
126
|
+
* endpoint, JWKS URI, and supported id_token signing algorithm, and wires
|
|
127
|
+
* a verifier that enforces signature + `iss` + `aud` + `exp` + `nbf` on
|
|
128
|
+
* subsequent {@link verifyToken} calls.
|
|
129
|
+
*
|
|
130
|
+
* **Discovery is bounded** at `discoveryTimeout` ms (default 5000) so an
|
|
131
|
+
* unreachable issuer fails fast with {@link DiscoveryError} rather than
|
|
132
|
+
* hanging your bootstrap.
|
|
133
|
+
*
|
|
134
|
+
* @throws {DiscoveryError} if discovery fails to resolve or the document
|
|
135
|
+
* is missing required fields (`token_endpoint`, `jwks_uri`,
|
|
136
|
+
* `id_token_signing_alg_values_supported`).
|
|
137
|
+
*/
|
|
138
|
+
static async fromIssuer(config) {
|
|
139
|
+
if (!config.issuer)
|
|
140
|
+
throw new Error('issuer is required');
|
|
141
|
+
if (!config.configId)
|
|
142
|
+
throw new Error('configId is required');
|
|
143
|
+
if (!config.clientId)
|
|
144
|
+
throw new Error('clientId is required');
|
|
145
|
+
if (config.clockToleranceSeconds !== undefined && config.clockToleranceSeconds < 0) {
|
|
146
|
+
throw new Error('clockToleranceSeconds must be >= 0');
|
|
147
|
+
}
|
|
148
|
+
const issuer = config.issuer.replace(/\/$/, '');
|
|
149
|
+
requireSecureUrl('issuer', issuer);
|
|
150
|
+
const discoveryUrl = `${issuer}/.well-known/openid-configuration`;
|
|
151
|
+
const timeout = config.discoveryTimeout ?? DEFAULT_DISCOVERY_TIMEOUT_MS;
|
|
152
|
+
let response;
|
|
153
|
+
try {
|
|
154
|
+
response = await fetch(discoveryUrl, {
|
|
155
|
+
method: 'GET',
|
|
156
|
+
headers: { Accept: 'application/json' },
|
|
157
|
+
signal: AbortSignal.timeout(timeout),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
throw new errors_1.DiscoveryError(`OIDC discovery failed at ${discoveryUrl}: ${err}`, { cause: err });
|
|
162
|
+
}
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
throw new errors_1.DiscoveryError(`OIDC discovery returned HTTP ${response.status} at ${discoveryUrl}`);
|
|
165
|
+
}
|
|
166
|
+
let raw;
|
|
167
|
+
try {
|
|
168
|
+
raw = (await response.json());
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
throw new errors_1.DiscoveryError(`OIDC discovery document at ${discoveryUrl} is not valid JSON`, { cause: err });
|
|
172
|
+
}
|
|
173
|
+
const required = (field) => {
|
|
174
|
+
const value = raw[field];
|
|
175
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
176
|
+
throw new errors_1.DiscoveryError(`Discovery document at ${discoveryUrl} is missing required field '${field}'`);
|
|
177
|
+
}
|
|
178
|
+
return value;
|
|
179
|
+
};
|
|
180
|
+
const tokenEndpoint = required('token_endpoint');
|
|
181
|
+
const jwksUri = required('jwks_uri');
|
|
182
|
+
// The discovered endpoints must also be https (loopback excepted) — a
|
|
183
|
+
// plaintext issuer could otherwise advertise plaintext sub-resources.
|
|
184
|
+
requireSecureUrl('token_endpoint', tokenEndpoint);
|
|
185
|
+
requireSecureUrl('jwks_uri', jwksUri);
|
|
186
|
+
const algsValue = raw['id_token_signing_alg_values_supported'];
|
|
187
|
+
if (!Array.isArray(algsValue) ||
|
|
188
|
+
algsValue.length === 0 ||
|
|
189
|
+
!algsValue.every((a) => typeof a === 'string')) {
|
|
190
|
+
throw new errors_1.DiscoveryError(`Discovery document at ${discoveryUrl} is missing required field ` +
|
|
191
|
+
`'id_token_signing_alg_values_supported' (must be a non-empty string array)`);
|
|
192
|
+
}
|
|
193
|
+
// spec.md §3.3: the algorithm allowlist MUST be a closed set
|
|
194
|
+
// ({RS256, ES256, ES384, ES512, EdDSA}). Intersect the issuer's advertised
|
|
195
|
+
// list with our allowlist — refuse to construct a client if no overlap.
|
|
196
|
+
// Without this, an issuer advertising only RS512 / PS256 / a symmetric alg
|
|
197
|
+
// would be silently trusted at verify time. Forecloses key-confusion /
|
|
198
|
+
// algorithm-substitution attacks where the JWKS happens to serve a key
|
|
199
|
+
// type matching whatever alg the JWT header advertises.
|
|
200
|
+
const allowedAlgorithms = Object.freeze(algsValue.filter((a) => DEFAULT_ID_TOKEN_ALGS.includes(a)));
|
|
201
|
+
if (allowedAlgorithms.length === 0) {
|
|
202
|
+
throw new errors_1.DiscoveryError(`Discovery document at ${discoveryUrl} advertises id_token signing algorithms ` +
|
|
203
|
+
`${JSON.stringify(algsValue)} — none are in the SDK allowlist ` +
|
|
204
|
+
`${JSON.stringify(DEFAULT_ID_TOKEN_ALGS)} (per spec.md §3.3). ` +
|
|
205
|
+
`Refusing to construct a verifier.`);
|
|
206
|
+
}
|
|
207
|
+
// RFC 8414 §3.3 / OIDC Discovery §4.3: the `issuer` value in the metadata
|
|
208
|
+
// document MUST be identical to the issuer URL the request was made to.
|
|
209
|
+
// Without this cross-check, a discovery document that advertises a different
|
|
210
|
+
// `issuer` (e.g., a shared base URL on a multi-tenant deployment) would be
|
|
211
|
+
// silently trusted, and `verifyToken` would later accept tokens issued by
|
|
212
|
+
// that *other* issuer — a cross-tenant token-acceptance bypass.
|
|
213
|
+
if (typeof raw['issuer'] !== 'string' || raw['issuer'].length === 0) {
|
|
214
|
+
throw new errors_1.DiscoveryError(`Discovery document at ${discoveryUrl} is missing required field 'issuer'`);
|
|
215
|
+
}
|
|
216
|
+
const issuerFromDoc = raw['issuer'].replace(/\/$/, '');
|
|
217
|
+
if (issuerFromDoc !== issuer) {
|
|
218
|
+
throw new errors_1.DiscoveryError(`Discovery document issuer '${issuerFromDoc}' does not match the issuer ` +
|
|
219
|
+
`requested ('${issuer}'). RFC 8414 §3.3 requires these to be identical.`);
|
|
220
|
+
}
|
|
221
|
+
const metadata = {
|
|
222
|
+
...raw,
|
|
223
|
+
issuer: issuerFromDoc,
|
|
224
|
+
token_endpoint: tokenEndpoint,
|
|
225
|
+
jwks_uri: jwksUri,
|
|
226
|
+
id_token_signing_alg_values_supported: algsValue,
|
|
227
|
+
};
|
|
228
|
+
return new HawcxOAuth({
|
|
229
|
+
configId: config.configId,
|
|
230
|
+
timeout: config.timeout,
|
|
231
|
+
clockToleranceSeconds: config.clockToleranceSeconds,
|
|
232
|
+
}, { metadata, clientId: config.clientId, allowedAlgorithms });
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Opt into `private_key_jwt` client authentication (discovery mode only).
|
|
236
|
+
* When set, the token exchange signs and attaches an RFC 7523
|
|
237
|
+
* `client_assertion` (in addition to PKCE). Without it, the exchange stays
|
|
238
|
+
* public-client + PKCE.
|
|
239
|
+
*
|
|
240
|
+
* Intended to be called once right after {@link fromIssuer}, before the
|
|
241
|
+
* client is shared. Returns `this` for chaining.
|
|
242
|
+
*/
|
|
243
|
+
/**
|
|
244
|
+
* @beta Experimental `private_key_jwt` surface; may change before stable.
|
|
245
|
+
*
|
|
246
|
+
* Returns a **new** discovery-mode client configured with the signer (sharing
|
|
247
|
+
* this client's resolved discovery state); the original is unchanged, so a
|
|
248
|
+
* configured client is immutable. Chained usage
|
|
249
|
+
* (`(await fromIssuer(...)).withClientAssertion(...)`) is unaffected.
|
|
250
|
+
*
|
|
251
|
+
* Refuses if the OP's discovery doc advertises
|
|
252
|
+
* `token_endpoint_auth_methods_supported` without `private_key_jwt`
|
|
253
|
+
* (the assertion would be silently ignored).
|
|
254
|
+
*/
|
|
255
|
+
withClientAssertion(signer) {
|
|
256
|
+
if (this.discoveryMetadata === null) {
|
|
257
|
+
throw new Error('withClientAssertion requires a discovery-mode client built via HawcxOAuth.fromIssuer(...)');
|
|
258
|
+
}
|
|
259
|
+
const methods = this.discoveryMetadata['token_endpoint_auth_methods_supported'];
|
|
260
|
+
if (Array.isArray(methods) && methods.length > 0 && !methods.includes('private_key_jwt')) {
|
|
261
|
+
throw new errors_1.DiscoveryError(`The OP does not advertise 'private_key_jwt' in token_endpoint_auth_methods_supported ` +
|
|
262
|
+
`(${JSON.stringify(methods)}); refusing to attach a client_assertion that would be ` +
|
|
263
|
+
`ignored. Register the client for private_key_jwt in the Hawcx admin console.`);
|
|
264
|
+
}
|
|
265
|
+
return new HawcxOAuth({
|
|
266
|
+
configId: this.configId,
|
|
267
|
+
timeout: this.timeout,
|
|
268
|
+
clockToleranceSeconds: this.clockToleranceSeconds,
|
|
269
|
+
}, {
|
|
270
|
+
metadata: this.discoveryMetadata,
|
|
271
|
+
clientId: this.expectedAudience,
|
|
272
|
+
allowedAlgorithms: this.allowedAlgorithms,
|
|
273
|
+
signer,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Exchange authorization code for id_token and verified claims.
|
|
278
|
+
*
|
|
279
|
+
* @param code - Authorization code from auth flow
|
|
280
|
+
* @param codeVerifier - PKCE code verifier
|
|
281
|
+
* @param redirectUri - Optional. If your original authorization request
|
|
282
|
+
* registered a `redirect_uri`, RFC 6749 §4.1.3 requires the token
|
|
283
|
+
* request to carry the same value. Omit if the auth request also omitted it.
|
|
284
|
+
* @param expectedNonce - Optional. If your authorization request bound a
|
|
285
|
+
* `nonce`, pass it here so the returned id_token's `nonce` is verified.
|
|
286
|
+
* Required whenever the token carries a nonce (verification refuses
|
|
287
|
+
* otherwise — OIDC Core §3.1.3.7).
|
|
288
|
+
*/
|
|
289
|
+
async exchangeCode(code, codeVerifier, redirectUri, expectedNonce) {
|
|
290
|
+
if (!code)
|
|
291
|
+
throw new errors_1.TokenExchangeError('code is required');
|
|
292
|
+
if (!codeVerifier)
|
|
293
|
+
throw new errors_1.TokenExchangeError('codeVerifier is required');
|
|
294
|
+
const body = new URLSearchParams();
|
|
295
|
+
body.append('grant_type', 'authorization_code');
|
|
296
|
+
body.append('code', code);
|
|
297
|
+
body.append('code_verifier', codeVerifier);
|
|
298
|
+
if (redirectUri) {
|
|
299
|
+
body.append('redirect_uri', redirectUri);
|
|
300
|
+
}
|
|
301
|
+
const signer = this.clientAssertionSigner;
|
|
302
|
+
if (signer !== null && this.discoveryMetadata !== null) {
|
|
303
|
+
// private_key_jwt: include client_id (parity with the demo RP) + the
|
|
304
|
+
// signed assertion. aud is the discovered token_endpoint string exactly,
|
|
305
|
+
// which the OP pins for the assertion. PKCE fields above are retained.
|
|
306
|
+
// In this guarded branch discoveryMetadata !== null, so expectedAudience
|
|
307
|
+
// is the clientId (non-null). Assert rather than mask with ''.
|
|
308
|
+
const clientId = this.expectedAudience;
|
|
309
|
+
body.append('client_id', clientId);
|
|
310
|
+
body.append('client_assertion_type', client_assertion_1.CLIENT_ASSERTION_TYPE);
|
|
311
|
+
body.append('client_assertion', await signer.sign(clientId, this.discoveryMetadata.token_endpoint));
|
|
312
|
+
}
|
|
313
|
+
let response;
|
|
314
|
+
try {
|
|
315
|
+
response = await fetch(this.tokenEndpoint, {
|
|
316
|
+
method: 'POST',
|
|
317
|
+
headers: {
|
|
318
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
319
|
+
'X-Config-Id': this.configId,
|
|
320
|
+
Accept: 'application/json',
|
|
321
|
+
},
|
|
322
|
+
body: body.toString(),
|
|
323
|
+
signal: AbortSignal.timeout(this.timeout),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
throw new errors_1.TokenExchangeError(`Network error: ${err}`);
|
|
328
|
+
}
|
|
329
|
+
if (!response.ok) {
|
|
330
|
+
let errorMsg = `HTTP ${response.status}`;
|
|
331
|
+
// Read the body as text first so a non-JSON error (e.g. an HTML 502 from
|
|
332
|
+
// a gateway) is preserved in the message instead of being swallowed.
|
|
333
|
+
const rawBody = await response.text().catch(() => '');
|
|
334
|
+
let errCode;
|
|
335
|
+
let errDesc;
|
|
336
|
+
if (rawBody) {
|
|
337
|
+
try {
|
|
338
|
+
const data = JSON.parse(rawBody);
|
|
339
|
+
errCode = data.error;
|
|
340
|
+
errDesc = data.error_description;
|
|
341
|
+
errorMsg = data.error_description || data.error || `${errorMsg}: ${rawBody}`;
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
errorMsg = `${errorMsg}: ${rawBody}`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
throw new errors_1.TokenExchangeError(errorMsg, response.status, {
|
|
348
|
+
error: errCode,
|
|
349
|
+
errorDescription: errDesc,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const data = (await response.json());
|
|
353
|
+
const idToken = data.id_token;
|
|
354
|
+
if (!idToken) {
|
|
355
|
+
throw new errors_1.TokenExchangeError('Response missing id_token');
|
|
356
|
+
}
|
|
357
|
+
const claims = await this.verifyToken(idToken, expectedNonce !== undefined ? { nonce: expectedNonce } : undefined);
|
|
358
|
+
return { idToken, claims };
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Verify a JWT token and return its claims.
|
|
362
|
+
*
|
|
363
|
+
* In **discovery mode**, enforces signature + `iss` + `aud` + `exp` + `nbf`
|
|
364
|
+
* (and the optional `nonce` claim if `options.nonce` is provided).
|
|
365
|
+
*
|
|
366
|
+
* In **legacy mode**, only the signature is verified. Audience and issuer
|
|
367
|
+
* claims are not checked, matching the pre-5.x behavior.
|
|
368
|
+
*/
|
|
369
|
+
async verifyToken(token, options) {
|
|
370
|
+
if (!token)
|
|
371
|
+
throw new errors_1.TokenVerificationError('token is required');
|
|
372
|
+
try {
|
|
373
|
+
const jwks = this.getJwks();
|
|
374
|
+
const { payload } = await (0, jose_1.jwtVerify)(token, jwks, {
|
|
375
|
+
...(this.expectedIssuer !== null && { issuer: this.expectedIssuer }),
|
|
376
|
+
...(this.expectedAudience !== null && { audience: this.expectedAudience }),
|
|
377
|
+
// Enforce the allowlist that fromIssuer pinned at construction time.
|
|
378
|
+
// Without this, jose accepts any algorithm whose key happens to be
|
|
379
|
+
// present in the JWKS — a key-confusion / alg-substitution path.
|
|
380
|
+
// `as string[]` because jose's type is mutable; ours is readonly.
|
|
381
|
+
...(this.allowedAlgorithms !== null && {
|
|
382
|
+
algorithms: this.allowedAlgorithms,
|
|
383
|
+
}),
|
|
384
|
+
// Fail closed on a token with no `exp`/`iat` (jose only checks them
|
|
385
|
+
// when present). In discovery mode we require both; legacy mode keeps
|
|
386
|
+
// 4.x behavior. A missing exp would otherwise read as never-expiring.
|
|
387
|
+
...(this.discoveryMetadata !== null && { requiredClaims: ['exp', 'iat'] }),
|
|
388
|
+
clockTolerance: this.clockToleranceSeconds,
|
|
389
|
+
});
|
|
390
|
+
if (options?.nonce !== undefined) {
|
|
391
|
+
if (payload.nonce !== options.nonce) {
|
|
392
|
+
throw new errors_1.TokenVerificationError(`Token nonce mismatch (expected '${options.nonce}', got '${payload.nonce ?? '<missing>'}')`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
else if (payload.nonce !== undefined && payload.nonce !== null) {
|
|
396
|
+
// OIDC Core §3.1.3.7 step 11: a present nonce MUST be verified. We have
|
|
397
|
+
// no expected value, so refuse rather than silently accept — pass the
|
|
398
|
+
// nonce you bound at /authorize via options.nonce (or exchangeCode's
|
|
399
|
+
// expectedNonce). Only RPs that actually use a nonce hit this.
|
|
400
|
+
throw new errors_1.TokenVerificationError('Token carries a nonce but none was provided to verify against. ' +
|
|
401
|
+
'Pass the expected nonce (options.nonce / exchangeCode expectedNonce).');
|
|
402
|
+
}
|
|
403
|
+
return payload;
|
|
404
|
+
}
|
|
405
|
+
catch (err) {
|
|
406
|
+
if (err instanceof errors_1.TokenVerificationError)
|
|
407
|
+
throw err;
|
|
408
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
409
|
+
// jose exposes machine-readable codes via `(err as any).code` for
|
|
410
|
+
// common JWT failures. Prefer that over string matching when present;
|
|
411
|
+
// fall back to substring sniffs for older versions / wrapped errors.
|
|
412
|
+
const code = err instanceof Error ? err.code : undefined;
|
|
413
|
+
// Map jose errors to our error types
|
|
414
|
+
if (code === 'ERR_JWT_EXPIRED' || message.includes('expired')) {
|
|
415
|
+
throw new errors_1.TokenVerificationError('Token expired');
|
|
416
|
+
}
|
|
417
|
+
if (code === 'ERR_JWT_CLAIM_VALIDATION_FAILED') {
|
|
418
|
+
// The `claim` property tells us which claim mismatched
|
|
419
|
+
const claim = err.claim;
|
|
420
|
+
if (claim === 'iss')
|
|
421
|
+
throw new errors_1.TokenVerificationError(`Unexpected JWT issuer: ${message}`);
|
|
422
|
+
if (claim === 'aud')
|
|
423
|
+
throw new errors_1.TokenVerificationError(`Unexpected JWT audience: ${message}`);
|
|
424
|
+
if (claim === 'nbf')
|
|
425
|
+
throw new errors_1.TokenVerificationError('Token not yet valid');
|
|
426
|
+
}
|
|
427
|
+
if (message.includes('not yet valid') || message.includes('nbf')) {
|
|
428
|
+
throw new errors_1.TokenVerificationError('Token not yet valid');
|
|
429
|
+
}
|
|
430
|
+
if (message.includes('signature')) {
|
|
431
|
+
throw new errors_1.TokenVerificationError('Invalid signature');
|
|
432
|
+
}
|
|
433
|
+
if (message.includes('audience') || message.includes('"aud"')) {
|
|
434
|
+
throw new errors_1.TokenVerificationError(`Unexpected JWT audience: ${message}`);
|
|
435
|
+
}
|
|
436
|
+
if (message.includes('issuer') || message.includes('"iss"')) {
|
|
437
|
+
throw new errors_1.TokenVerificationError(`Unexpected JWT issuer: ${message}`);
|
|
438
|
+
}
|
|
439
|
+
throw new errors_1.TokenVerificationError(`Token verification failed: ${message}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Get or create the remote JWKS. jose handles caching + concurrent-fetch
|
|
444
|
+
* coalescing internally.
|
|
445
|
+
*
|
|
446
|
+
* No single-flight guard is needed here: this method is fully synchronous
|
|
447
|
+
* (no `await` between the null-check and the assignment), so within Node's
|
|
448
|
+
* single-threaded event loop the first caller assigns `this.jwks` before any
|
|
449
|
+
* other code runs. Two concurrent `verifyToken` calls therefore cannot create
|
|
450
|
+
* duplicate `RemoteJWKSet` instances.
|
|
451
|
+
*/
|
|
452
|
+
getJwks() {
|
|
453
|
+
if (!this.jwks) {
|
|
454
|
+
const jwksUrl = new URL(this.jwksUrl);
|
|
455
|
+
// Only set the X-Config-Id header for the legacy `/keys` endpoint; the
|
|
456
|
+
// OIDC-discovered `/.well-known/jwks.json` is public and tenant-agnostic.
|
|
457
|
+
const isLegacyKeysEndpoint = this.discoveryMetadata === null;
|
|
458
|
+
this.jwks = (0, jose_1.createRemoteJWKSet)(jwksUrl, {
|
|
459
|
+
// Bound the JWKS fetch explicitly (jose's default is 5s; pin it to the
|
|
460
|
+
// configured request timeout so a stalled keys endpoint can't hang
|
|
461
|
+
// verification longer than intended).
|
|
462
|
+
timeoutDuration: this.timeout,
|
|
463
|
+
...(isLegacyKeysEndpoint && {
|
|
464
|
+
headers: { 'X-Config-Id': this.configId },
|
|
465
|
+
}),
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
return this.jwks;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Drop the cached JWKS so the next `verifyToken` re-fetches it. Useful after
|
|
472
|
+
* an operator-triggered signing-key rotation, or in tests.
|
|
473
|
+
*
|
|
474
|
+
* Canonical name, aligned with the Java (`refreshJwks`) and Python
|
|
475
|
+
* (`refresh_jwks`) SDKs.
|
|
476
|
+
*/
|
|
477
|
+
refreshJwks() {
|
|
478
|
+
this.jwks = null;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* @deprecated since 5.1.0 — renamed to {@link refreshJwks} for cross-SDK
|
|
482
|
+
* consistency. Will be removed in 6.0.0. Behaviour is identical.
|
|
483
|
+
*/
|
|
484
|
+
clearCache() {
|
|
485
|
+
// One-time deprecation nudge per instance (per-instance so tests and
|
|
486
|
+
// multi-tenant setups each get warned, while a single instance doesn't spam).
|
|
487
|
+
if (!this.clearCacheWarned) {
|
|
488
|
+
this.clearCacheWarned = true;
|
|
489
|
+
// eslint-disable-next-line no-console
|
|
490
|
+
console.warn('[@hawcx/oauth-client] clearCache() is deprecated; use refreshJwks(). ' +
|
|
491
|
+
'clearCache() will be removed in 6.0.0.');
|
|
492
|
+
}
|
|
493
|
+
this.refreshJwks();
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
exports.HawcxOAuth = HawcxOAuth;
|
|
497
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,+BAAsE;AACtE,yDAAkF;AAClF,qCAAsF;AAEtF,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,kBAAkB,GAAG,KAAM,CAAC;AAClC,gFAAgF;AAChF,MAAM,4BAA4B,GAAG,IAAK,CAAC;AAC3C;;;;;;GAMG;AACH,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAC3C;;;;;GAKG;AACH,MAAM,qBAAqB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC7D,OAAO;IACP,OAAO;IACP,OAAO;I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BAAoB,IAAI;oBAC1B,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,CAAC,QAAQ,EAAE;iBAC1C,CAAC;aACH,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,WAAW;QACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,qEAAqE;QACrE,8EAA8E;QAC9E,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC3B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC7B,sCAAsC;YACtC,OAAO,CAAC,IAAI,CACV,uEAAuE;gBACrE,wCAAwC,CAC3C,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;CAGF;AA3fD,gCA2fC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DelegationTransport } from '../delegation/transport';
|
|
2
|
+
import { DelegationKeyMaterial } from '../delegation/factory';
|
|
3
|
+
import { StepUpClientBaseOptions, StepUpConsumeOptions, StepUpConsumeResponse, StepUpStartOptions, StepUpStartTokenResponse } from './types';
|
|
4
|
+
export interface StepUpClientSecretKeyOptions extends StepUpClientBaseOptions {
|
|
5
|
+
secretKey: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
}
|
|
8
|
+
export type StepUpClientKeyOptions = StepUpClientBaseOptions & DelegationKeyMaterial & {
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class StepUpClient {
|
|
12
|
+
private transport;
|
|
13
|
+
private options;
|
|
14
|
+
private apiKey?;
|
|
15
|
+
constructor(options: {
|
|
16
|
+
transport: DelegationTransport;
|
|
17
|
+
clientOptions: StepUpClientBaseOptions;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
});
|
|
20
|
+
static fromSecretKey(options: StepUpClientSecretKeyOptions): StepUpClient;
|
|
21
|
+
static fromKeys(options: StepUpClientKeyOptions): StepUpClient;
|
|
22
|
+
private buildExtraHeaders;
|
|
23
|
+
startToken(options: StepUpStartOptions): Promise<StepUpStartTokenResponse>;
|
|
24
|
+
consumeReceipt(options: StepUpConsumeOptions): Promise<StepUpConsumeResponse>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/stepup/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAuD,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnH,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,4BAA6B,SAAQ,uBAAuB;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,sBAAsB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3G,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,OAAO,EAAE;QACnB,SAAS,EAAE,mBAAmB,CAAC;QAC/B,aAAa,EAAE,uBAAuB,CAAC;QACvC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAMD,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,4BAA4B,GAAG,YAAY;IAMzE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,YAAY;IAM9D,OAAO,CAAC,iBAAiB;IAmBnB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAuB1E,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAoBpF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StepUpClient = void 0;
|
|
4
|
+
const factory_1 = require("../delegation/factory");
|
|
5
|
+
const exceptions_1 = require("../delegation/exceptions");
|
|
6
|
+
class StepUpClient {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.transport = options.transport;
|
|
9
|
+
this.options = options.clientOptions;
|
|
10
|
+
this.apiKey = options.apiKey;
|
|
11
|
+
}
|
|
12
|
+
static fromSecretKey(options) {
|
|
13
|
+
const { apiKey } = options;
|
|
14
|
+
const transport = (0, factory_1.buildTransportFromSecretKey)(options);
|
|
15
|
+
return new StepUpClient({ transport, clientOptions: options, apiKey });
|
|
16
|
+
}
|
|
17
|
+
static fromKeys(options) {
|
|
18
|
+
const { apiKey } = options;
|
|
19
|
+
const transport = (0, factory_1.buildTransportFromKeys)(options);
|
|
20
|
+
return new StepUpClient({ transport, clientOptions: options, apiKey });
|
|
21
|
+
}
|
|
22
|
+
buildExtraHeaders() {
|
|
23
|
+
const headers = {
|
|
24
|
+
'X-Hawcx-Protocol-Version': '1',
|
|
25
|
+
...(this.options.extraHeaders || {}),
|
|
26
|
+
};
|
|
27
|
+
if (this.apiKey) {
|
|
28
|
+
headers['apikey'] = this.apiKey;
|
|
29
|
+
}
|
|
30
|
+
if (this.options.relyingParty) {
|
|
31
|
+
headers['X-Relying-Party'] = this.options.relyingParty;
|
|
32
|
+
}
|
|
33
|
+
if (this.options.tenantHeaderName && this.options.tenantHeaderValue) {
|
|
34
|
+
headers[this.options.tenantHeaderName] = this.options.tenantHeaderValue;
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
async startToken(options) {
|
|
39
|
+
try {
|
|
40
|
+
const apiPrefix = this.options.apiPrefix ?? '/v1';
|
|
41
|
+
return (await this.transport.send({
|
|
42
|
+
endpoint: `${apiPrefix}/management/stepup/start-token`,
|
|
43
|
+
payload: {
|
|
44
|
+
subject_userid: options.userId,
|
|
45
|
+
purpose: options.purpose,
|
|
46
|
+
new_mfa_method: options.newMfaMethod,
|
|
47
|
+
},
|
|
48
|
+
headers: this.buildExtraHeaders(),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof exceptions_1.DelegationError) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
throw new exceptions_1.DelegationRequestError('stepup.start-token failed', { cause: error });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async consumeReceipt(options) {
|
|
59
|
+
try {
|
|
60
|
+
const apiPrefix = this.options.apiPrefix ?? '/v1';
|
|
61
|
+
return (await this.transport.send({
|
|
62
|
+
endpoint: `${apiPrefix}/management/stepup/consume`,
|
|
63
|
+
payload: {
|
|
64
|
+
step_up_receipt: options.receipt,
|
|
65
|
+
},
|
|
66
|
+
headers: this.buildExtraHeaders(),
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof exceptions_1.DelegationError) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
throw new exceptions_1.DelegationRequestError('stepup.consume failed', { cause: error });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.StepUpClient = StepUpClient;
|
|
78
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/stepup/client.ts"],"names":[],"mappings":";;;AACA,mDAAmH;AACnH,yDAAmF;AAgBnF,MAAa,YAAY;IAKvB,YAAY,OAIX;QACC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IA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