@auth0/auth0-spa-js 2.10.0 → 2.11.1

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.
@@ -233,6 +233,8 @@ export declare class Auth0Client {
233
233
  * - `scope`: A unique set of scopes, generated by merging the scopes supplied in the options
234
234
  * with the SDK’s default scopes.
235
235
  * - `audience`: The target audience from the options, with fallback to the SDK's authorization configuration.
236
+ * - `organization`: Optional organization ID or name for authenticating the user in an organization context.
237
+ * When provided, the organization ID will be present in the access token payload.
236
238
  *
237
239
  * **Example Usage:**
238
240
  *
@@ -241,13 +243,15 @@ export declare class Auth0Client {
241
243
  * const options: CustomTokenExchangeOptions = {
242
244
  * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
243
245
  * subject_token_type: 'urn:acme:legacy-system-token',
244
- * scope: "openid profile"
246
+ * scope: "openid profile",
247
+ * organization: "org_12345"
245
248
  * };
246
249
  *
247
250
  * // Exchange the external token for Auth0 tokens
248
251
  * try {
249
252
  * const tokenResponse = await instance.exchangeToken(options);
250
253
  * // Use tokenResponse.access_token, tokenResponse.id_token, etc.
254
+ * // The organization ID will be present in the access token payload
251
255
  * } catch (error) {
252
256
  * // Handle token exchange error
253
257
  * }
@@ -53,6 +53,12 @@ export type CustomTokenExchangeOptions = {
53
53
  * "openid profile email read:data write:data"
54
54
  */
55
55
  scope?: string;
56
+ /**
57
+ * ID or name of the organization to use when authenticating a user.
58
+ * When provided, the user will be authenticated using the organization context.
59
+ * The organization ID will be present in the access token payload.
60
+ */
61
+ organization?: string;
56
62
  /**
57
63
  * Additional custom parameters for Auth0 Action processing
58
64
  *
@@ -140,9 +140,12 @@ export interface Auth0ClientOptions {
140
140
  */
141
141
  cache?: ICache;
142
142
  /**
143
- * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the legacy technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
143
+ * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the standard technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
144
144
  * The default setting is `false`.
145
145
  *
146
+ * Standard technique relies on cookies. Because browsers increasingly block third-party cookies, it requires a Custom Domain to function reliably. Refresh tokens serve as a fallback for environments where third-party cookies are blocked.
147
+ * Using a Custom Domain with this set to `false` is the most secure and recommended approach.
148
+ *
146
149
  * **Note**: Use of refresh tokens must be enabled by an administrator on your Auth0 client application.
147
150
  */
148
151
  useRefreshTokens?: boolean;
@@ -1,2 +1,2 @@
1
- declare const _default: "2.10.0";
1
+ declare const _default: "2.11.1";
2
2
  export default _default;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "@auth0/auth0-spa-js",
4
4
  "description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
5
5
  "license": "MIT",
6
- "version": "2.10.0",
6
+ "version": "2.11.1",
7
7
  "main": "dist/lib/auth0-spa-js.cjs.js",
8
8
  "types": "dist/typings/index.d.ts",
9
9
  "module": "dist/auth0-spa-js.production.esm.js",
@@ -59,7 +59,7 @@
59
59
  "@types/jest": "^28.1.7",
60
60
  "@typescript-eslint/eslint-plugin-tslint": "^5.33.1",
61
61
  "@typescript-eslint/parser": "^5.33.1",
62
- "browserstack-cypress-cli": "1.32.8",
62
+ "browserstack-cypress-cli": "1.36.0",
63
63
  "cli-table": "^0.3.6",
64
64
  "concurrently": "^7.3.0",
65
65
  "cypress": "13.17.0",
@@ -76,7 +76,7 @@
76
76
  "jest-junit": "^14.0.0",
77
77
  "jest-localstorage-mock": "^2.4.22",
78
78
  "jsonwebtoken": "^9.0.0",
79
- "oidc-provider": "^7.14.0",
79
+ "oidc-provider": "^9.6.0",
80
80
  "prettier": "^2.7.1",
81
81
  "pretty-quick": "^3.1.2",
82
82
  "rimraf": "^3.0.2",
@@ -1373,6 +1373,19 @@ export class Auth0Client {
1373
1373
  organization
1374
1374
  );
1375
1375
 
1376
+ // When logging in with authorization_code, check if a different user is authenticating
1377
+ // If so, clear the cache to prevent tokens from multiple users coexisting
1378
+ if (options.grant_type === 'authorization_code') {
1379
+ const existingIdToken = await this._getIdTokenFromCache();
1380
+
1381
+ if (existingIdToken?.decodedToken?.claims?.sub &&
1382
+ existingIdToken.decodedToken.claims.sub !== decodedToken.claims.sub) {
1383
+ // Different user detected - clear cached tokens
1384
+ await this.cacheManager.clear(this.options.clientId);
1385
+ this.userCache.remove(CACHE_KEY_ID_TOKEN_SUFFIX);
1386
+ }
1387
+ }
1388
+
1376
1389
  await this._saveEntryInCache({
1377
1390
  ...authResult,
1378
1391
  decodedToken,
@@ -1422,6 +1435,8 @@ export class Auth0Client {
1422
1435
  * - `scope`: A unique set of scopes, generated by merging the scopes supplied in the options
1423
1436
  * with the SDK’s default scopes.
1424
1437
  * - `audience`: The target audience from the options, with fallback to the SDK's authorization configuration.
1438
+ * - `organization`: Optional organization ID or name for authenticating the user in an organization context.
1439
+ * When provided, the organization ID will be present in the access token payload.
1425
1440
  *
1426
1441
  * **Example Usage:**
1427
1442
  *
@@ -1430,13 +1445,15 @@ export class Auth0Client {
1430
1445
  * const options: CustomTokenExchangeOptions = {
1431
1446
  * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
1432
1447
  * subject_token_type: 'urn:acme:legacy-system-token',
1433
- * scope: "openid profile"
1448
+ * scope: "openid profile",
1449
+ * organization: "org_12345"
1434
1450
  * };
1435
1451
  *
1436
1452
  * // Exchange the external token for Auth0 tokens
1437
1453
  * try {
1438
1454
  * const tokenResponse = await instance.exchangeToken(options);
1439
1455
  * // Use tokenResponse.access_token, tokenResponse.id_token, etc.
1456
+ * // The organization ID will be present in the access token payload
1440
1457
  * } catch (error) {
1441
1458
  * // Handle token exchange error
1442
1459
  * }
@@ -1454,7 +1471,8 @@ export class Auth0Client {
1454
1471
  options.scope,
1455
1472
  options.audience || this.options.authorizationParams.audience
1456
1473
  ),
1457
- audience: options.audience || this.options.authorizationParams.audience
1474
+ audience: options.audience || this.options.authorizationParams.audience,
1475
+ organization: options.organization || this.options.authorizationParams.organization
1458
1476
  });
1459
1477
  }
1460
1478
 
@@ -1638,6 +1656,7 @@ interface TokenExchangeRequestOptions extends BaseRequestTokenOptions {
1638
1656
  subject_token_type: string;
1639
1657
  actor_token?: string;
1640
1658
  actor_token_type?: string;
1659
+ organization?: string;
1641
1660
  }
1642
1661
 
1643
1662
  interface RequestTokenAdditionalParameters {
@@ -57,6 +57,13 @@ export type CustomTokenExchangeOptions = {
57
57
  */
58
58
  scope?: string;
59
59
 
60
+ /**
61
+ * ID or name of the organization to use when authenticating a user.
62
+ * When provided, the user will be authenticated using the organization context.
63
+ * The organization ID will be present in the access token payload.
64
+ */
65
+ organization?: string;
66
+
60
67
  /**
61
68
  * Additional custom parameters for Auth0 Action processing
62
69
  *
package/src/global.ts CHANGED
@@ -161,9 +161,12 @@ export interface Auth0ClientOptions {
161
161
  cache?: ICache;
162
162
 
163
163
  /**
164
- * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the legacy technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
164
+ * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the standard technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
165
165
  * The default setting is `false`.
166
166
  *
167
+ * Standard technique relies on cookies. Because browsers increasingly block third-party cookies, it requires a Custom Domain to function reliably. Refresh tokens serve as a fallback for environments where third-party cookies are blocked.
168
+ * Using a Custom Domain with this set to `false` is the most secure and recommended approach.
169
+ *
167
170
  * **Note**: Use of refresh tokens must be enabled by an administrator on your Auth0 client application.
168
171
  */
169
172
  useRefreshTokens?: boolean;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '2.10.0';
1
+ export default '2.11.1';