@auth0/auth0-react 2.12.0 → 2.14.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/dist/index.d.ts CHANGED
@@ -3,6 +3,6 @@ export { default as useAuth0 } from './use-auth0';
3
3
  export { default as withAuth0, WithAuth0Props } from './with-auth0';
4
4
  export { default as withAuthenticationRequired, WithAuthenticationRequiredOptions, } from './with-authentication-required';
5
5
  export { default as Auth0Context, Auth0ContextInterface, initialContext, LogoutOptions, RedirectLoginOptions, } from './auth0-context';
6
- export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, TimeoutError, MfaRequiredError, PopupCancelledError, PopupTimeoutError, AuthenticationError, MissingRefreshTokenError, GenericError, UseDpopNonceError, type FetcherConfig, RedirectConnectAccountOptions, ConnectAccountRedirectResult, ResponseType, ConnectError, CustomTokenExchangeOptions, TokenEndpointResponse, ClientConfiguration, } from '@auth0/auth0-spa-js';
6
+ export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, TimeoutError, MfaRequiredError, PopupCancelledError, PopupTimeoutError, AuthenticationError, MissingRefreshTokenError, GenericError, UseDpopNonceError, type FetcherConfig, RedirectConnectAccountOptions, ConnectAccountRedirectResult, ResponseType, ConnectError, CustomTokenExchangeOptions, TokenEndpointResponse, ClientConfiguration, type MfaApiClient, type Authenticator, type MfaFactorType, type EnrollParams, type EnrollOtpParams, type EnrollSmsParams, type EnrollVoiceParams, type EnrollEmailParams, type EnrollPushParams, type EnrollmentResponse, type ChallengeAuthenticatorParams, type ChallengeResponse, type VerifyParams, type EnrollmentFactor, MfaError, MfaListAuthenticatorsError, MfaEnrollmentError, MfaChallengeError, MfaVerifyError, MfaEnrollmentFactorsError, } from '@auth0/auth0-spa-js';
7
7
  export { OAuthError } from './errors';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,oBAAoB,EACpB,QAAQ,EACR,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,OAAO,IAAI,0BAA0B,EACrC,iCAAiC,GAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,OAAO,EACP,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACZ,iBAAiB,EACjB,KAAK,aAAa,EAClB,6BAA6B,EAC7B,4BAA4B,EAC5B,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,oBAAoB,EACpB,QAAQ,EACR,gB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'./auth0-context';
12
12
  * getAccessTokenSilently,
13
13
  * getAccessTokenWithPopup,
14
14
  * getIdTokenClaims,
15
- * exchangeToken,
15
+ * loginWithCustomTokenExchange,
16
+ * exchangeToken, // deprecated - use loginWithCustomTokenExchange
16
17
  * loginWithRedirect,
17
18
  * loginWithPopup,
18
19
  * logout,
@@ -1 +1 @@
1
- {"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,QAAA,MAAM,QAAQ,GAAI,KAAK,SAAS,IAAI,GAAG,IAAI,EACzC,8DAAsB,KACrB,qBAAqB,CAAC,KAAK,CACuB,CAAC;AAEtD,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,QAAQ,GAAI,KAAK,SAAS,IAAI,GAAG,IAAI,EACzC,8DAAsB,KACrB,qBAAqB,CAAC,KAAK,CACuB,CAAC;AAEtD,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@auth0/auth0-react",
4
- "version": "2.12.0",
4
+ "version": "2.14.0",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -58,7 +58,7 @@
58
58
  "@testing-library/jest-dom": "6.9.1",
59
59
  "@testing-library/react": "16.3.2",
60
60
  "@types/jest": "^29.5.14",
61
- "@types/react": "19.2.10",
61
+ "@types/react": "19.2.14",
62
62
  "@types/react-dom": "19.2.3",
63
63
  "@typescript-eslint/eslint-plugin": "^8.36.0",
64
64
  "@typescript-eslint/parser": "^8.36.0",
@@ -95,6 +95,6 @@
95
95
  "react-dom": "^16.11.0 || ^17 || ^18 || ~19.0.1 || ~19.1.2 || ^19.2.1"
96
96
  },
97
97
  "dependencies": {
98
- "@auth0/auth0-spa-js": "^2.12.0"
98
+ "@auth0/auth0-spa-js": "^2.15.0"
99
99
  }
