@auth0/auth0-spa-js 2.12.0 → 2.13.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 +4 -2
- package/dist/auth0-spa-js.development.js +286 -20
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +306 -20
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +32 -0
- package/dist/typings/errors.d.ts +15 -1
- package/dist/typings/global.d.ts +2 -2
- package/dist/typings/index.d.ts +3 -0
- package/dist/typings/mfa/MfaApiClient.d.ts +225 -0
- package/dist/typings/mfa/MfaContextManager.d.ts +79 -0
- package/dist/typings/mfa/constants.d.ts +23 -0
- package/dist/typings/mfa/errors.d.ts +117 -0
- package/dist/typings/mfa/index.d.ts +4 -0
- package/dist/typings/mfa/types.d.ts +181 -0
- package/dist/typings/mfa/utils.d.ts +23 -0
- package/dist/typings/utils.d.ts +2 -1
- package/dist/typings/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/Auth0Client.ts +54 -3
- package/src/dpop/utils.ts +4 -1
- package/src/errors.ts +12 -1
- package/src/global.ts +24 -1
- package/src/http.ts +1 -1
- package/src/index.ts +22 -0
- package/src/mfa/MfaApiClient.ts +425 -0
- package/src/mfa/MfaContextManager.ts +128 -0
- package/src/mfa/constants.ts +48 -0
- package/src/mfa/errors.ts +154 -0
- package/src/mfa/index.ts +24 -0
- package/src/mfa/types.ts +209 -0
- package/src/mfa/utils.ts +41 -0
- package/src/utils.ts +7 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ npm install @auth0/auth0-spa-js
|
|
|
30
30
|
From the CDN:
|
|
31
31
|
|
|
32
32
|
```html
|
|
33
|
-
<script src="https://cdn.auth0.com/js/auth0-spa-js/2.
|
|
33
|
+
<script src="https://cdn.auth0.com/js/auth0-spa-js/2.13/auth0-spa-js.production.js"></script>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
### Configure Auth0
|
|
@@ -114,7 +114,9 @@ window.addEventListener('load', async () => {
|
|
|
114
114
|
});
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
### More Examples
|
|
118
|
+
|
|
119
|
+
For comprehensive examples covering various scenarios including logging out, calling APIs, refresh tokens, organizations, MFA, DPoP, and more, see the [EXAMPLES.md](https://github.com/auth0/auth0-spa-js/blob/main/EXAMPLES.md) document.
|
|
118
120
|
|
|
119
121
|
## API Reference
|
|
120
122
|
|
|
@@ -529,7 +529,7 @@
|
|
|
529
529
|
return SuperTokensLock;
|
|
530
530
|
}();
|
|
531
531
|
var _default = browserTabsLock.default = SuperTokensLock;
|
|
532
|
-
var version = "2.
|
|
532
|
+
var version = "2.13.0";
|
|
533
533
|
const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
|
|
534
534
|
const DEFAULT_POPUP_CONFIG_OPTIONS = {
|
|
535
535
|
timeoutInSeconds: DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS
|
|
@@ -606,9 +606,10 @@
|
|
|
606
606
|
}
|
|
607
607
|
}
|
|
608
608
|
class MfaRequiredError extends GenericError {
|
|
609
|
-
constructor(error, error_description, mfa_token) {
|
|
609
|
+
constructor(error, error_description, mfa_token, mfa_requirements) {
|
|
610
610
|
super(error, error_description);
|
|
611
611
|
this.mfa_token = mfa_token;
|
|
612
|
+
this.mfa_requirements = mfa_requirements;
|
|
612
613
|
Object.setPrototypeOf(this, MfaRequiredError.prototype);
|
|
613
614
|
}
|
|
614
615
|
}
|
|
@@ -748,13 +749,19 @@
|
|
|
748
749
|
key: "env",
|
|
749
750
|
type: [ "object" ]
|
|
750
751
|
} ];
|
|
751
|
-
const stripAuth0Client =
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
752
|
+
const stripAuth0Client = function stripAuth0Client(auth0Client) {
|
|
753
|
+
let excludeEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
754
|
+
return Object.keys(auth0Client).reduce(((acc, key) => {
|
|
755
|
+
if (excludeEnv && key === "env") {
|
|
756
|
+
return acc;
|
|
757
|
+
}
|
|
758
|
+
const allowedProperty = ALLOWED_AUTH0CLIENT_PROPERTIES.find((p => p.key === key));
|
|
759
|
+
if (allowedProperty && allowedProperty.type.includes(typeof auth0Client[key])) {
|
|
760
|
+
acc[key] = auth0Client[key];
|
|
761
|
+
}
|
|
762
|
+
return acc;
|
|
763
|
+
}), {});
|
|
764
|
+
};
|
|
758
765
|
const createQueryParams = _a => {
|
|
759
766
|
var {clientId: client_id} = _a, params = __rest(_a, [ "clientId" ]);
|
|
760
767
|
return new URLSearchParams(stripUndefined(Object.assign({
|
|
@@ -1099,7 +1106,7 @@
|
|
|
1099
1106
|
}
|
|
1100
1107
|
const DPOP_NONCE_HEADER = "dpop-nonce";
|
|
1101
1108
|
const KEY_PAIR_ALGORITHM = "ES256";
|
|
1102
|
-
const SUPPORTED_GRANT_TYPES = [ "authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:token-exchange" ];
|
|
1109
|
+
const SUPPORTED_GRANT_TYPES = [ "authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:token-exchange", "http://auth0.com/oauth/grant-type/mfa-oob", "http://auth0.com/oauth/grant-type/mfa-otp", "http://auth0.com/oauth/grant-type/mfa-recovery-code" ];
|
|
1103
1110
|
function generateKeyPair() {
|
|
1104
1111
|
return generateKeyPair$1(KEY_PAIR_ALGORITHM, {
|
|
1105
1112
|
extractable: false
|
|
@@ -1212,7 +1219,7 @@
|
|
|
1212
1219
|
if (!ok) {
|
|
1213
1220
|
const errorMessage = error_description || "HTTP error. Unable to fetch ".concat(url);
|
|
1214
1221
|
if (error === "mfa_required") {
|
|
1215
|
-
throw new MfaRequiredError(error, errorMessage, data.mfa_token);
|
|
1222
|
+
throw new MfaRequiredError(error, errorMessage, data.mfa_token, data.mfa_requirements);
|
|
1216
1223
|
}
|
|
1217
1224
|
if (error === "missing_refresh_token") {
|
|
1218
1225
|
throw new MissingRefreshTokenError(audience, scope);
|
|
@@ -2276,6 +2283,57 @@
|
|
|
2276
2283
|
Object.setPrototypeOf(this, MyAccountApiError.prototype);
|
|
2277
2284
|
}
|
|
2278
2285
|
}
|
|
2286
|
+
const FACTOR_MAPPING = {
|
|
2287
|
+
otp: {
|
|
2288
|
+
authenticatorTypes: [ "otp" ]
|
|
2289
|
+
},
|
|
2290
|
+
sms: {
|
|
2291
|
+
authenticatorTypes: [ "oob" ],
|
|
2292
|
+
oobChannels: [ "sms" ]
|
|
2293
|
+
},
|
|
2294
|
+
email: {
|
|
2295
|
+
authenticatorTypes: [ "oob" ],
|
|
2296
|
+
oobChannels: [ "email" ]
|
|
2297
|
+
},
|
|
2298
|
+
push: {
|
|
2299
|
+
authenticatorTypes: [ "oob" ],
|
|
2300
|
+
oobChannels: [ "auth0" ]
|
|
2301
|
+
},
|
|
2302
|
+
voice: {
|
|
2303
|
+
authenticatorTypes: [ "oob" ],
|
|
2304
|
+
oobChannels: [ "voice" ]
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
const MfaGrantTypes = {
|
|
2308
|
+
OTP: "http://auth0.com/oauth/grant-type/mfa-otp",
|
|
2309
|
+
OOB: "http://auth0.com/oauth/grant-type/mfa-oob",
|
|
2310
|
+
RECOVERY_CODE: "http://auth0.com/oauth/grant-type/mfa-recovery-code"
|
|
2311
|
+
};
|
|
2312
|
+
function getAuthJsEnrollParams(params) {
|
|
2313
|
+
const mapping = FACTOR_MAPPING[params.factorType];
|
|
2314
|
+
return Object.assign(Object.assign(Object.assign({
|
|
2315
|
+
mfaToken: params.mfaToken,
|
|
2316
|
+
authenticatorTypes: mapping.authenticatorTypes
|
|
2317
|
+
}, mapping.oobChannels && {
|
|
2318
|
+
oobChannels: mapping.oobChannels
|
|
2319
|
+
}), "phoneNumber" in params && {
|
|
2320
|
+
phoneNumber: params.phoneNumber
|
|
2321
|
+
}), "email" in params && {
|
|
2322
|
+
email: params.email
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
function getGrantType(params) {
|
|
2326
|
+
if ("otp" in params && params.otp) {
|
|
2327
|
+
return MfaGrantTypes.OTP;
|
|
2328
|
+
}
|
|
2329
|
+
if ("oobCode" in params && params.oobCode) {
|
|
2330
|
+
return MfaGrantTypes.OOB;
|
|
2331
|
+
}
|
|
2332
|
+
if ("recoveryCode" in params && params.recoveryCode) {
|
|
2333
|
+
return MfaGrantTypes.RECOVERY_CODE;
|
|
2334
|
+
}
|
|
2335
|
+
return undefined;
|
|
2336
|
+
}
|
|
2279
2337
|
function _OverloadYield(e, d) {
|
|
2280
2338
|
this.v = e, this.k = d;
|
|
2281
2339
|
}
|
|
@@ -6503,7 +6561,7 @@
|
|
|
6503
6561
|
[curr[0]]: curr[1]
|
|
6504
6562
|
})), {});
|
|
6505
6563
|
}
|
|
6506
|
-
var MfaError = class MfaError extends Error {
|
|
6564
|
+
var MfaError$1 = class MfaError extends Error {
|
|
6507
6565
|
constructor(code, message, cause) {
|
|
6508
6566
|
super(message);
|
|
6509
6567
|
_defineProperty(this, "cause", void 0);
|
|
@@ -6516,25 +6574,25 @@
|
|
|
6516
6574
|
};
|
|
6517
6575
|
}
|
|
6518
6576
|
};
|
|
6519
|
-
var MfaListAuthenticatorsError = class extends MfaError {
|
|
6577
|
+
var MfaListAuthenticatorsError$1 = class extends MfaError$1 {
|
|
6520
6578
|
constructor(message, cause) {
|
|
6521
6579
|
super("mfa_list_authenticators_error", message, cause);
|
|
6522
6580
|
this.name = "MfaListAuthenticatorsError";
|
|
6523
6581
|
}
|
|
6524
6582
|
};
|
|
6525
|
-
var MfaEnrollmentError = class extends MfaError {
|
|
6583
|
+
var MfaEnrollmentError$1 = class extends MfaError$1 {
|
|
6526
6584
|
constructor(message, cause) {
|
|
6527
6585
|
super("mfa_enrollment_error", message, cause);
|
|
6528
6586
|
this.name = "MfaEnrollmentError";
|
|
6529
6587
|
}
|
|
6530
6588
|
};
|
|
6531
|
-
var MfaDeleteAuthenticatorError = class extends MfaError {
|
|
6589
|
+
var MfaDeleteAuthenticatorError = class extends MfaError$1 {
|
|
6532
6590
|
constructor(message, cause) {
|
|
6533
6591
|
super("mfa_delete_authenticator_error", message, cause);
|
|
6534
6592
|
this.name = "MfaDeleteAuthenticatorError";
|
|
6535
6593
|
}
|
|
6536
6594
|
};
|
|
6537
|
-
var MfaChallengeError = class extends MfaError {
|
|
6595
|
+
var MfaChallengeError$1 = class extends MfaError$1 {
|
|
6538
6596
|
constructor(message, cause) {
|
|
6539
6597
|
super("mfa_challenge_error", message, cause);
|
|
6540
6598
|
this.name = "MfaChallengeError";
|
|
@@ -6608,7 +6666,7 @@
|
|
|
6608
6666
|
});
|
|
6609
6667
|
if (!response.ok) {
|
|
6610
6668
|
const error = await response.json();
|
|
6611
|
-
throw new MfaListAuthenticatorsError(error.error_description || "Failed to list authenticators", error);
|
|
6669
|
+
throw new MfaListAuthenticatorsError$1(error.error_description || "Failed to list authenticators", error);
|
|
6612
6670
|
}
|
|
6613
6671
|
const apiResponse = await response.json();
|
|
6614
6672
|
return apiResponse.map(transformAuthenticatorResponse);
|
|
@@ -6638,7 +6696,7 @@
|
|
|
6638
6696
|
});
|
|
6639
6697
|
if (!response.ok) {
|
|
6640
6698
|
const error = await response.json();
|
|
6641
|
-
throw new MfaEnrollmentError(error.error_description || "Failed to enroll authenticator", error);
|
|
6699
|
+
throw new MfaEnrollmentError$1(error.error_description || "Failed to enroll authenticator", error);
|
|
6642
6700
|
}
|
|
6643
6701
|
const apiResponse = await response.json();
|
|
6644
6702
|
return transformEnrollmentResponse(apiResponse);
|
|
@@ -6678,7 +6736,7 @@
|
|
|
6678
6736
|
});
|
|
6679
6737
|
if (!response.ok) {
|
|
6680
6738
|
const error = await response.json();
|
|
6681
|
-
throw new MfaChallengeError(error.error_description || "Failed to challenge authenticator", error);
|
|
6739
|
+
throw new MfaChallengeError$1(error.error_description || "Failed to challenge authenticator", error);
|
|
6682
6740
|
}
|
|
6683
6741
|
const apiResponse = await response.json();
|
|
6684
6742
|
return transformChallengeResponse(apiResponse);
|
|
@@ -7109,6 +7167,194 @@
|
|
|
7109
7167
|
codeVerifier: codeVerifier
|
|
7110
7168
|
};
|
|
7111
7169
|
}
|
|
7170
|
+
class MfaError extends GenericError {
|
|
7171
|
+
constructor(error, error_description) {
|
|
7172
|
+
super(error, error_description);
|
|
7173
|
+
Object.setPrototypeOf(this, MfaError.prototype);
|
|
7174
|
+
}
|
|
7175
|
+
static fromPayload(_ref) {
|
|
7176
|
+
let {error: error, error_description: error_description} = _ref;
|
|
7177
|
+
return new MfaError(error, error_description);
|
|
7178
|
+
}
|
|
7179
|
+
}
|
|
7180
|
+
class MfaListAuthenticatorsError extends MfaError {
|
|
7181
|
+
constructor(error, error_description) {
|
|
7182
|
+
super(error, error_description);
|
|
7183
|
+
Object.setPrototypeOf(this, MfaListAuthenticatorsError.prototype);
|
|
7184
|
+
}
|
|
7185
|
+
}
|
|
7186
|
+
class MfaEnrollmentError extends MfaError {
|
|
7187
|
+
constructor(error, error_description) {
|
|
7188
|
+
super(error, error_description);
|
|
7189
|
+
Object.setPrototypeOf(this, MfaEnrollmentError.prototype);
|
|
7190
|
+
}
|
|
7191
|
+
}
|
|
7192
|
+
class MfaChallengeError extends MfaError {
|
|
7193
|
+
constructor(error, error_description) {
|
|
7194
|
+
super(error, error_description);
|
|
7195
|
+
Object.setPrototypeOf(this, MfaChallengeError.prototype);
|
|
7196
|
+
}
|
|
7197
|
+
}
|
|
7198
|
+
class MfaVerifyError extends MfaError {
|
|
7199
|
+
constructor(error, error_description) {
|
|
7200
|
+
super(error, error_description);
|
|
7201
|
+
Object.setPrototypeOf(this, MfaVerifyError.prototype);
|
|
7202
|
+
}
|
|
7203
|
+
}
|
|
7204
|
+
class MfaEnrollmentFactorsError extends MfaError {
|
|
7205
|
+
constructor(error, error_description) {
|
|
7206
|
+
super(error, error_description);
|
|
7207
|
+
Object.setPrototypeOf(this, MfaEnrollmentFactorsError.prototype);
|
|
7208
|
+
}
|
|
7209
|
+
}
|
|
7210
|
+
const DEFAULT_TTL_MS = 10 * 60 * 1e3;
|
|
7211
|
+
class MfaContextManager {
|
|
7212
|
+
constructor() {
|
|
7213
|
+
let ttlMs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_TTL_MS;
|
|
7214
|
+
this.contexts = new Map;
|
|
7215
|
+
this.ttlMs = ttlMs;
|
|
7216
|
+
}
|
|
7217
|
+
set(mfaToken, context) {
|
|
7218
|
+
this.cleanup();
|
|
7219
|
+
this.contexts.set(mfaToken, Object.assign(Object.assign({}, context), {
|
|
7220
|
+
createdAt: Date.now()
|
|
7221
|
+
}));
|
|
7222
|
+
}
|
|
7223
|
+
get(mfaToken) {
|
|
7224
|
+
const context = this.contexts.get(mfaToken);
|
|
7225
|
+
if (!context) {
|
|
7226
|
+
return undefined;
|
|
7227
|
+
}
|
|
7228
|
+
if (Date.now() - context.createdAt > this.ttlMs) {
|
|
7229
|
+
this.contexts.delete(mfaToken);
|
|
7230
|
+
return undefined;
|
|
7231
|
+
}
|
|
7232
|
+
return context;
|
|
7233
|
+
}
|
|
7234
|
+
remove(mfaToken) {
|
|
7235
|
+
this.contexts.delete(mfaToken);
|
|
7236
|
+
}
|
|
7237
|
+
cleanup() {
|
|
7238
|
+
const now = Date.now();
|
|
7239
|
+
for (const [key, value] of this.contexts) {
|
|
7240
|
+
if (now - value.createdAt > this.ttlMs) {
|
|
7241
|
+
this.contexts.delete(key);
|
|
7242
|
+
}
|
|
7243
|
+
}
|
|
7244
|
+
}
|
|
7245
|
+
get size() {
|
|
7246
|
+
return this.contexts.size;
|
|
7247
|
+
}
|
|
7248
|
+
}
|
|
7249
|
+
class MfaApiClient {
|
|
7250
|
+
constructor(authJsMfaClient, auth0Client) {
|
|
7251
|
+
this.authJsMfaClient = authJsMfaClient;
|
|
7252
|
+
this.auth0Client = auth0Client;
|
|
7253
|
+
this.contextManager = new MfaContextManager;
|
|
7254
|
+
}
|
|
7255
|
+
setMFAAuthDetails(mfaToken, scope, audience, mfaRequirements) {
|
|
7256
|
+
this.contextManager.set(mfaToken, {
|
|
7257
|
+
scope: scope,
|
|
7258
|
+
audience: audience,
|
|
7259
|
+
mfaRequirements: mfaRequirements
|
|
7260
|
+
});
|
|
7261
|
+
}
|
|
7262
|
+
async getAuthenticators(mfaToken) {
|
|
7263
|
+
var _a, _b;
|
|
7264
|
+
const context = this.contextManager.get(mfaToken);
|
|
7265
|
+
if (!((_a = context === null || context === void 0 ? void 0 : context.mfaRequirements) === null || _a === void 0 ? void 0 : _a.challenge) || context.mfaRequirements.challenge.length === 0) {
|
|
7266
|
+
throw new MfaListAuthenticatorsError("invalid_request", "challengeType is required and must contain at least one challenge type, please check mfa_required error payload");
|
|
7267
|
+
}
|
|
7268
|
+
const challengeTypes = context.mfaRequirements.challenge.map((c => c.type));
|
|
7269
|
+
try {
|
|
7270
|
+
const allAuthenticators = await this.authJsMfaClient.listAuthenticators({
|
|
7271
|
+
mfaToken: mfaToken
|
|
7272
|
+
});
|
|
7273
|
+
return allAuthenticators.filter((auth => {
|
|
7274
|
+
if (!auth.type) return false;
|
|
7275
|
+
return challengeTypes.includes(auth.type);
|
|
7276
|
+
}));
|
|
7277
|
+
} catch (error) {
|
|
7278
|
+
if (error instanceof MfaListAuthenticatorsError$1) {
|
|
7279
|
+
throw new MfaListAuthenticatorsError((_b = error.cause) === null || _b === void 0 ? void 0 : _b.error, error.message);
|
|
7280
|
+
}
|
|
7281
|
+
throw error;
|
|
7282
|
+
}
|
|
7283
|
+
}
|
|
7284
|
+
async enroll(params) {
|
|
7285
|
+
var _a;
|
|
7286
|
+
const authJsParams = getAuthJsEnrollParams(params);
|
|
7287
|
+
try {
|
|
7288
|
+
return await this.authJsMfaClient.enrollAuthenticator(authJsParams);
|
|
7289
|
+
} catch (error) {
|
|
7290
|
+
if (error instanceof MfaEnrollmentError$1) {
|
|
7291
|
+
throw new MfaEnrollmentError((_a = error.cause) === null || _a === void 0 ? void 0 : _a.error, error.message);
|
|
7292
|
+
}
|
|
7293
|
+
throw error;
|
|
7294
|
+
}
|
|
7295
|
+
}
|
|
7296
|
+
async challenge(params) {
|
|
7297
|
+
var _a;
|
|
7298
|
+
try {
|
|
7299
|
+
const authJsParams = {
|
|
7300
|
+
challengeType: params.challengeType,
|
|
7301
|
+
mfaToken: params.mfaToken
|
|
7302
|
+
};
|
|
7303
|
+
if (params.authenticatorId) {
|
|
7304
|
+
authJsParams.authenticatorId = params.authenticatorId;
|
|
7305
|
+
}
|
|
7306
|
+
return await this.authJsMfaClient.challengeAuthenticator(authJsParams);
|
|
7307
|
+
} catch (error) {
|
|
7308
|
+
if (error instanceof MfaChallengeError$1) {
|
|
7309
|
+
throw new MfaChallengeError((_a = error.cause) === null || _a === void 0 ? void 0 : _a.error, error.message);
|
|
7310
|
+
}
|
|
7311
|
+
throw error;
|
|
7312
|
+
}
|
|
7313
|
+
}
|
|
7314
|
+
async getEnrollmentFactors(mfaToken) {
|
|
7315
|
+
const context = this.contextManager.get(mfaToken);
|
|
7316
|
+
if (!context || !context.mfaRequirements) {
|
|
7317
|
+
throw new MfaEnrollmentFactorsError("mfa_context_not_found", "MFA context not found for this MFA token. Please retry the original request to get a new MFA token.");
|
|
7318
|
+
}
|
|
7319
|
+
if (!context.mfaRequirements.enroll || context.mfaRequirements.enroll.length === 0) {
|
|
7320
|
+
return [];
|
|
7321
|
+
}
|
|
7322
|
+
return context.mfaRequirements.enroll;
|
|
7323
|
+
}
|
|
7324
|
+
async verify(params) {
|
|
7325
|
+
const context = this.contextManager.get(params.mfaToken);
|
|
7326
|
+
if (!context) {
|
|
7327
|
+
throw new MfaVerifyError("mfa_context_not_found", "MFA context not found for this MFA token. Please retry the original request to get a new MFA token.");
|
|
7328
|
+
}
|
|
7329
|
+
const grantType = getGrantType(params);
|
|
7330
|
+
if (!grantType) {
|
|
7331
|
+
throw new MfaVerifyError("invalid_request", "Unable to determine grant type. Provide one of: otp, oobCode, or recoveryCode.");
|
|
7332
|
+
}
|
|
7333
|
+
const scope = context.scope;
|
|
7334
|
+
const audience = context.audience;
|
|
7335
|
+
try {
|
|
7336
|
+
const result = await this.auth0Client._requestTokenForMfa({
|
|
7337
|
+
grant_type: grantType,
|
|
7338
|
+
mfaToken: params.mfaToken,
|
|
7339
|
+
scope: scope,
|
|
7340
|
+
audience: audience,
|
|
7341
|
+
otp: params.otp,
|
|
7342
|
+
oob_code: params.oobCode,
|
|
7343
|
+
binding_code: params.bindingCode,
|
|
7344
|
+
recovery_code: params.recoveryCode
|
|
7345
|
+
});
|
|
7346
|
+
this.contextManager.remove(params.mfaToken);
|
|
7347
|
+
return result;
|
|
7348
|
+
} catch (error) {
|
|
7349
|
+
if (error instanceof MfaRequiredError) {
|
|
7350
|
+
this.setMFAAuthDetails(error.mfa_token, scope, audience, error.mfa_requirements);
|
|
7351
|
+
} else if (error instanceof MfaVerifyError) {
|
|
7352
|
+
throw new MfaVerifyError(error.error, error.error_description);
|
|
7353
|
+
}
|
|
7354
|
+
throw error;
|
|
7355
|
+
}
|
|
7356
|
+
}
|
|
7357
|
+
}
|
|
7112
7358
|
const lock = new _default;
|
|
7113
7359
|
class Auth0Client {
|
|
7114
7360
|
constructor(options) {
|
|
@@ -7177,6 +7423,7 @@
|
|
|
7177
7423
|
domain: this.options.domain,
|
|
7178
7424
|
clientId: this.options.clientId
|
|
7179
7425
|
});
|
|
7426
|
+
this.mfa = new MfaApiClient(this.authJsClient.mfa, this);
|
|
7180
7427
|
if (typeof window !== "undefined" && window.Worker && this.options.useRefreshTokens && cacheLocation === CACHE_LOCATION_MEMORY) {
|
|
7181
7428
|
if (this.options.workerUrl) {
|
|
7182
7429
|
this.worker = new Worker(this.options.workerUrl);
|
|
@@ -7192,7 +7439,9 @@
|
|
|
7192
7439
|
});
|
|
7193
7440
|
}
|
|
7194
7441
|
_url(path) {
|
|
7195
|
-
const
|
|
7442
|
+
const auth0ClientObj = this.options.auth0Client || DEFAULT_AUTH0_CLIENT;
|
|
7443
|
+
const strippedAuth0Client = stripAuth0Client(auth0ClientObj, true);
|
|
7444
|
+
const auth0Client = encodeURIComponent(btoa(JSON.stringify(strippedAuth0Client)));
|
|
7196
7445
|
return "".concat(this.domainUrl).concat(path, "&auth0Client=").concat(auth0Client);
|
|
7197
7446
|
}
|
|
7198
7447
|
_authorizeUrl(authorizeOptions) {
|
|
@@ -7573,6 +7822,7 @@
|
|
|
7573
7822
|
}
|
|
7574
7823
|
}
|
|
7575
7824
|
async _getTokenUsingRefreshToken(options) {
|
|
7825
|
+
var _a, _b;
|
|
7576
7826
|
const cache = await this.cacheManager.get(new CacheKey({
|
|
7577
7827
|
scope: options.authorizationParams.scope,
|
|
7578
7828
|
audience: options.authorizationParams.audience || DEFAULT_AUDIENCE,
|
|
@@ -7623,6 +7873,9 @@
|
|
|
7623
7873
|
if ((e.message.indexOf(MISSING_REFRESH_TOKEN_ERROR_MESSAGE) > -1 || e.message && e.message.indexOf(INVALID_REFRESH_TOKEN_ERROR_MESSAGE) > -1) && this.options.useRefreshTokensFallback) {
|
|
7624
7874
|
return await this._getTokenFromIFrame(options);
|
|
7625
7875
|
}
|
|
7876
|
+
if (e instanceof MfaRequiredError) {
|
|
7877
|
+
this.mfa.setMFAAuthDetails(e.mfa_token, (_a = options.authorizationParams) === null || _a === void 0 ? void 0 : _a.scope, (_b = options.authorizationParams) === null || _b === void 0 ? void 0 : _b.audience, e.mfa_requirements);
|
|
7878
|
+
}
|
|
7626
7879
|
throw e;
|
|
7627
7880
|
}
|
|
7628
7881
|
}
|
|
@@ -7792,6 +8045,12 @@
|
|
|
7792
8045
|
window.location.assign(url);
|
|
7793
8046
|
}
|
|
7794
8047
|
}
|
|
8048
|
+
async _requestTokenForMfa(options, additionalParameters) {
|
|
8049
|
+
const {mfaToken: mfaToken} = options, restOptions = __rest(options, [ "mfaToken" ]);
|
|
8050
|
+
return this._requestToken(Object.assign(Object.assign({}, restOptions), {
|
|
8051
|
+
mfa_token: mfaToken
|
|
8052
|
+
}), additionalParameters);
|
|
8053
|
+
}
|
|
7795
8054
|
}
|
|
7796
8055
|
async function createAuth0Client(options) {
|
|
7797
8056
|
const auth0 = new Auth0Client(options);
|
|
@@ -7805,7 +8064,14 @@
|
|
|
7805
8064
|
exports.GenericError = GenericError;
|
|
7806
8065
|
exports.InMemoryCache = InMemoryCache;
|
|
7807
8066
|
exports.LocalStorageCache = LocalStorageCache;
|
|
8067
|
+
exports.MfaApiClient = MfaApiClient;
|
|
8068
|
+
exports.MfaChallengeError = MfaChallengeError;
|
|
8069
|
+
exports.MfaEnrollmentError = MfaEnrollmentError;
|
|
8070
|
+
exports.MfaEnrollmentFactorsError = MfaEnrollmentFactorsError;
|
|
8071
|
+
exports.MfaError = MfaError;
|
|
8072
|
+
exports.MfaListAuthenticatorsError = MfaListAuthenticatorsError;
|
|
7808
8073
|
exports.MfaRequiredError = MfaRequiredError;
|
|
8074
|
+
exports.MfaVerifyError = MfaVerifyError;
|
|
7809
8075
|
exports.MissingRefreshTokenError = MissingRefreshTokenError;
|
|
7810
8076
|
exports.MyAccountApiError = MyAccountApiError;
|
|
7811
8077
|
exports.PopupCancelledError = PopupCancelledError;
|