@auth0/auth0-spa-js 2.2.0 → 2.3.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.
@@ -204,7 +204,7 @@ export declare class Auth0Client {
204
204
  * - `subject_token_type`: The type of the external token (validated by this function).
205
205
  * - `scope`: A unique set of scopes, generated by merging the scopes supplied in the options
206
206
  * with the SDK’s default scopes.
207
- * - `audience`: The target audience, as determined by the SDK's authorization configuration.
207
+ * - `audience`: The target audience from the options, with fallback to the SDK's authorization configuration.
208
208
  *
209
209
  * **Example Usage:**
210
210
  *
@@ -213,15 +213,15 @@ export declare class Auth0Client {
213
213
  * const options: CustomTokenExchangeOptions = {
214
214
  * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
215
215
  * subject_token_type: 'urn:acme:legacy-system-token',
216
- * scope: ['openid', 'profile']
216
+ * scope: "openid profile"
217
217
  * };
218
218
  *
219
219
  * // Exchange the external token for Auth0 tokens
220
220
  * try {
221
221
  * const tokenResponse = await instance.exchangeToken(options);
222
- * console.log('Token response:', tokenResponse);
222
+ * // Use tokenResponse.access_token, tokenResponse.id_token, etc.
223
223
  * } catch (error) {
224
- * console.error('Token exchange failed:', error);
224
+ * // Handle token exchange error
225
225
  * }
226
226
  * ```
227
227
  */
@@ -36,12 +36,13 @@ export type CustomTokenExchangeOptions = {
36
36
  * The target audience for the requested Auth0 token
37
37
  *
38
38
  * @remarks
39
- * Must match exactly with an API identifier configured in your Auth0 tenant
39
+ * Must match exactly with an API identifier configured in your Auth0 tenant.
40
+ * If not provided, falls back to the client's default audience.
40
41
  *
41
42
  * @example
42
43
  * "https://api.your-service.com/v1"
43
44
  */
44
- audience: string;
45
+ audience?: string;
45
46
  /**
46
47
  * Space-separated list of OAuth 2.0 scopes being requested
47
48
  *
@@ -72,6 +72,8 @@ export interface AuthorizationParams {
72
72
  *
73
73
  * - If you provide an Organization ID (a string with the prefix `org_`), it will be validated against the `org_id` claim of your user's ID Token. The validation is case-sensitive.
74
74
  * - If you provide an Organization Name (a string *without* the prefix `org_`), it will be validated against the `org_name` claim of your user's ID Token. The validation is case-insensitive.
75
+ * To use an Organization Name you must have "Allow Organization Names in Authentication API" switched on in your Auth0 settings dashboard.
76
+ * More information is available on the [Auth0 documentation portal](https://auth0.com/docs/manage-users/organizations/configure-organizations/use-org-name-authentication-api)
75
77
  *
76
78
  */
77
79
  organization?: string;
@@ -1,2 +1,2 @@
1
- declare const _default: "2.2.0";
1
+ declare const _default: "2.3.0";
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.2.0",
6
+ "version": "2.3.0",
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",
@@ -901,7 +901,15 @@ export class Auth0Client {
901
901
  const authorizeTimeout =
902
902
  options.timeoutInSeconds || this.options.authorizeTimeoutInSeconds;
903
903
 
904
- const codeResult = await runIframe(url, this.domainUrl, authorizeTimeout);
904
+ // Extract origin from domainUrl, fallback to domainUrl if URL parsing fails
905
+ let eventOrigin: string;
906
+ try {
907
+ eventOrigin = new URL(this.domainUrl).origin;
908
+ } catch {
909
+ eventOrigin = this.domainUrl;
910
+ }
911
+
912
+ const codeResult = await runIframe(url, eventOrigin, authorizeTimeout);
905
913
 
906
914
  if (stateIn !== codeResult.state) {
907
915
  throw new GenericError('state_mismatch', 'Invalid state');
@@ -1171,7 +1179,7 @@ export class Auth0Client {
1171
1179
  * - `subject_token_type`: The type of the external token (validated by this function).
1172
1180
  * - `scope`: A unique set of scopes, generated by merging the scopes supplied in the options
1173
1181
  * with the SDK’s default scopes.
1174
- * - `audience`: The target audience, as determined by the SDK's authorization configuration.
1182
+ * - `audience`: The target audience from the options, with fallback to the SDK's authorization configuration.
1175
1183
  *
1176
1184
  * **Example Usage:**
1177
1185
  *
@@ -1180,15 +1188,15 @@ export class Auth0Client {
1180
1188
  * const options: CustomTokenExchangeOptions = {
1181
1189
  * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
1182
1190
  * subject_token_type: 'urn:acme:legacy-system-token',
1183
- * scope: ['openid', 'profile']
1191
+ * scope: "openid profile"
1184
1192
  * };
1185
1193
  *
1186
1194
  * // Exchange the external token for Auth0 tokens
1187
1195
  * try {
1188
1196
  * const tokenResponse = await instance.exchangeToken(options);
1189
- * console.log('Token response:', tokenResponse);
1197
+ * // Use tokenResponse.access_token, tokenResponse.id_token, etc.
1190
1198
  * } catch (error) {
1191
- * console.error('Token exchange failed:', error);
1199
+ * // Handle token exchange error
1192
1200
  * }
1193
1201
  * ```
1194
1202
  */
@@ -1200,7 +1208,7 @@ export class Auth0Client {
1200
1208
  subject_token: options.subject_token,
1201
1209
  subject_token_type: options.subject_token_type,
1202
1210
  scope: getUniqueScopes(options.scope, this.scope),
1203
- audience: this.options.authorizationParams.audience
1211
+ audience: options.audience || this.options.authorizationParams.audience
1204
1212
  });
1205
1213
  }
