@auth0/auth0-react 2.6.0 → 2.8.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 +22 -2
- package/dist/auth0-context.d.ts.map +1 -1
- package/dist/auth0-provider.d.ts +9 -2
- package/dist/auth0-provider.d.ts.map +1 -1
- package/dist/auth0-react.cjs.js +36 -27
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +26 -18
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +36 -27
- 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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/auth0-context.tsx +26 -1
- package/src/auth0-provider.tsx +29 -4
- package/src/index.tsx +6 -1
- package/src/utils.tsx +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { default as Auth0Provider, Auth0ProviderOptions, AppState, } from './auth0-provider';
|
|
1
|
+
export { default as Auth0Provider, Auth0ProviderOptions, AppState, ConnectedAccount } from './auth0-provider';
|
|
2
2
|
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 } 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 } 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,
|
|
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,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,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.8.0",
|
|
5
5
|
"description": "Auth0 SDK for React Single Page Applications (SPA)",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"auth0",
|
|
@@ -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.7.0"
|
|
99
99
|
}
|
|
100
100
|
}
|
package/src/auth0-context.tsx
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
GetTokenSilentlyVerboseResponse,
|
|
11
11
|
RedirectLoginOptions as SPARedirectLoginOptions,
|
|
12
12
|
type Auth0Client,
|
|
13
|
+
RedirectConnectAccountOptions,
|
|
14
|
+
ConnectAccountRedirectResult
|
|
13
15
|
} from '@auth0/auth0-spa-js';
|
|
14
16
|
import { createContext } from 'react';
|
|
15
17
|
import { AuthState, initialAuthState } from './auth-state';
|
|
@@ -120,6 +122,28 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
120
122
|
config?: PopupConfigOptions
|
|
121
123
|
) => Promise<void>;
|
|
122
124
|
|
|
125
|
+
/**
|
|
126
|
+
* ```js
|
|
127
|
+
* await connectAccountWithRedirect({
|
|
128
|
+
* connection: 'google-oauth2',
|
|
129
|
+
* authorizationParams: {
|
|
130
|
+
* access_type: 'offline',
|
|
131
|
+
* scope: 'openid profile email https://www.googleapis.com/auth/drive.readonly',
|
|
132
|
+
* }
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* Redirects to the `/connect` URL using the parameters
|
|
137
|
+
* provided as arguments. This then redirects to the connection's login page
|
|
138
|
+
* where the user can authenticate and authorize the account to be connected.
|
|
139
|
+
*
|
|
140
|
+
* If connecting the account is successful `onRedirectCallback` will be called
|
|
141
|
+
* with the details of the connected account.
|
|
142
|
+
*/
|
|
143
|
+
connectAccountWithRedirect: (
|
|
144
|
+
options: RedirectConnectAccountOptions
|
|
145
|
+
) => Promise<void>;
|
|
146
|
+
|
|
123
147
|
/**
|
|
124
148
|
* ```js
|
|
125
149
|
* auth0.logout({ logoutParams: { returnTo: window.location.origin } });
|
|
@@ -140,7 +164,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
140
164
|
*
|
|
141
165
|
* @param url The URL to that should be used to retrieve the `state` and `code` values. Defaults to `window.location.href` if not given.
|
|
142
166
|
*/
|
|
143
|
-
handleRedirectCallback: (url?: string) => Promise<RedirectLoginResult>;
|
|
167
|
+
handleRedirectCallback: (url?: string) => Promise<RedirectLoginResult | ConnectAccountRedirectResult>;
|
|
144
168
|
|
|
145
169
|
/**
|
|
146
170
|
* Returns the current DPoP nonce used for making requests to Auth0.
|
|
@@ -207,6 +231,7 @@ export const initialContext = {
|
|
|
207
231
|
getIdTokenClaims: stub,
|
|
208
232
|
loginWithRedirect: stub,
|
|
209
233
|
loginWithPopup: stub,
|
|
234
|
+
connectAccountWithRedirect: stub,
|
|
210
235
|
logout: stub,
|
|
211
236
|
handleRedirectCallback: stub,
|
|
212
237
|
getDpopNonce: stub,
|
package/src/auth0-provider.tsx
CHANGED
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
RedirectLoginResult,
|
|
16
16
|
GetTokenSilentlyOptions,
|
|
17
17
|
User,
|
|
18
|
+
RedirectConnectAccountOptions,
|
|
19
|
+
ConnectAccountRedirectResult,
|
|
20
|
+
ResponseType
|
|
18
21
|
} from '@auth0/auth0-spa-js';
|
|
19
22
|
import Auth0Context, {
|
|
20
23
|
Auth0ContextInterface,
|
|
@@ -31,10 +34,18 @@ import { reducer } from './reducer';
|
|
|
31
34
|
import { initialAuthState, type AuthState } from './auth-state';
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
|
-
* The
|
|
37
|
+
* The account that has been connected during the connect flow.
|
|
38
|
+
*/
|
|
39
|
+
export type ConnectedAccount = Omit<ConnectAccountRedirectResult, 'appState' | 'response_type'>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The state of the application before the user was redirected to the login page
|
|
43
|
+
* and any account that the user may have connected to.
|
|
35
44
|
*/
|
|
36
45
|
export type AppState = {
|
|
37
46
|
returnTo?: string;
|
|
47
|
+
connectedAccount?: ConnectedAccount;
|
|
48
|
+
response_type?: ResponseType;
|
|
38
49
|
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
39
50
|
};
|
|
40
51
|
|
|
@@ -116,7 +127,7 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
|
|
|
116
127
|
window.history.replaceState(
|
|
117
128
|
{},
|
|
118
129
|
document.title,
|
|
119
|
-
appState
|
|
130
|
+
appState!.returnTo ?? window.location.pathname
|
|
120
131
|
);
|
|
121
132
|
};
|
|
122
133
|
|
|
@@ -160,8 +171,12 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
160
171
|
try {
|
|
161
172
|
let user: TUser | undefined;
|
|
162
173
|
if (hasAuthParams() && !skipRedirectCallback) {
|
|
163
|
-
const { appState } = await client.handleRedirectCallback();
|
|
174
|
+
const { appState = {}, response_type, ...result } = await client.handleRedirectCallback();
|
|
164
175
|
user = await client.getUser();
|
|
176
|
+
appState.response_type = response_type;
|
|
177
|
+
if (response_type === ResponseType.ConnectCode) {
|
|
178
|
+
appState.connectedAccount = result as ConnectedAccount;
|
|
179
|
+
}
|
|
165
180
|
onRedirectCallback(appState, user);
|
|
166
181
|
} else {
|
|
167
182
|
await client.checkSession();
|
|
@@ -251,13 +266,21 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
251
266
|
[client]
|
|
252
267
|
);
|
|
253
268
|
|
|
269
|
+
const connectAccountWithRedirect = useCallback(
|
|
270
|
+
(options: RedirectConnectAccountOptions) =>
|
|
271
|
+
client.connectAccountWithRedirect(options),
|
|
272
|
+
[client]
|
|
273
|
+
);
|
|
274
|
+
|
|
254
275
|
const getIdTokenClaims = useCallback(
|
|
255
276
|
() => client.getIdTokenClaims(),
|
|
256
277
|
[client]
|
|
257
278
|
);
|
|
258
279
|
|
|
259
280
|
const handleRedirectCallback = useCallback(
|
|
260
|
-
async (
|
|
281
|
+
async (
|
|
282
|
+
url?: string
|
|
283
|
+
): Promise<RedirectLoginResult | ConnectAccountRedirectResult> => {
|
|
261
284
|
try {
|
|
262
285
|
return await client.handleRedirectCallback(url);
|
|
263
286
|
} catch (error) {
|
|
@@ -300,6 +323,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
300
323
|
getIdTokenClaims,
|
|
301
324
|
loginWithRedirect,
|
|
302
325
|
loginWithPopup,
|
|
326
|
+
connectAccountWithRedirect,
|
|
303
327
|
logout,
|
|
304
328
|
handleRedirectCallback,
|
|
305
329
|
getDpopNonce,
|
|
@@ -314,6 +338,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
|
|
|
314
338
|
getIdTokenClaims,
|
|
315
339
|
loginWithRedirect,
|
|
316
340
|
loginWithPopup,
|
|
341
|
+
connectAccountWithRedirect,
|
|
317
342
|
logout,
|
|
318
343
|
handleRedirectCallback,
|
|
319
344
|
getDpopNonce,
|
package/src/index.tsx
CHANGED
|
@@ -2,6 +2,7 @@ export {
|
|
|
2
2
|
default as Auth0Provider,
|
|
3
3
|
Auth0ProviderOptions,
|
|
4
4
|
AppState,
|
|
5
|
+
ConnectedAccount
|
|
5
6
|
} from './auth0-provider';
|
|
6
7
|
export { default as useAuth0 } from './use-auth0';
|
|
7
8
|
export { default as withAuth0, WithAuth0Props } from './with-auth0';
|
|
@@ -38,6 +39,10 @@ export {
|
|
|
38
39
|
MissingRefreshTokenError,
|
|
39
40
|
GenericError,
|
|
40
41
|
UseDpopNonceError,
|
|
41
|
-
type FetcherConfig
|
|
42
|
+
type FetcherConfig,
|
|
43
|
+
RedirectConnectAccountOptions,
|
|
44
|
+
ConnectAccountRedirectResult,
|
|
45
|
+
ResponseType,
|
|
46
|
+
ConnectError
|
|
42
47
|
} from '@auth0/auth0-spa-js';
|
|
43
48
|
export { OAuthError } from './errors';
|