@auth0/auth0-spa-js 2.0.7 → 2.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 +1 -1
- package/dist/auth0-spa-js.development.js +38 -29
- 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/lib/auth0-spa-js.cjs.js +38 -29
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +1 -1
- package/dist/typings/global.d.ts +9 -5
- package/dist/typings/transaction-manager.d.ts +1 -2
- package/dist/typings/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/Auth0Client.ts +21 -20
- package/src/global.ts +9 -5
- package/src/jwt.ts +25 -9
- package/src/transaction-manager.ts +8 -9
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ npm install @auth0/auth0-spa-js
|
|
|
29
29
|
From the CDN:
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
|
-
<script src="https://cdn.auth0.com/js/auth0-spa-js/2.
|
|
32
|
+
<script src="https://cdn.auth0.com/js/auth0-spa-js/2.1/auth0-spa-js.production.js"></script>
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
### Configure Auth0
|
|
@@ -472,7 +472,7 @@
|
|
|
472
472
|
exports.default = SuperTokensLock;
|
|
473
473
|
}));
|
|
474
474
|
var Lock = unwrapExports(browserTabsLock);
|
|
475
|
-
var version = "2.0
|
|
475
|
+
var version = "2.1.0";
|
|
476
476
|
const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
|
|
477
477
|
const DEFAULT_POPUP_CONFIG_OPTIONS = {
|
|
478
478
|
timeoutInSeconds: DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS
|
|
@@ -989,20 +989,17 @@
|
|
|
989
989
|
this.clientId = clientId;
|
|
990
990
|
this.cookieDomain = cookieDomain;
|
|
991
991
|
this.storageKey = `${TRANSACTION_STORAGE_KEY_PREFIX}.${this.clientId}`;
|
|
992
|
-
this.transaction = this.storage.get(this.storageKey);
|
|
993
992
|
}
|
|
994
993
|
create(transaction) {
|
|
995
|
-
this.transaction = transaction;
|
|
996
994
|
this.storage.save(this.storageKey, transaction, {
|
|
997
995
|
daysUntilExpire: 1,
|
|
998
996
|
cookieDomain: this.cookieDomain
|
|
999
997
|
});
|
|
1000
998
|
}
|
|
1001
999
|
get() {
|
|
1002
|
-
return this.
|
|
1000
|
+
return this.storage.get(this.storageKey);
|
|
1003
1001
|
}
|
|
1004
1002
|
remove() {
|
|
1005
|
-
delete this.transaction;
|
|
1006
1003
|
this.storage.remove(this.storageKey, {
|
|
1007
1004
|
cookieDomain: this.cookieDomain
|
|
1008
1005
|
});
|
|
@@ -1111,11 +1108,22 @@
|
|
|
1111
1108
|
throw new Error(`Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (${now}) is after last auth at ${authTimeDate}`);
|
|
1112
1109
|
}
|
|
1113
1110
|
}
|
|
1114
|
-
if (options.
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1111
|
+
if (options.organization) {
|
|
1112
|
+
const org = options.organization.trim();
|
|
1113
|
+
if (org.startsWith("org_")) {
|
|
1114
|
+
const orgId = org;
|
|
1115
|
+
if (!decoded.claims.org_id) {
|
|
1116
|
+
throw new Error("Organization ID (org_id) claim must be a string present in the ID token");
|
|
1117
|
+
} else if (orgId !== decoded.claims.org_id) {
|
|
1118
|
+
throw new Error(`Organization ID (org_id) claim mismatch in the ID token; expected "${orgId}", found "${decoded.claims.org_id}"`);
|
|
1119
|
+
}
|
|
1120
|
+
} else {
|
|
1121
|
+
const orgName = org.toLowerCase();
|
|
1122
|
+
if (!decoded.claims.org_name) {
|
|
1123
|
+
throw new Error("Organization Name (org_name) claim must be a string present in the ID token");
|
|
1124
|
+
} else if (orgName !== decoded.claims.org_name.toLowerCase()) {
|
|
1125
|
+
throw new Error(`Organization Name (org_name) claim mismatch in the ID token; expected "${orgName}", found "${decoded.claims.org_name.toLowerCase()}"`);
|
|
1126
|
+
}
|
|
1119
1127
|
}
|
|
1120
1128
|
}
|
|
1121
1129
|
return decoded;
|
|
@@ -1456,22 +1464,22 @@
|
|
|
1456
1464
|
_authorizeUrl(authorizeOptions) {
|
|
1457
1465
|
return this._url(`/authorize?${createQueryParams(authorizeOptions)}`);
|
|
1458
1466
|
}
|
|
1459
|
-
async _verifyIdToken(id_token, nonce,
|
|
1467
|
+
async _verifyIdToken(id_token, nonce, organization) {
|
|
1460
1468
|
const now = await this.nowProvider();
|
|
1461
1469
|
return verify({
|
|
1462
1470
|
iss: this.tokenIssuer,
|
|
1463
1471
|
aud: this.options.clientId,
|
|
1464
1472
|
id_token: id_token,
|
|
1465
1473
|
nonce: nonce,
|
|
1466
|
-
|
|
1474
|
+
organization: organization,
|
|
1467
1475
|
leeway: this.options.leeway,
|
|
1468
1476
|
max_age: parseNumber(this.options.authorizationParams.max_age),
|
|
1469
1477
|
now: now
|
|
1470
1478
|
});
|
|
1471
1479
|
}
|
|
1472
|
-
|
|
1473
|
-
if (
|
|
1474
|
-
this.cookieStorage.save(this.orgHintCookieName,
|
|
1480
|
+
_processOrgHint(organization) {
|
|
1481
|
+
if (organization) {
|
|
1482
|
+
this.cookieStorage.save(this.orgHintCookieName, organization, {
|
|
1475
1483
|
daysUntilExpire: this.sessionCheckExpiryDays,
|
|
1476
1484
|
cookieDomain: this.options.cookieDomain
|
|
1477
1485
|
});
|
|
@@ -1519,7 +1527,7 @@
|
|
|
1519
1527
|
if (params.state !== codeResult.state) {
|
|
1520
1528
|
throw new GenericError("state_mismatch", "Invalid state");
|
|
1521
1529
|
}
|
|
1522
|
-
const
|
|
1530
|
+
const organization = ((_a = options.authorizationParams) === null || _a === void 0 ? void 0 : _a.organization) || this.options.authorizationParams.organization;
|
|
1523
1531
|
await this._requestToken({
|
|
1524
1532
|
audience: params.audience,
|
|
1525
1533
|
scope: params.scope,
|
|
@@ -1529,7 +1537,7 @@
|
|
|
1529
1537
|
redirect_uri: params.redirect_uri
|
|
1530
1538
|
}, {
|
|
1531
1539
|
nonceIn: params.nonce,
|
|
1532
|
-
|
|
1540
|
+
organization: organization
|
|
1533
1541
|
});
|
|
1534
1542
|
}
|
|
1535
1543
|
async getUser() {
|
|
@@ -1545,12 +1553,12 @@
|
|
|
1545
1553
|
async loginWithRedirect(options = {}) {
|
|
1546
1554
|
var _a;
|
|
1547
1555
|
const _b = patchOpenUrlWithOnRedirect(options), {openUrl: openUrl, fragment: fragment, appState: appState} = _b, urlOptions = __rest(_b, [ "openUrl", "fragment", "appState" ]);
|
|
1548
|
-
const
|
|
1556
|
+
const organization = ((_a = urlOptions.authorizationParams) === null || _a === void 0 ? void 0 : _a.organization) || this.options.authorizationParams.organization;
|
|
1549
1557
|
const _c = await this._prepareAuthorizeUrl(urlOptions.authorizationParams || {}), {url: url} = _c, transaction = __rest(_c, [ "url" ]);
|
|
1550
1558
|
this.transactionManager.create(Object.assign(Object.assign(Object.assign({}, transaction), {
|
|
1551
1559
|
appState: appState
|
|
1552
|
-
}),
|
|
1553
|
-
|
|
1560
|
+
}), organization && {
|
|
1561
|
+
organization: organization
|
|
1554
1562
|
}));
|
|
1555
1563
|
const urlWithFragment = fragment ? `${url}#${fragment}` : url;
|
|
1556
1564
|
if (openUrl) {
|
|
@@ -1576,7 +1584,7 @@
|
|
|
1576
1584
|
if (!transaction.code_verifier || transaction.state && transaction.state !== state) {
|
|
1577
1585
|
throw new GenericError("state_mismatch", "Invalid state");
|
|
1578
1586
|
}
|
|
1579
|
-
const
|
|
1587
|
+
const organization = transaction.organization;
|
|
1580
1588
|
const nonceIn = transaction.nonce;
|
|
1581
1589
|
const redirect_uri = transaction.redirect_uri;
|
|
1582
1590
|
await this._requestToken(Object.assign({
|
|
@@ -1589,7 +1597,7 @@
|
|
|
1589
1597
|
redirect_uri: redirect_uri
|
|
1590
1598
|
} : {}), {
|
|
1591
1599
|
nonceIn: nonceIn,
|
|
1592
|
-
|
|
1600
|
+
organization: organization
|
|
1593
1601
|
});
|
|
1594
1602
|
return {
|
|
1595
1603
|
appState: transaction.appState
|
|
@@ -1727,9 +1735,9 @@
|
|
|
1727
1735
|
const params = Object.assign(Object.assign({}, options.authorizationParams), {
|
|
1728
1736
|
prompt: "none"
|
|
1729
1737
|
});
|
|
1730
|
-
const
|
|
1731
|
-
if (
|
|
1732
|
-
params.organization =
|
|
1738
|
+
const orgHint = this.cookieStorage.get(this.orgHintCookieName);
|
|
1739
|
+
if (orgHint && !params.organization) {
|
|
1740
|
+
params.organization = orgHint;
|
|
1733
1741
|
}
|
|
1734
1742
|
const {url: url, state: stateIn, nonce: nonceIn, code_verifier: code_verifier, redirect_uri: redirect_uri, scope: scope, audience: audience} = await this._prepareAuthorizeUrl(params, {
|
|
1735
1743
|
response_mode: "web_message"
|
|
@@ -1750,7 +1758,8 @@
|
|
|
1750
1758
|
redirect_uri: redirect_uri,
|
|
1751
1759
|
timeout: options.authorizationParams.timeout || this.httpTimeoutMs
|
|
1752
1760
|
}), {
|
|
1753
|
-
nonceIn: nonceIn
|
|
1761
|
+
nonceIn: nonceIn,
|
|
1762
|
+
organization: params.organization
|
|
1754
1763
|
});
|
|
1755
1764
|
return Object.assign(Object.assign({}, tokenResult), {
|
|
1756
1765
|
scope: scope,
|
|
@@ -1843,7 +1852,7 @@
|
|
|
1843
1852
|
}
|
|
1844
1853
|
}
|
|
1845
1854
|
async _requestToken(options, additionalParameters) {
|
|
1846
|
-
const {nonceIn: nonceIn,
|
|
1855
|
+
const {nonceIn: nonceIn, organization: organization} = additionalParameters || {};
|
|
1847
1856
|
const authResult = await oauthToken(Object.assign({
|
|
1848
1857
|
baseUrl: this.domainUrl,
|
|
1849
1858
|
client_id: this.options.clientId,
|
|
@@ -1851,7 +1860,7 @@
|
|
|
1851
1860
|
useFormData: this.options.useFormData,
|
|
1852
1861
|
timeout: this.httpTimeoutMs
|
|
1853
1862
|
}, options), this.worker);
|
|
1854
|
-
const decodedToken = await this._verifyIdToken(authResult.id_token, nonceIn,
|
|
1863
|
+
const decodedToken = await this._verifyIdToken(authResult.id_token, nonceIn, organization);
|
|
1855
1864
|
await this._saveEntryInCache(Object.assign(Object.assign(Object.assign(Object.assign({}, authResult), {
|
|
1856
1865
|
decodedToken: decodedToken,
|
|
1857
1866
|
scope: options.scope,
|
|
@@ -1865,7 +1874,7 @@
|
|
|
1865
1874
|
daysUntilExpire: this.sessionCheckExpiryDays,
|
|
1866
1875
|
cookieDomain: this.options.cookieDomain
|
|
1867
1876
|
});
|
|
1868
|
-
this.
|
|
1877
|
+
this._processOrgHint(organization);
|
|
1869
1878
|
return Object.assign(Object.assign({}, authResult), {
|
|
1870
1879
|
decodedToken: decodedToken
|
|
1871
1880
|
});
|