1206
1214
  }
@@ -38,12 +38,13 @@ export type CustomTokenExchangeOptions = {
38
38
  * The target audience for the requested Auth0 token
39
39
  *
40
40
  * @remarks
41
- * Must match exactly with an API identifier configured in your Auth0 tenant
41
+ * Must match exactly with an API identifier configured in your Auth0 tenant.
42
+ * If not provided, falls back to the client's default audience.
42
43
  *
43
44
  * @example
44
45
  * "https://api.your-service.com/v1"
45
46
  */
46
- audience: string;
47
+ audience?: string;
47
48
 
48
49
  /**
49
50
  * Space-separated list of OAuth 2.0 scopes being requested
package/src/api.ts CHANGED
@@ -15,9 +15,18 @@ export async function oauthToken(
15
15
  }: TokenEndpointOptions,
16
16
  worker?: Worker
17
17
  ) {
18
+ const isTokenExchange =
19
+ options.grant_type === 'urn:ietf:params:oauth:grant-type:token-exchange';
20
+
21
+ const allParams = {
22
+ ...options,
23
+ ...(isTokenExchange && audience && { audience }),
24
+ ...(isTokenExchange && scope && { scope })
25
+ };
26
+
18
27
  const body = useFormData
19
- ? createQueryParams(options)
20
- : JSON.stringify(options);
28
+ ? createQueryParams(allParams)
29
+ : JSON.stringify(allParams);
21
30
 
22
31
  return await getJSON<TokenEndpointResponse>(
23
32
  `${baseUrl}/oauth/token`,
package/src/global.ts CHANGED
@@ -84,6 +84,8 @@ export interface AuthorizationParams {
84
84
  *
85
85
  * - If you provide an Organization ID (a string with the prefix `org_`), it will be validated against the `org_id` claim of your user's ID Token. The validation is case-sensitive.
86
86
  * - If you provide an Organization Name (a string *without* the prefix `org_`), it will be validated against the `org_name` claim of your user's ID Token. The validation is case-insensitive.
87
+ * To use an Organization Name you must have "Allow Organization Names in Authentication API" switched on in your Auth0 settings dashboard.
88
+ * More information is available on the [Auth0 documentation portal](https://auth0.com/docs/manage-users/organizations/configure-organizations/use-org-name-authentication-api)
87
89
  *
88
90
  */
89
91
  organization?: string;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '2.2.0';
1
+ export default '2.3.0';