@auth0/auth0-react 2.4.0 → 2.6.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 +46 -1
- package/dist/auth0-context.d.ts.map +1 -1
- package/dist/auth0-provider.d.ts.map +1 -1
- package/dist/auth0-react.cjs.js +24 -13
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +18 -8
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +24 -13
- 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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/auth0-context.tsx +50 -0
- package/src/auth0-provider.tsx +28 -0
- package/src/index.tsx +3 -1
- package/src/utils.tsx +15 -4
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 } 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 } from '@auth0/auth0-spa-js';
|
|
7
7
|
export { OAuthError } from './errors';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,GACT,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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,oBAAoB,EACpB,QAAQ,GACT,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,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,aAAa,GAAI,qBAAqC,KAAG,OAEzC,CAAC;AA4B9B,eAAO,MAAM,UAAU,UAxBb,OAAO,KAAG,KAwBsC,CAAC;AAE3D,eAAO,MAAM,UAAU,UA1Bb,OAAO,KAAG,KA0BiD,CAAC;AAEtE;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,GAAI,UAAU,GAAG,SAkBjD,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.6.0",
|
|
5
5
|
"description": "Auth0 SDK for React Single Page Applications (SPA)",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"auth0",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@rollup/plugin-replace": "^5.0.1",
|
|
56
56
|
"@rollup/plugin-terser": "^0.4.3",
|
|
57
57
|
"@testing-library/dom": "^10.4.0",
|
|
58
|
-
"@testing-library/jest-dom": "6.
|
|
59
|
-
"@testing-library/react": "16.
|
|
58
|
+
"@testing-library/jest-dom": "6.8.0",
|
|
59
|
+
"@testing-library/react": "16.3.0",
|
|
60
60
|
"@types/jest": "^29.5.14",
|
|
61
61
|
"@types/react": "19.1.8",
|
|
62
62
|
"@types/react-dom": "19.1.6",
|
|
@@ -95,6 +95,6 @@
|
|
|
95
95
|
"react-dom": "^16.11.0 || ^17 || ^18 || ^19"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@auth0/auth0-spa-js": "^2.
|
|
98
|
+
"@auth0/auth0-spa-js": "^2.5.0"
|
|
99
99
|
}
|
|
100
100
|
}
|
package/src/auth0-context.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
User,
|
|
10
10
|
GetTokenSilentlyVerboseResponse,
|
|
11
11
|
RedirectLoginOptions as SPARedirectLoginOptions,
|
|
12
|
+
type Auth0Client,
|
|
12
13
|
} from '@auth0/auth0-spa-js';
|
|
13
14
|
import { createContext } from 'react';
|
|
14
15
|
import { AuthState, initialAuthState } from './auth-state';
|
|
@@ -140,6 +141,51 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
140
141
|
* @param url The URL to that should be used to retrieve the `state` and `code` values. Defaults to `window.location.href` if not given.
|
|
141
142
|
*/
|
|
142
143
|
handleRedirectCallback: (url?: string) => Promise<RedirectLoginResult>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Returns the current DPoP nonce used for making requests to Auth0.
|
|
147
|
+
*
|
|
148
|
+
* It can return `undefined` because when starting fresh it will not
|
|
149
|
+
* be populated until after the first response from the server.
|
|
150
|
+
*
|
|
151
|
+
* It requires enabling the {@link Auth0ClientOptions.useDpop} option.
|
|
152
|
+
*
|
|
153
|
+
* @param nonce The nonce value.
|
|
154
|
+
* @param id The identifier of a nonce: if absent, it will get the nonce
|
|
155
|
+
* used for requests to Auth0. Otherwise, it will be used to
|
|
156
|
+
* select a specific non-Auth0 nonce.
|
|
157
|
+
*/
|
|
158
|
+
getDpopNonce: Auth0Client['getDpopNonce'];
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Sets the current DPoP nonce used for making requests to Auth0.
|
|
162
|
+
*
|
|
163
|
+
* It requires enabling the {@link Auth0ClientOptions.useDpop} option.
|
|
164
|
+
*
|
|
165
|
+
* @param nonce The nonce value.
|
|
166
|
+
* @param id The identifier of a nonce: if absent, it will set the nonce
|
|
167
|
+
* used for requests to Auth0. Otherwise, it will be used to
|
|
168
|
+
* select a specific non-Auth0 nonce.
|
|
169
|
+
*/
|
|
170
|
+
setDpopNonce: Auth0Client['setDpopNonce'];
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Returns a string to be used to demonstrate possession of the private
|
|
174
|
+
* key used to cryptographically bind access tokens with DPoP.
|
|
175
|
+
*
|
|
176
|
+
* It requires enabling the {@link Auth0ClientOptions.useDpop} option.
|
|
177
|
+
*/
|
|
178
|
+
generateDpopProof: Auth0Client['generateDpopProof'];
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns a new `Fetcher` class that will contain a `fetchWithAuth()` method.
|
|
182
|
+
* This is a drop-in replacement for the Fetch API's `fetch()` method, but will
|
|
183
|
+
* handle certain authentication logic for you, like building the proper auth
|
|
184
|
+
* headers or managing DPoP nonces and retries automatically.
|
|
185
|
+
*
|
|
186
|
+
* Check the `EXAMPLES.md` file for a deeper look into this method.
|
|
187
|
+
*/
|
|
188
|
+
createFetcher: Auth0Client['createFetcher'];
|
|
143
189
|
}
|
|
144
190
|
|
|
145
191
|
/**
|
|
@@ -163,6 +209,10 @@ export const initialContext = {
|
|
|
163
209
|
loginWithPopup: stub,
|
|
164
210
|
logout: stub,
|
|
165
211
|
handleRedirectCallback: stub,
|
|
212
|
+
getDpopNonce: stub,
|
|
213
|
+
setDpopNonce: stub,
|
|
214
|
+
generateDpopProof: stub,
|
|
215
|
+
createFetcher: stub,
|
|
166
216
|
};
|
|
167
217
|
|
|
168
218
|
/**
|
package/src/auth0-provider.tsx
CHANGED
|
@@ -272,6 +272,26 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
272
272
|
[client]
|
|
273
273
|
);
|
|
274
274
|
|
|
275
|
+
const getDpopNonce = useCallback<Auth0Client['getDpopNonce']>(
|
|
276
|
+
(id) => client.getDpopNonce(id),
|
|
277
|
+
[client]
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
const setDpopNonce = useCallback<Auth0Client['setDpopNonce']>(
|
|
281
|
+
(nonce, id) => client.setDpopNonce(nonce, id),
|
|
282
|
+
[client]
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const generateDpopProof = useCallback<Auth0Client['generateDpopProof']>(
|
|
286
|
+
(params) => client.generateDpopProof(params),
|
|
287
|
+
[client]
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const createFetcher = useCallback<Auth0Client['createFetcher']>(
|
|
291
|
+
(config) => client.createFetcher(config),
|
|
292
|
+
[client]
|
|
293
|
+
);
|
|
294
|
+
|
|
275
295
|
const contextValue = useMemo<Auth0ContextInterface<TUser>>(() => {
|
|
276
296
|
return {
|
|
277
297
|
...state,
|
|
@@ -282,6 +302,10 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
282
302
|
loginWithPopup,
|
|
283
303
|
logout,
|
|
284
304
|
handleRedirectCallback,
|
|
305
|
+
getDpopNonce,
|
|
306
|
+
setDpopNonce,
|
|
307
|
+
generateDpopProof,
|
|
308
|
+
createFetcher,
|
|
285
309
|
};
|
|
286
310
|
}, [
|
|
287
311
|
state,
|
|
@@ -292,6 +316,10 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
292
316
|
loginWithPopup,
|
|
293
317
|
logout,
|
|
294
318
|
handleRedirectCallback,
|
|
319
|
+
getDpopNonce,
|
|
320
|
+
setDpopNonce,
|
|
321
|
+
generateDpopProof,
|
|
322
|
+
createFetcher,
|
|
295
323
|
]);
|
|
296
324
|
|
|
297
325
|
return <context.Provider value={contextValue}>{children}</context.Provider>;
|
package/src/index.tsx
CHANGED
package/src/utils.tsx
CHANGED
|
@@ -4,6 +4,15 @@ const CODE_RE = /[?&]code=[^&]+/;
|
|
|
4
4
|
const STATE_RE = /[?&]state=[^&]+/;
|
|
5
5
|
const ERROR_RE = /[?&]error=[^&]+/;
|
|
6
6
|
|
|
7
|
+
interface WithError {
|
|
8
|
+
error: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface WithErrorAndDescription {
|
|
12
|
+
error: string;
|
|
13
|
+
error_description: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
export const hasAuthParams = (searchParams = window.location.search): boolean =>
|
|
8
17
|
(CODE_RE.test(searchParams) || ERROR_RE.test(searchParams)) &&
|
|
9
18
|
STATE_RE.test(searchParams);
|
|
@@ -19,15 +28,17 @@ const normalizeErrorFn =
|
|
|
19
28
|
error !== null &&
|
|
20
29
|
typeof error === 'object' &&
|
|
21
30
|
'error' in error &&
|
|
22
|
-
typeof error.error === 'string'
|
|
31
|
+
typeof (error as WithError).error === 'string'
|
|
23
32
|
) {
|
|
24
33
|
if (
|
|
25
34
|
'error_description' in error &&
|
|
26
|
-
typeof error.error_description === 'string'
|
|
35
|
+
typeof (error as WithErrorAndDescription).error_description === 'string'
|
|
27
36
|
) {
|
|
28
|
-
|
|
37
|
+
const e = error as WithErrorAndDescription;
|
|
38
|
+
return new OAuthError(e.error, e.error_description);
|
|
29
39
|
}
|
|
30
|
-
|
|
40
|
+
const e = error as WithError;
|
|
41
|
+
return new OAuthError(e.error);
|
|
31
42
|
}
|
|
32
43
|
return new Error(fallbackMessage);
|
|
33
44
|
};
|