@auth0/auth0-react 2.8.0 → 2.10.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 } 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 } 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,EAA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B,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,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
@@ -12,6 +12,7 @@ import { Auth0ContextInterface } from './auth0-context';
12
12
  * getAccessTokenSilently,
13
13
  * getAccessTokenWithPopup,
14
14
  * getIdTokenClaims,
15
+ * exchangeToken,
15
16
  * loginWithRedirect,
16
17
  * loginWithPopup,
17
18
  * 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;;;;;;;;;;;;;;;;;;;;;GAqBG;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;;;;;;;;;;;;;;;;;;;;;;GAsBG;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.8.0",
4
+ "version": "2.10.0",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -74,8 +74,8 @@
74
74
  "oidc-provider": "^8.8.1",
75
75
  "prettier": "^2.8.1",
76
76
  "pretty-quick": "^3.1.3",
77
- "react": "19.1.0",
78
- "react-dom": "19.1.0",
77
+ "react": "19.1.2",
78
+ "react-dom": "19.1.2",
79
79
  "rollup": "^3.7.0",
80
80
  "rollup-plugin-analyzer": "^4.0.0",
81
81
  "rollup-plugin-delete": "^2.0.0",
@@ -91,10 +91,10 @@
91
91
  "typescript": "^5.8.3"
92
92
  },
93
93
  "peerDependencies": {
94
- "react": "^16.11.0 || ^17 || ^18 || ^19",
95
- "react-dom": "^16.11.0 || ^17 || ^18 || ^19"
94
+ "react": "^16.11.0 || ^17 || ^18 || ~19.0.1 || ~19.1.2 || ^19.2.1",
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.7.0"
98
+ "@auth0/auth0-spa-js": "^2.9.1"
99
99
  }
100
100
  }
@@ -11,7 +11,9 @@ import {
11
11
  RedirectLoginOptions as SPARedirectLoginOptions,
12
12
  type Auth0Client,
13
13
  RedirectConnectAccountOptions,
14
- ConnectAccountRedirectResult
14
+ ConnectAccountRedirectResult,
15
+ CustomTokenExchangeOptions,
16
+ TokenEndpointResponse
15
17
  } from '@auth0/auth0-spa-js';
16
18
  import { createContext } from 'react';
17
19
  import { AuthState, initialAuthState } from './auth-state';
@@ -90,6 +92,35 @@ export interface Auth0ContextInterface<TUser extends User = User>
90
92
  */
91
93
  getIdTokenClaims: () => Promise<IdToken | undefined>;
92
94
 
95
+ /**
96
+ * ```js
97
+ * const tokenResponse = await exchangeToken({
98
+ * subject_token: 'external_token_value',
99
+ * subject_token_type: 'urn:acme:legacy-system-token',
100
+ * scope: 'openid profile email'
101
+ * });
102
+ * ```
103
+ *
104
+ * Exchanges an external subject token for Auth0 tokens via a token exchange request.
105
+ *
106
+ * This method implements the token exchange grant as specified in RFC 8693.
107
+ * It performs a token exchange by sending a request to the `/oauth/token` endpoint
108
+ * with the external token and returns Auth0 tokens (access token, ID token, etc.).
109
+ *
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)
116
+ *
117
+ * @param options - The options required to perform the token exchange
118
+ * @returns A promise that resolves to the token endpoint response containing Auth0 tokens
119
+ */
120
+ exchangeToken: (
121
+ options: CustomTokenExchangeOptions
122
+ ) => Promise<TokenEndpointResponse>;
123
+
93
124
  /**
94
125
  * ```js
95
126
  * await loginWithRedirect(options);
@@ -126,9 +157,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
126
157
  * ```js
127
158
  * await connectAccountWithRedirect({
128
159
  * connection: 'google-oauth2',
129
- * authorizationParams: {
130
- * access_type: 'offline',
131
- * scope: 'openid profile email https://www.googleapis.com/auth/drive.readonly',
160
+ * scopes: ['openid', 'profile', 'email', 'https://www.googleapis.com/auth/drive.readonly'],
161
+ * authorization_params: {
162
+ * // additional authorization params to forward to the authorization server
132
163
  * }
133
164
  * });
134
165
  * ```
@@ -229,6 +260,7 @@ export const initialContext = {
229
260
  getAccessTokenSilently: stub,
230
261
  getAccessTokenWithPopup: stub,
231
262
  getIdTokenClaims: stub,
263
+ exchangeToken: stub,
232
264
  loginWithRedirect: stub,
233
265
  loginWithPopup: stub,
234
266
  connectAccountWithRedirect: stub,
@@ -17,7 +17,9 @@ import {
17
17
  User,
18
18
  RedirectConnectAccountOptions,
19
19
  ConnectAccountRedirectResult,
20
- ResponseType
20
+ ResponseType,
21
+ CustomTokenExchangeOptions,
22
+ TokenEndpointResponse
21
23
  } from '@auth0/auth0-spa-js';
22
24
  import Auth0Context, {
23
25
  Auth0ContextInterface,
@@ -277,6 +279,30 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
277
279
  [client]
278
280
  );
279
281
 
282
+ const exchangeToken = useCallback(
283
+ async (
284
+ options: CustomTokenExchangeOptions
285
+ ): Promise<TokenEndpointResponse> => {
286
+ let tokenResponse;
287
+ try {
288
+ tokenResponse = await client.exchangeToken(options);
289
+ } catch (error) {
290
+ throw tokenError(error);
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
295
+ // identical regardless of whether the token was retrieved via silent auth or CTE.
296
+ dispatch({
297
+ type: 'GET_ACCESS_TOKEN_COMPLETE',
298
+ user: await client.getUser(),
299
+ });
300
+ }
301
+ return tokenResponse;
302
+ },
303
+ [client]
304
+ );
305
+
280
306
  const handleRedirectCallback = useCallback(
281
307
  async (
282
308
  url?: string
@@ -321,6 +347,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
321
347
  getAccessTokenSilently,
322
348
  getAccessTokenWithPopup,
323
349
  getIdTokenClaims,
350
+ exchangeToken,
324
351
  loginWithRedirect,
325
352
  loginWithPopup,
326
353
  connectAccountWithRedirect,
@@ -336,6 +363,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
336
363
  getAccessTokenSilently,
337
364
  getAccessTokenWithPopup,
338
365
  getIdTokenClaims,
366
+ exchangeToken,
339
367
  loginWithRedirect,
340
368
  loginWithPopup,
341
369
  connectAccountWithRedirect,
package/src/index.tsx CHANGED
@@ -43,6 +43,8 @@ export {
43
43
  RedirectConnectAccountOptions,
44
44
  ConnectAccountRedirectResult,
45
45
  ResponseType,
46
- ConnectError
46
+ ConnectError,
47
+ CustomTokenExchangeOptions,
48
+ TokenEndpointResponse
47
49
  } from '@auth0/auth0-spa-js';
48
50
  export { OAuthError } from './errors';
package/src/use-auth0.tsx CHANGED
@@ -14,6 +14,7 @@ import Auth0Context, { Auth0ContextInterface } from './auth0-context';
14
14
  * getAccessTokenSilently,
15
15
  * getAccessTokenWithPopup,
16
16
  * getIdTokenClaims,
17
+ * exchangeToken,
17
18
  * loginWithRedirect,
18
19
  * loginWithPopup,
19
20
  * logout,