@auth0/auth0-react 1.11.0 → 2.0.0-beta.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/README.md +69 -148
- package/dist/auth0-context.d.ts +27 -43
- package/dist/auth0-context.d.ts.map +1 -1
- package/dist/auth0-provider.d.ts +16 -100
- package/dist/auth0-provider.d.ts.map +1 -1
- package/dist/auth0-react.cjs.js +46 -64
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +42 -55
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +46 -64
- package/dist/auth0-react.js.map +1 -1
- package/dist/auth0-react.min.js +1 -15
- 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/dist/reducer.d.ts +1 -1
- package/dist/reducer.d.ts.map +1 -1
- package/dist/use-auth0.d.ts +2 -1
- package/dist/use-auth0.d.ts.map +1 -1
- package/dist/with-auth0.d.ts +5 -2
- package/dist/with-auth0.d.ts.map +1 -1
- package/dist/with-authentication-required.d.ts +5 -4
- package/dist/with-authentication-required.d.ts.map +1 -1
- package/package.json +33 -32
- package/src/auth0-context.tsx +18 -58
- package/src/auth0-provider.tsx +27 -155
- package/src/index.tsx +3 -2
- package/src/reducer.tsx +1 -1
- package/src/use-auth0.tsx +5 -3
- package/src/with-auth0.tsx +8 -4
- package/src/with-authentication-required.tsx +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { default as Auth0Provider, Auth0ProviderOptions, AppState, } from './aut
|
|
|
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
|
-
export { default as Auth0Context, Auth0ContextInterface, RedirectLoginOptions, } from './auth0-context';
|
|
6
|
-
export { PopupLoginOptions, PopupConfigOptions,
|
|
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, } 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,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,
|
|
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,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/reducer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { User } from '@auth0/auth0-spa-js';
|
|
2
2
|
import { AuthState } from './auth-state';
|
|
3
|
-
|
|
3
|
+
type Action = {
|
|
4
4
|
type: 'LOGIN_POPUP_STARTED';
|
|
5
5
|
} | {
|
|
6
6
|
type: 'INITIALISED' | 'LOGIN_POPUP_COMPLETE' | 'GET_ACCESS_TOKEN_COMPLETE' | 'HANDLE_REDIRECT_COMPLETE';
|
package/dist/reducer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,KAAK,MAAM,GACP;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,GAC/B;IACE,IAAI,EACA,aAAa,GACb,sBAAsB,GACtB,2BAA2B,GAC3B,0BAA0B,CAAC;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,GACD;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,OAAO,UAAW,SAAS,UAAU,MAAM,KAAG,SAuC1D,CAAC"}
|
package/dist/use-auth0.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { User } from '@auth0/auth0-spa-js';
|
|
2
3
|
import { Auth0ContextInterface } from './auth0-context';
|
|
3
4
|
/**
|
|
@@ -22,6 +23,6 @@ import { Auth0ContextInterface } from './auth0-context';
|
|
|
22
23
|
*
|
|
23
24
|
* TUser is an optional type param to provide a type to the `user` field.
|
|
24
25
|
*/
|
|
25
|
-
declare const useAuth0: <TUser extends User = User>() => Auth0ContextInterface<TUser>;
|
|
26
|
+
declare const useAuth0: <TUser extends User = User>(context?: import("react").Context<Auth0ContextInterface<User>>) => Auth0ContextInterface<TUser>;
|
|
26
27
|
export default useAuth0;
|
|
27
28
|
//# sourceMappingURL=use-auth0.d.ts.map
|
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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,QAAQ
|
|
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,6HAGuC,CAAC;AAEtD,eAAe,QAAQ,CAAC"}
|
package/dist/with-auth0.d.ts
CHANGED
|
@@ -19,8 +19,11 @@ export interface WithAuth0Props {
|
|
|
19
19
|
* export default withAuth0(MyComponent);
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* Wrap your class components in this Higher Order Component to give them access to the Auth0Context
|
|
22
|
+
* Wrap your class components in this Higher Order Component to give them access to the Auth0Context.
|
|
23
|
+
*
|
|
24
|
+
* Providing a context as the second argument allows you to configure the Auth0Provider the Auth0Context
|
|
25
|
+
* should come from f you have multiple within your application.
|
|
23
26
|
*/
|
|
24
|
-
declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P
|
|
27
|
+
declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P>, context?: React.Context<Auth0ContextInterface<import("@auth0/auth0-spa-js").User>>) => React.ComponentType<Omit<P, "auth0">>;
|
|
25
28
|
export default withAuth0;
|
|
26
29
|
//# sourceMappingURL=with-auth0.d.ts.map
|
package/dist/with-auth0.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED
|
|
1
|
+
{"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,SAAS,4LAad,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ComponentType, FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth0ContextInterface, RedirectLoginOptions } from './auth0-context';
|
|
3
3
|
/**
|
|
4
4
|
* Options for the withAuthenticationRequired Higher Order Component
|
|
5
5
|
*/
|
|
@@ -48,10 +48,11 @@ export interface WithAuthenticationRequiredOptions {
|
|
|
48
48
|
*/
|
|
49
49
|
loginOptions?: RedirectLoginOptions;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
* The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
|
|
52
|
+
* within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
|
|
53
|
+
* associated with the default Auth0Context.
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
+
context?: React.Context<Auth0ContextInterface>;
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* ```js
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,EAAE,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,EAAE,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAqB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAazB;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACnC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC;IAClC;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,kEAErB,iCAAiC,gBAqC3C,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Auth0",
|
|
3
3
|
"name": "@auth0/auth0-react",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-beta.0",
|
|
5
5
|
"description": "Auth0 SDK for React Single Page Applications (SPA)",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"auth0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"start:gatsby": "npm start --prefix=examples/gatsby-app",
|
|
32
32
|
"start:nextjs": "npm run dev --prefix=examples/nextjs-app",
|
|
33
33
|
"start:api": "npm start --prefix=examples/users-api",
|
|
34
|
-
"test:cra": "start-server-and-test start:api 3001 start:cra 3000 cypress:run",
|
|
34
|
+
"test:cra": "start-server-and-test start:api 3001 start:cra http-get://127.0.0.1:3000 cypress:run",
|
|
35
35
|
"test:cra:watch": "start-server-and-test start:api 3001 start:cra 3000 cypress:open",
|
|
36
36
|
"test:gatsby": "start-server-and-test start:api 3001 start:gatsby 3000 cypress:run",
|
|
37
37
|
"test:gatsby:watch": "start-server-and-test start:api 3001 start:gatsby 3000 cypress:open",
|
|
@@ -51,44 +51,45 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/auth0/auth0-react#readme",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@rollup/plugin-node-resolve": "^
|
|
55
|
-
"@rollup/plugin-replace": "^
|
|
56
|
-
"@
|
|
57
|
-
"@testing-library/
|
|
54
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
55
|
+
"@rollup/plugin-replace": "^5.0.1",
|
|
56
|
+
"@rollup/plugin-terser": "^0.1.0",
|
|
57
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
58
|
+
"@testing-library/react": "^13.4.0",
|
|
58
59
|
"@testing-library/react-hooks": "^7.0.2",
|
|
59
|
-
"@types/jest": "^
|
|
60
|
-
"@types/react": "^17.0.
|
|
61
|
-
"@types/react-dom": "^17.0.
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
63
|
-
"@typescript-eslint/parser": "^5.
|
|
64
|
-
"browserstack-cypress-cli": "^1.1
|
|
65
|
-
"cypress": "^9.
|
|
66
|
-
"eslint": "^8.
|
|
67
|
-
"eslint-plugin-react": "^7.
|
|
68
|
-
"eslint-plugin-react-hooks": "^4.
|
|
69
|
-
"husky": "^4.
|
|
70
|
-
"jest": "^
|
|
71
|
-
"jest-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
60
|
+
"@types/jest": "^29.2.3",
|
|
61
|
+
"@types/react": "^17.0.52",
|
|
62
|
+
"@types/react-dom": "^17.0.18",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
|
64
|
+
"@typescript-eslint/parser": "^5.45.0",
|
|
65
|
+
"browserstack-cypress-cli": "^1.19.1",
|
|
66
|
+
"cypress": "^9.7.0",
|
|
67
|
+
"eslint": "^8.28.0",
|
|
68
|
+
"eslint-plugin-react": "^7.31.11",
|
|
69
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
70
|
+
"husky": "^4.3.8",
|
|
71
|
+
"jest": "^29.3.1",
|
|
72
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
73
|
+
"jest-junit": "^15.0.0",
|
|
74
|
+
"oidc-provider": "^8.0.0",
|
|
75
|
+
"prettier": "^2.8.1",
|
|
74
76
|
"pretty-quick": "^3.1.3",
|
|
75
77
|
"react": "^18.2.0",
|
|
76
78
|
"react-dom": "^18.2.0",
|
|
77
|
-
"react-test-renderer": "^18.
|
|
78
|
-
"rollup": "^
|
|
79
|
+
"react-test-renderer": "^18.2.0",
|
|
80
|
+
"rollup": "^3.7.0",
|
|
79
81
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
80
82
|
"rollup-plugin-delete": "^2.0.0",
|
|
81
83
|
"rollup-plugin-dev": "^1.1.3",
|
|
82
84
|
"rollup-plugin-livereload": "^2.0.5",
|
|
83
85
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
84
|
-
"rollup-plugin-serve": "^
|
|
85
|
-
"rollup-plugin-
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"typescript": "^4.6.3"
|
|
86
|
+
"rollup-plugin-serve": "^2.0.2",
|
|
87
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
88
|
+
"start-server-and-test": "^1.15.2",
|
|
89
|
+
"ts-jest": "^29.0.3",
|
|
90
|
+
"tslib": "^2.4.1",
|
|
91
|
+
"typedoc": "^0.23.21",
|
|
92
|
+
"typescript": "^4.9.4"
|
|
92
93
|
},
|
|
93
94
|
"peerDependencies": {
|
|
94
95
|
"react": "^16.11.0 || ^17 || ^18",
|
|
@@ -100,6 +101,6 @@
|
|
|
100
101
|
}
|
|
101
102
|
},
|
|
102
103
|
"dependencies": {
|
|
103
|
-
"@auth0/auth0-spa-js": "^
|
|
104
|
+
"@auth0/auth0-spa-js": "^2.0.1"
|
|
104
105
|
}
|
|
105
106
|
}
|
package/src/auth0-context.tsx
CHANGED
|
@@ -1,40 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BaseLoginOptions,
|
|
3
|
-
GetIdTokenClaimsOptions,
|
|
4
2
|
GetTokenSilentlyOptions,
|
|
5
3
|
GetTokenWithPopupOptions,
|
|
6
4
|
IdToken,
|
|
7
|
-
LogoutOptions,
|
|
8
|
-
LogoutUrlOptions,
|
|
5
|
+
LogoutOptions as SPALogoutOptions,
|
|
9
6
|
PopupLoginOptions,
|
|
10
7
|
PopupConfigOptions,
|
|
11
|
-
RedirectLoginOptions as Auth0RedirectLoginOptions,
|
|
12
8
|
RedirectLoginResult,
|
|
13
9
|
User,
|
|
14
10
|
GetTokenSilentlyVerboseResponse,
|
|
11
|
+
RedirectLoginOptions as SPARedirectLoginOptions,
|
|
15
12
|
} from '@auth0/auth0-spa-js';
|
|
16
13
|
import { createContext } from 'react';
|
|
17
14
|
import { AuthState, initialAuthState } from './auth-state';
|
|
15
|
+
import { AppState } from './auth0-provider';
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* settings.
|
|
25
|
-
*/
|
|
26
|
-
redirectUri?: string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Used to store state before doing the redirect
|
|
30
|
-
*/
|
|
31
|
-
appState?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Used to add to the URL fragment before redirecting
|
|
35
|
-
*/
|
|
36
|
-
fragment?: string;
|
|
37
|
-
}
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
18
|
+
export interface LogoutOptions extends Omit<SPALogoutOptions, 'onRedirect'> {}
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
20
|
+
export interface RedirectLoginOptions<TAppState = AppState>
|
|
21
|
+
extends Omit<SPARedirectLoginOptions<TAppState>, 'onRedirect'> {}
|
|
38
22
|
|
|
39
23
|
/**
|
|
40
24
|
* Contains the authenticated state and authentication methods provided by the `useAuth0` hook.
|
|
@@ -66,9 +50,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
66
50
|
* the `auth0` cookie.
|
|
67
51
|
*/
|
|
68
52
|
getAccessTokenSilently: {
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
>;
|
|
53
|
+
(
|
|
54
|
+
options: GetTokenSilentlyOptions & { detailedResponse: true }
|
|
55
|
+
): Promise<GetTokenSilentlyVerboseResponse>;
|
|
72
56
|
(options?: GetTokenSilentlyOptions): Promise<string>;
|
|
73
57
|
(options: GetTokenSilentlyOptions): Promise<
|
|
74
58
|
GetTokenSilentlyVerboseResponse | string
|
|
@@ -90,7 +74,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
90
74
|
getAccessTokenWithPopup: (
|
|
91
75
|
options?: GetTokenWithPopupOptions,
|
|
92
76
|
config?: PopupConfigOptions
|
|
93
|
-
) => Promise<string>;
|
|
77
|
+
) => Promise<string | undefined>;
|
|
94
78
|
|
|
95
79
|
/**
|
|
96
80
|
* ```js
|
|
@@ -99,9 +83,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
99
83
|
*
|
|
100
84
|
* Returns all claims from the id_token if available.
|
|
101
85
|
*/
|
|
102
|
-
getIdTokenClaims: (
|
|
103
|
-
options?: GetIdTokenClaimsOptions
|
|
104
|
-
) => Promise<IdToken | undefined>;
|
|
86
|
+
getIdTokenClaims: () => Promise<IdToken | undefined>;
|
|
105
87
|
|
|
106
88
|
/**
|
|
107
89
|
* ```js
|
|
@@ -112,7 +94,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
112
94
|
* provided as arguments. Random and secure `state` and `nonce`
|
|
113
95
|
* parameters will be auto-generated.
|
|
114
96
|
*/
|
|
115
|
-
loginWithRedirect: (
|
|
97
|
+
loginWithRedirect: (
|
|
98
|
+
options?: RedirectLoginOptions<AppState>
|
|
99
|
+
) => Promise<void>;
|
|
116
100
|
|
|
117
101
|
/**
|
|
118
102
|
* ```js
|
|
@@ -140,35 +124,11 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
140
124
|
*
|
|
141
125
|
* Clears the application session and performs a redirect to `/v2/logout`, using
|
|
142
126
|
* the parameters provided as arguments, to clear the Auth0 session.
|
|
143
|
-
* If the `federated` option is specified, it also clears the Identity Provider session.
|
|
144
|
-
* If the `localOnly` option is specified, it only clears the application session.
|
|
145
|
-
* It is invalid to set both the `federated` and `localOnly` options to `true`,
|
|
146
|
-
* and an error will be thrown if you do.
|
|
127
|
+
* If the `logoutParams.federated` option is specified, it also clears the Identity Provider session.
|
|
147
128
|
* [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
|
|
148
129
|
*/
|
|
149
130
|
logout: (options?: LogoutOptions) => void;
|
|
150
131
|
|
|
151
|
-
/**
|
|
152
|
-
* ```js
|
|
153
|
-
* const authUrl = await buildAuthorizeUrl();
|
|
154
|
-
* ```
|
|
155
|
-
*
|
|
156
|
-
* Builds an `/authorize` URL for loginWithRedirect using the parameters
|
|
157
|
-
* provided as arguments. Random and secure `state` and `nonce`
|
|
158
|
-
* parameters will be auto-generated.
|
|
159
|
-
*/
|
|
160
|
-
buildAuthorizeUrl: (options?: Auth0RedirectLoginOptions) => Promise<string>;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* ```js
|
|
164
|
-
* const logoutUrl = buildLogoutUrl();
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* returns a URL to the logout endpoint using the parameters provided as arguments.
|
|
168
|
-
* @param options
|
|
169
|
-
*/
|
|
170
|
-
buildLogoutUrl: (options?: LogoutUrlOptions) => string;
|
|
171
|
-
|
|
172
132
|
/**
|
|
173
133
|
* After the browser redirects back to the callback page,
|
|
174
134
|
* call `handleRedirectCallback` to handle success and error
|
|
@@ -190,7 +150,7 @@ const stub = (): never => {
|
|
|
190
150
|
/**
|
|
191
151
|
* @ignore
|
|
192
152
|
*/
|
|
193
|
-
const initialContext = {
|
|
153
|
+
export const initialContext = {
|
|
194
154
|
...initialAuthState,
|
|
195
155
|
buildAuthorizeUrl: stub,
|
|
196
156
|
buildLogoutUrl: stub,
|
package/src/auth0-provider.tsx
CHANGED
|
@@ -9,19 +9,18 @@ import React, {
|
|
|
9
9
|
import {
|
|
10
10
|
Auth0Client,
|
|
11
11
|
Auth0ClientOptions,
|
|
12
|
-
CacheLocation,
|
|
13
|
-
LogoutOptions,
|
|
14
|
-
LogoutUrlOptions,
|
|
15
12
|
PopupLoginOptions,
|
|
16
13
|
PopupConfigOptions,
|
|
17
|
-
RedirectLoginOptions as Auth0RedirectLoginOptions,
|
|
18
14
|
GetTokenWithPopupOptions,
|
|
19
15
|
RedirectLoginResult,
|
|
20
|
-
ICache,
|
|
21
16
|
GetTokenSilentlyOptions,
|
|
22
17
|
User,
|
|
23
18
|
} from '@auth0/auth0-spa-js';
|
|
24
|
-
import Auth0Context, {
|
|
19
|
+
import Auth0Context, {
|
|
20
|
+
Auth0ContextInterface,
|
|
21
|
+
LogoutOptions,
|
|
22
|
+
RedirectLoginOptions,
|
|
23
|
+
} from './auth0-context';
|
|
25
24
|
import { hasAuthParams, loginError, tokenError } from './utils';
|
|
26
25
|
import { reducer } from './reducer';
|
|
27
26
|
import { initialAuthState } from './auth-state';
|
|
@@ -37,7 +36,7 @@ export type AppState = {
|
|
|
37
36
|
/**
|
|
38
37
|
* The main configuration to instantiate the `Auth0Provider`.
|
|
39
38
|
*/
|
|
40
|
-
export interface Auth0ProviderOptions {
|
|
39
|
+
export interface Auth0ProviderOptions extends Auth0ClientOptions {
|
|
41
40
|
/**
|
|
42
41
|
* The child nodes your Provider has wrapped
|
|
43
42
|
*/
|
|
@@ -63,108 +62,23 @@ export interface Auth0ProviderOptions {
|
|
|
63
62
|
*/
|
|
64
63
|
skipRedirectCallback?: boolean;
|
|
65
64
|
/**
|
|
66
|
-
*
|
|
67
|
-
* `'example.eu.auth0.com'` or , `'example.mycompany.com'`
|
|
68
|
-
* (when using [custom domains](https://auth0.com/docs/custom-domains))
|
|
69
|
-
*/
|
|
70
|
-
domain: string;
|
|
71
|
-
/**
|
|
72
|
-
* The issuer to be used for validation of JWTs, optionally defaults to the domain above
|
|
73
|
-
*/
|
|
74
|
-
issuer?: string;
|
|
75
|
-
/**
|
|
76
|
-
* The Client ID found on your Application settings page
|
|
77
|
-
*/
|
|
78
|
-
clientId: string;
|
|
79
|
-
/**
|
|
80
|
-
* The default URL where Auth0 will redirect your browser to with
|
|
81
|
-
* the authentication result. It must be whitelisted in
|
|
82
|
-
* the "Allowed Callback URLs" field in your Auth0 Application's
|
|
83
|
-
* settings. If not provided here, it should be provided in the other
|
|
84
|
-
* methods that provide authentication.
|
|
85
|
-
*/
|
|
86
|
-
redirectUri?: string;
|
|
87
|
-
/**
|
|
88
|
-
* The value in seconds used to account for clock skew in JWT expirations.
|
|
89
|
-
* Typically, this value is no more than a minute or two at maximum.
|
|
90
|
-
* Defaults to 60s.
|
|
91
|
-
*/
|
|
92
|
-
leeway?: number;
|
|
93
|
-
/**
|
|
94
|
-
* The location to use when storing cache data. Valid values are `memory` or `localstorage`.
|
|
95
|
-
* The default setting is `memory`.
|
|
65
|
+
* Context to be used when creating the Auth0Provider, defaults to the internally created context.
|
|
96
66
|
*
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Specify a custom cache implementation to use for token storage and retrieval. This setting takes precedence over `cacheLocation` if they are both specified.
|
|
67
|
+
* This allows multiple Auth0Providers to be nested within the same application, the context value can then be
|
|
68
|
+
* passed to useAuth0, withAuth0, or withAuthenticationRequired to use that specific Auth0Provider to access
|
|
69
|
+
* auth state and methods specifically tied to the provider that the context belongs to.
|
|
102
70
|
*
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
cache?: ICache;
|
|
106
|
-
/**
|
|
107
|
-
* If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the legacy technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
|
|
108
|
-
* The default setting is `false`.
|
|
71
|
+
* When using multiple Auth0Providers in a single application you should do the following to ensure sessions are not
|
|
72
|
+
* overwritten:
|
|
109
73
|
*
|
|
110
|
-
*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* A maximum number of seconds to wait before declaring background calls to /authorize as failed for timeout
|
|
115
|
-
* Defaults to 60s.
|
|
116
|
-
*/
|
|
117
|
-
authorizeTimeoutInSeconds?: number;
|
|
118
|
-
/**
|
|
119
|
-
* Changes to recommended defaults, like defaultScope
|
|
120
|
-
*/
|
|
121
|
-
advancedOptions?: {
|
|
122
|
-
/**
|
|
123
|
-
* The default scope to be included with all requests.
|
|
124
|
-
* If not provided, 'openid profile email' is used. This can be set to `null` in order to effectively remove the default scopes.
|
|
125
|
-
*
|
|
126
|
-
* Note: The `openid` scope is **always applied** regardless of this setting.
|
|
127
|
-
*/
|
|
128
|
-
defaultScope?: string;
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Maximum allowable elapsed time (in seconds) since authentication.
|
|
132
|
-
* If the last time the user authenticated is greater than this value,
|
|
133
|
-
* the user must be reauthenticated.
|
|
134
|
-
*/
|
|
135
|
-
maxAge?: string | number;
|
|
136
|
-
/**
|
|
137
|
-
* The default scope to be used on authentication requests.
|
|
138
|
-
* The defaultScope defined in the Auth0Client is included
|
|
139
|
-
* along with this scope
|
|
140
|
-
*/
|
|
141
|
-
scope?: string;
|
|
142
|
-
/**
|
|
143
|
-
* The default audience to be used for requesting API access.
|
|
144
|
-
*/
|
|
145
|
-
audience?: string;
|
|
146
|
-
/**
|
|
147
|
-
* The Id of an organization to log in to.
|
|
74
|
+
* * Configure a different redirect_uri for each Auth0Provider, and set skipRedirectCallback for each provider to ignore
|
|
75
|
+
* the others redirect_uri
|
|
76
|
+
* * If using localstorage for both Auth0Providers, ensure that the audience and scope are different for so that the key
|
|
77
|
+
* used to store data is different
|
|
148
78
|
*
|
|
149
|
-
*
|
|
150
|
-
* the `org_id` claim in your user's ID Token.
|
|
151
|
-
*/
|
|
152
|
-
organization?: string;
|
|
153
|
-
/**
|
|
154
|
-
* The Id of an invitation to accept. This is available from the user invitation URL that is given when participating in a user invitation flow.
|
|
155
|
-
*/
|
|
156
|
-
invitation?: string;
|
|
157
|
-
/**
|
|
158
|
-
* The name of the connection configured for your application.
|
|
159
|
-
* If null, it will redirect to the Auth0 Login Page and show
|
|
160
|
-
* the Login Widget.
|
|
79
|
+
* For a sample on using multiple Auth0Providers review the [React Account Linking Sample](https://github.com/auth0-samples/auth0-link-accounts-sample/tree/react-variant)
|
|
161
80
|
*/
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* If you need to send custom parameters to the Authorization Server,
|
|
165
|
-
* make sure to use the original parameter name.
|
|
166
|
-
*/
|
|
167
|
-
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
|
+
context?: React.Context<Auth0ContextInterface>;
|
|
168
82
|
}
|
|
169
83
|
|
|
170
84
|
/**
|
|
@@ -179,12 +93,8 @@ declare const __VERSION__: string;
|
|
|
179
93
|
const toAuth0ClientOptions = (
|
|
180
94
|
opts: Auth0ProviderOptions
|
|
181
95
|
): Auth0ClientOptions => {
|
|
182
|
-
const { clientId, redirectUri, maxAge, ...validOpts } = opts;
|
|
183
96
|
return {
|
|
184
|
-
...
|
|
185
|
-
client_id: clientId,
|
|
186
|
-
redirect_uri: redirectUri,
|
|
187
|
-
max_age: maxAge,
|
|
97
|
+
...opts,
|
|
188
98
|
auth0Client: {
|
|
189
99
|
name: 'auth0-react',
|
|
190
100
|
version: __VERSION__,
|
|
@@ -192,22 +102,6 @@ const toAuth0ClientOptions = (
|
|
|
192
102
|
};
|
|
193
103
|
};
|
|
194
104
|
|
|
195
|
-
/**
|
|
196
|
-
* @ignore
|
|
197
|
-
*/
|
|
198
|
-
const toAuth0LoginRedirectOptions = (
|
|
199
|
-
opts?: RedirectLoginOptions
|
|
200
|
-
): Auth0RedirectLoginOptions | undefined => {
|
|
201
|
-
if (!opts) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const { redirectUri, ...validOpts } = opts;
|
|
205
|
-
return {
|
|
206
|
-
...validOpts,
|
|
207
|
-
redirect_uri: redirectUri,
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
|
|
211
105
|
/**
|
|
212
106
|
* @ignore
|
|
213
107
|
*/
|
|
@@ -236,6 +130,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
236
130
|
children,
|
|
237
131
|
skipRedirectCallback,
|
|
238
132
|
onRedirectCallback = defaultOnRedirectCallback,
|
|
133
|
+
context = Auth0Context,
|
|
239
134
|
...clientOpts
|
|
240
135
|
} = opts;
|
|
241
136
|
const [client] = useState(
|
|
@@ -267,20 +162,9 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
267
162
|
})();
|
|
268
163
|
}, [client, onRedirectCallback, skipRedirectCallback]);
|
|
269
164
|
|
|
270
|
-
const buildAuthorizeUrl = useCallback(
|
|
271
|
-
(opts?: RedirectLoginOptions): Promise<string> =>
|
|
272
|
-
client.buildAuthorizeUrl(toAuth0LoginRedirectOptions(opts)),
|
|
273
|
-
[client]
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
const buildLogoutUrl = useCallback(
|
|
277
|
-
(opts?: LogoutUrlOptions): string => client.buildLogoutUrl(opts),
|
|
278
|
-
[client]
|
|
279
|
-
);
|
|
280
|
-
|
|
281
165
|
const loginWithRedirect = useCallback(
|
|
282
166
|
(opts?: RedirectLoginOptions): Promise<void> =>
|
|
283
|
-
client.loginWithRedirect(
|
|
167
|
+
client.loginWithRedirect(opts),
|
|
284
168
|
[client]
|
|
285
169
|
);
|
|
286
170
|
|
|
@@ -303,15 +187,11 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
303
187
|
);
|
|
304
188
|
|
|
305
189
|
const logout = useCallback(
|
|
306
|
-
(opts: LogoutOptions = {}): Promise<void>
|
|
307
|
-
|
|
308
|
-
if (opts.
|
|
309
|
-
if (maybePromise && typeof maybePromise.then === 'function') {
|
|
310
|
-
return maybePromise.then(() => dispatch({ type: 'LOGOUT' }));
|
|
311
|
-
}
|
|
190
|
+
async (opts: LogoutOptions = {}): Promise<void> => {
|
|
191
|
+
await client.logout(opts);
|
|
192
|
+
if (opts.openUrl || opts.openUrl === false) {
|
|
312
193
|
dispatch({ type: 'LOGOUT' });
|
|
313
194
|
}
|
|
314
|
-
return maybePromise;
|
|
315
195
|
},
|
|
316
196
|
[client]
|
|
317
197
|
);
|
|
@@ -339,7 +219,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
339
219
|
async (
|
|
340
220
|
opts?: GetTokenWithPopupOptions,
|
|
341
221
|
config?: PopupConfigOptions
|
|
342
|
-
): Promise<string> => {
|
|
222
|
+
): Promise<string | undefined> => {
|
|
343
223
|
let token;
|
|
344
224
|
try {
|
|
345
225
|
token = await client.getTokenWithPopup(opts, config);
|
|
@@ -357,7 +237,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
357
237
|
);
|
|
358
238
|
|
|
359
239
|
const getIdTokenClaims = useCallback(
|
|
360
|
-
(
|
|
240
|
+
() => client.getIdTokenClaims(),
|
|
361
241
|
[client]
|
|
362
242
|
);
|
|
363
243
|
|
|
@@ -380,8 +260,6 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
380
260
|
const contextValue = useMemo(() => {
|
|
381
261
|
return {
|
|
382
262
|
...state,
|
|
383
|
-
buildAuthorizeUrl,
|
|
384
|
-
buildLogoutUrl,
|
|
385
263
|
getAccessTokenSilently,
|
|
386
264
|
getAccessTokenWithPopup,
|
|
387
265
|
getIdTokenClaims,
|
|
@@ -392,8 +270,6 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
392
270
|
};
|
|
393
271
|
}, [
|
|
394
272
|
state,
|
|
395
|
-
buildAuthorizeUrl,
|
|
396
|
-
buildLogoutUrl,
|
|
397
273
|
getAccessTokenSilently,
|
|
398
274
|
getAccessTokenWithPopup,
|
|
399
275
|
getIdTokenClaims,
|
|
@@ -403,11 +279,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
403
279
|
handleRedirectCallback,
|
|
404
280
|
]);
|
|
405
281
|
|
|
406
|
-
return
|
|
407
|
-
<Auth0Context.Provider value={contextValue}>
|
|
408
|
-
{children}
|
|
409
|
-
</Auth0Context.Provider>
|
|
410
|
-
);
|
|
282
|
+
return <context.Provider value={contextValue}>{children}</context.Provider>;
|
|
411
283
|
};
|
|
412
284
|
|
|
413
285
|
export default Auth0Provider;
|
package/src/index.tsx
CHANGED
|
@@ -12,14 +12,15 @@ export {
|
|
|
12
12
|
export {
|
|
13
13
|
default as Auth0Context,
|
|
14
14
|
Auth0ContextInterface,
|
|
15
|
+
initialContext,
|
|
16
|
+
LogoutOptions,
|
|
15
17
|
RedirectLoginOptions,
|
|
16
18
|
} from './auth0-context';
|
|
17
19
|
export {
|
|
20
|
+
AuthorizationParams,
|
|
18
21
|
PopupLoginOptions,
|
|
19
22
|
PopupConfigOptions,
|
|
20
|
-
GetIdTokenClaimsOptions,
|
|
21
23
|
GetTokenWithPopupOptions,
|
|
22
|
-
LogoutOptions,
|
|
23
24
|
LogoutUrlOptions,
|
|
24
25
|
CacheLocation,
|
|
25
26
|
GetTokenSilentlyOptions,
|
package/src/reducer.tsx
CHANGED
|
@@ -35,7 +35,7 @@ export const reducer = (state: AuthState, action: Action): AuthState => {
|
|
|
35
35
|
};
|
|
36
36
|
case 'HANDLE_REDIRECT_COMPLETE':
|
|
37
37
|
case 'GET_ACCESS_TOKEN_COMPLETE':
|
|
38
|
-
if (state.user
|
|
38
|
+
if (state.user === action.user) {
|
|
39
39
|
return state;
|
|
40
40
|
}
|
|
41
41
|
return {
|