@auth0/auth0-react 2.12.0 → 2.13.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/auth0-context.d.ts +61 -7
- package/dist/auth0-context.d.ts.map +1 -1
- package/dist/auth0-provider.d.ts.map +1 -1
- package/dist/auth0-react.cjs.js +21 -14
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +21 -14
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +21 -14
- package/dist/auth0-react.js.map +1 -1
- package/dist/auth0-react.min.js +1 -1
- package/dist/auth0-react.min.js.map +1 -1
- package/dist/use-auth0.d.ts +2 -1
- package/dist/use-auth0.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/auth0-context.tsx +64 -7
- package/src/auth0-provider.tsx +16 -5
- package/src/use-auth0.tsx +2 -1
package/dist/use-auth0.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { Auth0ContextInterface } from './auth0-context';
|
|
|
12
12
|
* getAccessTokenSilently,
|
|
13
13
|
* getAccessTokenWithPopup,
|
|
14
14
|
* getIdTokenClaims,
|
|
15
|
-
*
|
|
15
|
+
* loginWithCustomTokenExchange,
|
|
16
|
+
* exchangeToken, // deprecated - use loginWithCustomTokenExchange
|
|
16
17
|
* loginWithRedirect,
|
|
17
18
|
* loginWithPopup,
|
|
18
19
|
* logout,
|
package/dist/use-auth0.d.ts.map
CHANGED
|
@@ -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
|
|
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.
|
|
4
|
+
"version": "2.13.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.
|
|
61
|
+
"@types/react": "19.2.11",
|
|
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.
|
|
98
|
+
"@auth0/auth0-spa-js": "^2.14.0"
|
|
99
99
|
}
|
|
100
100
|
}
|
package/src/auth0-context.tsx
CHANGED
|
@@ -93,6 +93,60 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
93
93
|
getIdTokenClaims: () => Promise<IdToken | undefined>;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
+
* ```js
|
|
97
|
+
* await loginWithCustomTokenExchange(options);
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Exchanges an external subject token for Auth0 tokens and logs the user in.
|
|
101
|
+
* This method implements the Custom Token Exchange grant as specified in RFC 8693.
|
|
102
|
+
*
|
|
103
|
+
* The exchanged tokens are automatically cached, establishing an authenticated session.
|
|
104
|
+
* After calling this method, you can use `getUser()`, `getIdTokenClaims()`, and
|
|
105
|
+
* `getTokenSilently()` to access the user's information and tokens.
|
|
106
|
+
*
|
|
107
|
+
* @param options - The options required to perform the token exchange.
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves to the token endpoint response,
|
|
110
|
+
* which contains the issued Auth0 tokens (access_token, id_token, etc.).
|
|
111
|
+
*
|
|
112
|
+
* The request includes the following parameters:
|
|
113
|
+
* - `grant_type`: "urn:ietf:params:oauth:grant-type:token-exchange"
|
|
114
|
+
* - `subject_token`: The external token to exchange
|
|
115
|
+
* - `subject_token_type`: The type identifier of the external token
|
|
116
|
+
* - `scope`: Merged scopes from the request and SDK defaults
|
|
117
|
+
* - `audience`: Target audience (defaults to SDK configuration)
|
|
118
|
+
* - `organization`: Optional organization ID/name for org-scoped authentication
|
|
119
|
+
*
|
|
120
|
+
* **Example Usage:**
|
|
121
|
+
*
|
|
122
|
+
* ```js
|
|
123
|
+
* const options = {
|
|
124
|
+
* subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
|
|
125
|
+
* subject_token_type: 'urn:acme:legacy-system-token',
|
|
126
|
+
* scope: 'openid profile email',
|
|
127
|
+
* audience: 'https://api.example.com',
|
|
128
|
+
* organization: 'org_12345'
|
|
129
|
+
* };
|
|
130
|
+
*
|
|
131
|
+
* try {
|
|
132
|
+
* const tokenResponse = await loginWithCustomTokenExchange(options);
|
|
133
|
+
* console.log('Access token:', tokenResponse.access_token);
|
|
134
|
+
*
|
|
135
|
+
* // User is now logged in - access user info
|
|
136
|
+
* const user = await getUser();
|
|
137
|
+
* console.log('Logged in user:', user);
|
|
138
|
+
* } catch (error) {
|
|
139
|
+
* console.error('Token exchange failed:', error);
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
loginWithCustomTokenExchange: (
|
|
144
|
+
options: CustomTokenExchangeOptions
|
|
145
|
+
) => Promise<TokenEndpointResponse>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @deprecated Use `loginWithCustomTokenExchange()` instead. This method will be removed in the next major version.
|
|
149
|
+
*
|
|
96
150
|
* ```js
|
|
97
151
|
* const tokenResponse = await exchangeToken({
|
|
98
152
|
* subject_token: 'external_token_value',
|
|
@@ -101,18 +155,20 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
101
155
|
* });
|
|
102
156
|
* ```
|
|
103
157
|
*
|
|
104
|
-
* Exchanges an external subject token for Auth0 tokens
|
|
158
|
+
* Exchanges an external subject token for Auth0 tokens and logs the user in.
|
|
105
159
|
*
|
|
106
160
|
* This method implements the token exchange grant as specified in RFC 8693.
|
|
107
161
|
* It performs a token exchange by sending a request to the `/oauth/token` endpoint
|
|
108
162
|
* with the external token and returns Auth0 tokens (access token, ID token, etc.).
|
|
109
163
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
164
|
+
* **Example:**
|
|
165
|
+
* ```js
|
|
166
|
+
* // Instead of:
|
|
167
|
+
* const tokens = await exchangeToken(options);
|
|
168
|
+
*
|
|
169
|
+
* // Use:
|
|
170
|
+
* const tokens = await loginWithCustomTokenExchange(options);
|
|
171
|
+
* ```
|
|
116
172
|
*
|
|
117
173
|
* @param options - The options required to perform the token exchange
|
|
118
174
|
* @returns A promise that resolves to the token endpoint response containing Auth0 tokens
|
|
@@ -271,6 +327,7 @@ export const initialContext = {
|
|
|
271
327
|
getAccessTokenSilently: stub,
|
|
272
328
|
getAccessTokenWithPopup: stub,
|
|
273
329
|
getIdTokenClaims: stub,
|
|
330
|
+
loginWithCustomTokenExchange: stub,
|
|
274
331
|
exchangeToken: stub,
|
|
275
332
|
loginWithRedirect: stub,
|
|
276
333
|
loginWithPopup: stub,
|
package/src/auth0-provider.tsx
CHANGED
|
@@ -279,19 +279,19 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
279
279
|
[client]
|
|
280
280
|
);
|
|
281
281
|
|
|
282
|
-
const
|
|
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.
|
|
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
|
|
@@ -352,6 +361,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
352
361
|
getAccessTokenSilently,
|
|
353
362
|
getAccessTokenWithPopup,
|
|
354
363
|
getIdTokenClaims,
|
|
364
|
+
loginWithCustomTokenExchange,
|
|
355
365
|
exchangeToken,
|
|
356
366
|
loginWithRedirect,
|
|
357
367
|
loginWithPopup,
|
|
@@ -369,6 +379,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
369
379
|
getAccessTokenSilently,
|
|
370
380
|
getAccessTokenWithPopup,
|
|
371
381
|
getIdTokenClaims,
|
|
382
|
+
loginWithCustomTokenExchange,
|
|
372
383
|
exchangeToken,
|
|
373
384
|
loginWithRedirect,
|
|
374
385
|
loginWithPopup,
|
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
|
-
*
|
|
17
|
+
* loginWithCustomTokenExchange,
|
|
18
|
+
* exchangeToken, // deprecated - use loginWithCustomTokenExchange
|
|
18
19
|
* loginWithRedirect,
|
|
19
20
|
* loginWithPopup,
|
|
20
21
|
* logout,
|