100
100
  }
@@ -13,7 +13,8 @@ import {
13
13
  RedirectConnectAccountOptions,
14
14
  ConnectAccountRedirectResult,
15
15
  CustomTokenExchangeOptions,
16
- TokenEndpointResponse
16
+ TokenEndpointResponse,
17
+ type MfaApiClient
17
18
  } from '@auth0/auth0-spa-js';
18
19
  import { createContext } from 'react';
19
20
  import { AuthState, initialAuthState } from './auth-state';
@@ -93,6 +94,60 @@ export interface Auth0ContextInterface<TUser extends User = User>
93
94
  getIdTokenClaims: () => Promise<IdToken | undefined>;
94
95
 
95
96
  /**
97
+ * ```js
98
+ * await loginWithCustomTokenExchange(options);
99
+ * ```
100
+ *
101
+ * Exchanges an external subject token for Auth0 tokens and logs the user in.
102
+ * This method implements the Custom Token Exchange grant as specified in RFC 8693.
103
+ *
104
+ * The exchanged tokens are automatically cached, establishing an authenticated session.
105
+ * After calling this method, you can use `getUser()`, `getIdTokenClaims()`, and
106
+ * `getTokenSilently()` to access the user's information and tokens.
107
+ *
108
+ * @param options - The options required to perform the token exchange.
109
+ *
110
+ * @returns A promise that resolves to the token endpoint response,
111
+ * which contains the issued Auth0 tokens (access_token, id_token, etc.).
112
+ *
113
+ * The request includes the following parameters:
114
+ * - `grant_type`: "urn:ietf:params:oauth:grant-type:token-exchange"
115
+ * - `subject_token`: The external token to exchange
116
+ * - `subject_token_type`: The type identifier of the external token
117
+ * - `scope`: Merged scopes from the request and SDK defaults
118
+ * - `audience`: Target audience (defaults to SDK configuration)
119
+ * - `organization`: Optional organization ID/name for org-scoped authentication
120
+ *
121
+ * **Example Usage:**
122
+ *
123
+ * ```js
124
+ * const options = {
125
+ * subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
126
+ * subject_token_type: 'urn:acme:legacy-system-token',
127
+ * scope: 'openid profile email',
128
+ * audience: 'https://api.example.com',
129
+ * organization: 'org_12345'
130
+ * };
131
+ *
132
+ * try {
133
+ * const tokenResponse = await loginWithCustomTokenExchange(options);
134
+ * console.log('Access token:', tokenResponse.access_token);
135
+ *
136
+ * // User is now logged in - access user info
137
+ * const user = await getUser();
138
+ * console.log('Logged in user:', user);
139
+ * } catch (error) {
140
+ * console.error('Token exchange failed:', error);
141
+ * }
142
+ * ```
143
+ */
144
+ loginWithCustomTokenExchange: (
145
+ options: CustomTokenExchangeOptions
146
+ ) => Promise<TokenEndpointResponse>;
147
+
148
+ /**
149
+ * @deprecated Use `loginWithCustomTokenExchange()` instead. This method will be removed in the next major version.
150
+ *
96
151
  * ```js
97
152
  * const tokenResponse = await exchangeToken({
98
153
  * subject_token: 'external_token_value',
@@ -101,18 +156,20 @@ export interface Auth0ContextInterface<TUser extends User = User>
101
156
  * });
102
157
  * ```
103
158
  *
104
- * Exchanges an external subject token for Auth0 tokens via a token exchange request.
159
+ * Exchanges an external subject token for Auth0 tokens and logs the user in.
105
160
  *
106
161
  * This method implements the token exchange grant as specified in RFC 8693.
107
162
  * It performs a token exchange by sending a request to the `/oauth/token` endpoint
108
163
  * with the external token and returns Auth0 tokens (access token, ID token, etc.).
109
164
  *
110
- * The request includes the following parameters:
111
- * - `grant_type`: Hard-coded to "urn:ietf:params:oauth:grant-type:token-exchange"
112
- * - `subject_token`: The external token to be exchanged
113
- * - `subject_token_type`: A namespaced URI identifying the token type (must be under your organization's control)
114
- * - `audience`: The target audience (falls back to the SDK's default audience if not provided)
115
- * - `scope`: Space-separated list of scopes (merged with the SDK's default scopes)
165
+ * **Example:**
166
+ * ```js
167
+ * // Instead of:
168
+ * const tokens = await exchangeToken(options);
169
+ *
170
+ * // Use:
171
+ * const tokens = await loginWithCustomTokenExchange(options);
172
+ * ```
116
173
  *
117
174
  * @param options - The options required to perform the token exchange
118
175
  * @returns A promise that resolves to the token endpoint response containing Auth0 tokens
@@ -252,6 +309,60 @@ export interface Auth0ContextInterface<TUser extends User = User>
252
309
  * containing the domain and clientId.
253
310
  */
254
311
  getConfiguration: Auth0Client['getConfiguration'];
312
+
313
+ /**
314
+ * ```js
315
+ * const { mfa } = useAuth0();
316
+ * const authenticators = await mfa.getAuthenticators(mfaToken);
317
+ * ```
318
+ *
319
+ * MFA API client for Multi-Factor Authentication operations.
320
+ *
321
+ * Provides access to all MFA-related methods:
322
+ * - `getAuthenticators(mfaToken)` - List enrolled authenticators
323
+ * - `enroll(params)` - Enroll new authenticators (OTP, SMS, Voice, Email, Push)
324
+ * - `challenge(params)` - Initiate MFA challenges
325
+ * - `verify(params)` - Verify MFA challenges and complete authentication
326
+ * - `getEnrollmentFactors(mfaToken)` - Get available enrollment factors
327
+ *
328
+ * @example
329
+ * ```js
330
+ * const { mfa, getAccessTokenSilently } = useAuth0();
331
+ *
332
+ * try {
333
+ * await getAccessTokenSilently();
334
+ * } catch (error) {
335
+ * if (error.error === 'mfa_required') {
336
+ * // Check if enrollment is needed
337
+ * const factors = await mfa.getEnrollmentFactors(error.mfa_token);
338
+ *
339
+ * if (factors.length > 0) {
340
+ * // Enroll in OTP
341
+ * const enrollment = await mfa.enroll({
342
+ * mfaToken: error.mfa_token,
343
+ * factorType: 'otp'
344
+ * });
345
+ * console.log('QR Code:', enrollment.barcodeUri);
346
+ * }
347
+ *
348
+ * // Get authenticators and challenge
349
+ * const authenticators = await mfa.getAuthenticators(error.mfa_token);
350
+ * await mfa.challenge({
351
+ * mfaToken: error.mfa_token,
352
+ * challengeType: 'otp',
353
+ * authenticatorId: authenticators[0].id
354
+ * });
355
+ *
356
+ * // Verify with user's code
357
+ * const tokens = await mfa.verify({
358
+ * mfaToken: error.mfa_token,
359
+ * otp: userCode
360
+ * });
361
+ * }
362
+ * }
363
+ * ```
364
+ */
365
+ mfa: MfaApiClient;
255
366
  }
256
367
 
257
368
  /**
@@ -271,6 +382,7 @@ export const initialContext = {
271
382
  getAccessTokenSilently: stub,
272
383
  getAccessTokenWithPopup: stub,
273
384
  getIdTokenClaims: stub,
385
+ loginWithCustomTokenExchange: stub,
274
386
  exchangeToken: stub,
275
387
  loginWithRedirect: stub,
276
388
  loginWithPopup: stub,
@@ -282,6 +394,13 @@ export const initialContext = {
282
394
  generateDpopProof: stub,
283
395
  createFetcher: stub,
284
396
  getConfiguration: stub,
397
+ mfa: {
398
+ getAuthenticators: stub,
399
+ enroll: stub,
400
+ challenge: stub,
401
+ verify: stub,
402
+ getEnrollmentFactors: stub,
403
+ } as unknown as MfaApiClient,
285
404
  };
286
405
 
287
406
  /**
@@ -279,19 +279,19 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
279
279
  [client]
280
280
  );
281
281
 
282
- const exchangeToken = useCallback(
282
+ const loginWithCustomTokenExchange = useCallback(
283
283
  async (
284
284
  options: CustomTokenExchangeOptions
285
285
  ): Promise<TokenEndpointResponse> => {
286
286
  let tokenResponse;
287
287
  try {
288
- tokenResponse = await client.exchangeToken(options);
288
+ tokenResponse = await client.loginWithCustomTokenExchange(options);
289
289
  } catch (error) {
290
290
  throw tokenError(error);
291
291
  } finally {
292
- // We dispatch the standard GET_ACCESS_TOKEN_COMPLETE action here to maintain
293
- // backward compatibility and consistency with the getAccessTokenSilently flow.
294
- // This ensures the SDK's internal state lifecycle (loading/user updates) remains
292
+ // We dispatch the standard GET_ACCESS_TOKEN_COMPLETE action here to maintain
293
+ // backward compatibility and consistency with the getAccessTokenSilently flow.
294
+ // This ensures the SDK's internal state lifecycle (loading/user updates) remains
295
295
  // identical regardless of whether the token was retrieved via silent auth or CTE.
296
296
  dispatch({
297
297
  type: 'GET_ACCESS_TOKEN_COMPLETE',
@@ -303,6 +303,15 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
303
303
  [client]
304
304
  );
305
305
 
306
+ const exchangeToken = useCallback(
307
+ async (
308
+ options: CustomTokenExchangeOptions
309
+ ): Promise<TokenEndpointResponse> => {
310
+ return loginWithCustomTokenExchange(options);
311
+ },
312
+ [loginWithCustomTokenExchange]
313
+ );
314
+
306
315
  const handleRedirectCallback = useCallback(
307
316
  async (
308
317
  url?: string
@@ -346,12 +355,15 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
346
355
  [client]
347
356
  );
348
357
 
358
+ const mfa = useMemo(() => client.mfa, [client]);
359
+
349
360
  const contextValue = useMemo<Auth0ContextInterface<TUser>>(() => {
350
361
  return {
351
362
  ...state,
352
363
  getAccessTokenSilently,
353
364
  getAccessTokenWithPopup,
354
365
  getIdTokenClaims,
366
+ loginWithCustomTokenExchange,
355
367
  exchangeToken,
356
368
  loginWithRedirect,
357
369
  loginWithPopup,
@@ -363,12 +375,14 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
363
375
  generateDpopProof,
364
376
  createFetcher,
365
377
  getConfiguration,
378
+ mfa,
366
379
  };
367
380
  }, [
368
381
  state,
369
382
  getAccessTokenSilently,
370
383
  getAccessTokenWithPopup,
371
384
  getIdTokenClaims,
385
+ loginWithCustomTokenExchange,
372
386
  exchangeToken,
373
387
  loginWithRedirect,
374
388
  loginWithPopup,
@@ -380,6 +394,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
380
394
  generateDpopProof,
381
395
  createFetcher,
382
396
  getConfiguration,
397
+ mfa,
383
398
  ]);
384
399
 
385
400
  return <context.Provider value={contextValue}>{children}</context.Provider>;
package/src/index.tsx CHANGED
@@ -47,5 +47,27 @@ export {
47
47
  CustomTokenExchangeOptions,
48
48
  TokenEndpointResponse,
49
49
  ClientConfiguration,
50
+ // MFA Types
51
+ type MfaApiClient,
52
+ type Authenticator,
53
+ type MfaFactorType,
54
+ type EnrollParams,
55
+ type EnrollOtpParams,
56
+ type EnrollSmsParams,
57
+ type EnrollVoiceParams,
58
+ type EnrollEmailParams,
59
+ type EnrollPushParams,
60
+ type EnrollmentResponse,
61
+ type ChallengeAuthenticatorParams,
62
+ type ChallengeResponse,
63
+ type VerifyParams,
64
+ type EnrollmentFactor,
65
+ // MFA Errors
66
+ MfaError,
67
+ MfaListAuthenticatorsError,
68
+ MfaEnrollmentError,
69
+ MfaChallengeError,
70
+ MfaVerifyError,
71
+ MfaEnrollmentFactorsError,
50
72
  } from '@auth0/auth0-spa-js';
51
73
  export { OAuthError } from './errors';
package/src/use-auth0.tsx CHANGED
@@ -14,7 +14,8 @@ import Auth0Context, { Auth0ContextInterface } from './auth0-context';
14
14
  * getAccessTokenSilently,
15
15
  * getAccessTokenWithPopup,
16
16
  * getIdTokenClaims,
17
- * exchangeToken,
17
+ * loginWithCustomTokenExchange,
18
+ * exchangeToken, // deprecated - use loginWithCustomTokenExchange
18
19
  * loginWithRedirect,
19
20
  * loginWithPopup,
20
21
  * logout,