@axa-fr/react-oidc 6.9.7 → 6.10.1

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.
Files changed (146) hide show
  1. package/README.md +102 -102
  2. package/dist/FetchToken.d.ts.map +1 -1
  3. package/dist/FetchToken.js +2 -2
  4. package/dist/FetchToken.js.map +1 -1
  5. package/dist/OidcProvider.d.ts +7 -6
  6. package/dist/OidcProvider.d.ts.map +1 -1
  7. package/dist/OidcProvider.js +30 -26
  8. package/dist/OidcProvider.js.map +1 -1
  9. package/dist/OidcSecure.d.ts +2 -2
  10. package/dist/OidcSecure.d.ts.map +1 -1
  11. package/dist/OidcSecure.js +2 -4
  12. package/dist/OidcSecure.js.map +1 -1
  13. package/dist/OidcServiceWorker.js +150 -144
  14. package/dist/OidcTrustedDomains.js +9 -10
  15. package/dist/ReactOidc.d.ts +1 -1
  16. package/dist/ReactOidc.d.ts.map +1 -1
  17. package/dist/ReactOidc.js +22 -16
  18. package/dist/ReactOidc.js.map +1 -1
  19. package/dist/User.d.ts.map +1 -1
  20. package/dist/User.js +1 -1
  21. package/dist/User.js.map +1 -1
  22. package/dist/core/default-component/AuthenticateError.component.d.ts +1 -1
  23. package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
  24. package/dist/core/default-component/Authenticating.component.d.ts +1 -1
  25. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  26. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  27. package/dist/core/default-component/Callback.component.js +5 -5
  28. package/dist/core/default-component/Callback.component.js.map +1 -1
  29. package/dist/core/default-component/Loading.component.d.ts +1 -1
  30. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  31. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts +1 -1
  32. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  33. package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
  34. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  35. package/dist/core/default-component/SilentCallback.component.js +1 -0
  36. package/dist/core/default-component/SilentCallback.component.js.map +1 -1
  37. package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
  38. package/dist/core/default-component/SilentLogin.component.js +5 -7
  39. package/dist/core/default-component/SilentLogin.component.js.map +1 -1
  40. package/dist/core/default-component/index.d.ts +2 -2
  41. package/dist/core/default-component/index.d.ts.map +1 -1
  42. package/dist/core/default-component/index.js +5 -5
  43. package/dist/core/default-component/index.js.map +1 -1
  44. package/dist/core/routes/OidcRoutes.d.ts +1 -1
  45. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  46. package/dist/core/routes/OidcRoutes.js +1 -1
  47. package/dist/core/routes/OidcRoutes.js.map +1 -1
  48. package/dist/core/routes/withRouter.d.ts.map +1 -1
  49. package/dist/core/routes/withRouter.js.map +1 -1
  50. package/dist/index.d.ts +7 -6
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +10 -10
  53. package/dist/index.js.map +1 -1
  54. package/dist/vanilla/checkSessionIFrame.d.ts.map +1 -1
  55. package/dist/vanilla/checkSessionIFrame.js +15 -15
  56. package/dist/vanilla/checkSessionIFrame.js.map +1 -1
  57. package/dist/vanilla/initSession.d.ts.map +1 -1
  58. package/dist/vanilla/initSession.js +1 -1
  59. package/dist/vanilla/initSession.js.map +1 -1
  60. package/dist/vanilla/initWorker.d.ts +1 -1
  61. package/dist/vanilla/initWorker.d.ts.map +1 -1
  62. package/dist/vanilla/initWorker.js +22 -20
  63. package/dist/vanilla/initWorker.js.map +1 -1
  64. package/dist/vanilla/memoryStorageBackend.d.ts +5 -4
  65. package/dist/vanilla/memoryStorageBackend.d.ts.map +1 -1
  66. package/dist/vanilla/memoryStorageBackend.js.map +1 -1
  67. package/dist/vanilla/noHashQueryStringUtils.d.ts +3 -3
  68. package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -1
  69. package/dist/vanilla/noHashQueryStringUtils.js +4 -4
  70. package/dist/vanilla/noHashQueryStringUtils.js.map +1 -1
  71. package/dist/vanilla/oidc.d.ts +6 -6
  72. package/dist/vanilla/oidc.d.ts.map +1 -1
  73. package/dist/vanilla/oidc.js +215 -216
  74. package/dist/vanilla/oidc.js.map +1 -1
  75. package/dist/vanilla/parseTokens.d.ts +2 -2
  76. package/dist/vanilla/parseTokens.d.ts.map +1 -1
  77. package/dist/vanilla/parseTokens.js +8 -8
  78. package/dist/vanilla/parseTokens.js.map +1 -1
  79. package/dist/vanilla/route-utils.d.ts.map +1 -1
  80. package/dist/vanilla/route-utils.js +10 -7
  81. package/dist/vanilla/route-utils.js.map +1 -1
  82. package/dist/vanilla/timer.d.ts.map +1 -1
  83. package/dist/vanilla/timer.js +8 -8
  84. package/dist/vanilla/timer.js.map +1 -1
  85. package/dist/vanilla/vanillaOidc.d.ts +6 -4
  86. package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
  87. package/dist/vanilla/vanillaOidc.js +4 -5
  88. package/dist/vanilla/vanillaOidc.js.map +1 -1
  89. package/package.json +15 -6
  90. package/src/oidc/FetchToken.tsx +10 -11
  91. package/src/oidc/OidcProvider.tsx +82 -83
  92. package/src/oidc/OidcSecure.tsx +16 -18
  93. package/src/oidc/ReactOidc.tsx +74 -63
  94. package/src/oidc/User.ts +14 -13
  95. package/src/oidc/core/default-component/AuthenticateError.component.tsx +1 -1
  96. package/src/oidc/core/default-component/Authenticating.component.tsx +1 -1
  97. package/src/oidc/core/default-component/Callback.component.tsx +18 -18
  98. package/src/oidc/core/default-component/Loading.component.tsx +1 -1
  99. package/src/oidc/core/default-component/ServiceWorkerNotSupported.component.tsx +1 -1
  100. package/src/oidc/core/default-component/SessionLost.component.tsx +1 -1
  101. package/src/oidc/core/default-component/SilentCallback.component.tsx +7 -6
  102. package/src/oidc/core/default-component/SilentLogin.component.tsx +16 -18
  103. package/src/oidc/core/default-component/index.ts +2 -2
  104. package/src/oidc/core/routes/OidcRoutes.tsx +16 -15
  105. package/src/oidc/core/routes/withRouter.tsx +2 -4
  106. package/src/oidc/index.ts +7 -6
  107. package/src/oidc/vanilla/OidcServiceWorker.js +150 -144
  108. package/src/oidc/vanilla/OidcTrustedDomains.js +9 -10
  109. package/src/oidc/vanilla/checkSessionIFrame.ts +24 -23
  110. package/src/oidc/vanilla/index.ts +2 -1
  111. package/src/oidc/vanilla/initSession.ts +36 -37
  112. package/src/oidc/vanilla/initWorker.ts +82 -83
  113. package/src/oidc/vanilla/memoryStorageBackend.ts +13 -6
  114. package/src/oidc/vanilla/noHashQueryStringUtils.ts +13 -13
  115. package/src/oidc/vanilla/oidc.ts +460 -467
  116. package/src/oidc/vanilla/parseTokens.ts +73 -79
  117. package/src/oidc/vanilla/route-utils.ts +18 -18
  118. package/src/oidc/vanilla/timer.ts +14 -16
  119. package/src/oidc/vanilla/vanillaOidc.ts +35 -19
  120. package/src/override/AuthenticateError.component.tsx +4 -3
  121. package/src/override/Authenticating.component.tsx +4 -3
  122. package/src/override/Callback.component.tsx +4 -3
  123. package/src/override/Loading.component.tsx +4 -6
  124. package/src/override/ServiceWorkerNotSupported.component.tsx +5 -5
  125. package/src/override/SessionLost.component.tsx +8 -7
  126. package/src/override/style.ts +12 -10
  127. package/dist/core/routes/index.d.ts +0 -3
  128. package/dist/core/routes/index.d.ts.map +0 -1
  129. package/dist/core/routes/index.js +0 -9
  130. package/dist/core/routes/index.js.map +0 -1
  131. package/dist/vanilla/index.d.ts +0 -2
  132. package/dist/vanilla/index.d.ts.map +0 -1
  133. package/dist/vanilla/index.js +0 -6
  134. package/dist/vanilla/index.js.map +0 -1
  135. package/src/App.css +0 -38
  136. package/src/App.specold.tsx +0 -46
  137. package/src/App.tsx +0 -103
  138. package/src/FetchUser.tsx +0 -53
  139. package/src/Home.tsx +0 -23
  140. package/src/MultiAuth.tsx +0 -129
  141. package/src/Profile.tsx +0 -81
  142. package/src/configurations.ts +0 -73
  143. package/src/index.css +0 -13
  144. package/src/index.tsx +0 -9
  145. package/src/logo.svg +0 -7
  146. package/src/setupTests.js +0 -5
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OidcRoutes = void 0;
7
- var OidcRoutes_1 = require("./OidcRoutes");
8
- Object.defineProperty(exports, "OidcRoutes", { enumerable: true, get: function () { return __importDefault(OidcRoutes_1).default; } });
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/oidc/core/routes/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAqD;AAA5C,yHAAA,OAAO,OAAc"}
@@ -1,2 +0,0 @@
1
- export { VanillaOidc } from './vanillaOidc';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oidc/vanilla/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VanillaOidc = void 0;
4
- var vanillaOidc_1 = require("./vanillaOidc");
5
- Object.defineProperty(exports, "VanillaOidc", { enumerable: true, get: function () { return vanillaOidc_1.VanillaOidc; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/vanilla/index.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
package/src/App.css DELETED
@@ -1,38 +0,0 @@
1
- .App {
2
- text-align: center;
3
- }
4
-
5
- .App-logo {
6
- height: 40vmin;
7
- pointer-events: none;
8
- }
9
-
10
- @media (prefers-reduced-motion: no-preference) {
11
- .App-logo {
12
- animation: App-logo-spin infinite 20s linear;
13
- }
14
- }
15
-
16
- .App-header {
17
- background-color: #282c34;
18
- min-height: 100vh;
19
- display: flex;
20
- flex-direction: column;
21
- align-items: center;
22
- justify-content: center;
23
- font-size: calc(10px + 2vmin);
24
- color: white;
25
- }
26
-
27
- .App-link {
28
- color: #61dafb;
29
- }
30
-
31
- @keyframes App-logo-spin {
32
- from {
33
- transform: rotate(0deg);
34
- }
35
- to {
36
- transform: rotate(360deg);
37
- }
38
- }
@@ -1,46 +0,0 @@
1
- // __tests__/fetch.test.js
2
- /*import React from 'react'
3
- import {rest} from 'msw'
4
- import {setupServer} from 'msw/node'
5
- import {render, fireEvent, waitFor, screen} from '@testing-library/react'
6
- import '@testing-library/jest-dom'
7
- import App from "./App";
8
- import {act} from "react-dom/test-utils";
9
-
10
- const server = setupServer(
11
- rest.get('http://api/.well-known/openid-configuration', (req, res, ctx) => {
12
- return res( ctx.status(200),ctx.json({
13
- "issuer":"https://demo.identityserver.io",
14
- "jwks_uri":"https://demo.identityserver.io/.well-known/openid-configuration/jwks",
15
- "authorization_endpoint":"https://demo.identityserver.io/connect/authorize",
16
- "token_endpoint":"https://demo.identityserver.io/connect/token",
17
- "userinfo_endpoint":"https://demo.identityserver.io/connect/userinfo",
18
- "end_session_endpoint":"https://demo.identityserver.io/connect/endsession",
19
- "check_session_iframe":"https://demo.identityserver.io/connect/checksession",
20
- "revocation_endpoint":"https://demo.identityserver.io/connect/revocation",
21
- "introspection_endpoint":"https://demo.identityserver.io/connect/introspect",
22
- "device_authorization_endpoint":"https://demo.identityserver.io/connect/deviceauthorization","frontchannel_logout_supported":true,"frontchannel_logout_session_supported":true,"backchannel_logout_supported":true,"backchannel_logout_session_supported":true,"scopes_supported":["openid","profile","email","api","api.scope1","api.scope2","scope2","policyserver.runtime","policyserver.management","offline_access"],"claims_supported":["sub","name","family_name","given_name","middle_name","nickname","preferred_username","profile","picture","website","gender","birthdate","zoneinfo","locale","updated_at","email","email_verified"],"grant_types_supported":["authorization_code","client_credentials","refresh_token","implicit","password","urn:ietf:params:oauth:grant-type:device_code"],"response_types_supported":["code","token","id_token","id_token token","code id_token","code token","code id_token token"],"response_modes_supported":["form_post","query","fragment"],"token_endpoint_auth_methods_supported":["client_secret_basic","client_secret_post"],"id_token_signing_alg_values_supported":["RS256"],"subject_types_supported":["public"],"code_challenge_methods_supported":["plain","S256"],"request_parameter_supported":true}))
23
- }),
24
- )
25
-
26
- beforeAll(() => server.listen())
27
- afterEach(() => server.resetHandlers())
28
- afterAll(() => server.close())
29
-
30
- test('Load home page then login should log', async () => {
31
-
32
- const configuration = {
33
- client_id: 'interactive.public.short',
34
- redirect_uri: 'http://localhost:4200/authentication/callback',
35
- scope: 'openid profile email api offline_access',
36
- authority: 'http://api',
37
- refresh_time_before_tokens_expiration_in_second: 70,
38
- };
39
- // @ts-ignore
40
- const {debug, getByText, rerender} = render(<App configuration={configuration}/>);
41
- await waitFor(() => getByText('React Demo Application protected by OpenId Connect'));
42
- fireEvent.click(screen.getByText('Login'));
43
- await waitFor(() => getByText('Authentification en cours'));
44
-
45
- })
46
- */
package/src/App.tsx DELETED
@@ -1,103 +0,0 @@
1
- import React, {useReducer} from 'react';
2
- import {BrowserRouter, Route, NavLink, Routes} from 'react-router-dom';
3
- import { Home } from "./Home";
4
- import { Profile, SecureProfile } from "./Profile";
5
- import { configurationAuth0, configurationIdentityServer, configurationIdentityServerWithoutDiscovery } from './configurations';
6
- import { withOidcSecure, OidcProvider } from "./oidc";
7
- import {FetchUserHoc, FetchUserHook} from "./FetchUser";
8
- import { MultiAuthContainer } from "./MultiAuth";
9
-
10
- const OidcSecureHoc = withOidcSecure(Profile);
11
-
12
-
13
- const getRandomInt = (max) => {
14
- return Math.floor(Math.random() * max);
15
- }
16
-
17
-
18
- function reducer(state, action) {
19
- switch (action.type) {
20
- case 'event':
21
- const id = getRandomInt(9999999999999).toString();
22
- return [{...action.data, id, date:Date.now()}, ...state]
23
- default:
24
- throw new Error();
25
- }
26
- }
27
-
28
- function App() {
29
- const [show, setShow] = React.useState(false);
30
- const [events, dispatch] = useReducer(reducer, []);
31
-
32
- const onEvent=(configurationName, eventName, data )=>{
33
- // console.log(`oidc:${configurationName}:${eventName}`, data);
34
- dispatch({type: 'event', data: {name: `oidc:${configurationName}:${eventName}`, data}})
35
- }
36
- return (<>
37
-
38
- <OidcProvider configuration={configurationIdentityServer} onEvent={onEvent}>
39
- <BrowserRouter>
40
- <nav className="navbar navbar-expand-lg navbar-dark bg-primary">
41
- <a className="navbar-brand" href="/">@axa-fr/react-oidc</a>
42
- <button className="navbar-toggler" type="button" onClick={() => setShow(!show)} data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
43
- <span className="navbar-toggler-icon"/>
44
- </button>
45
- <div style={show ? { display: "block" } : { display: 'none' }} className="collapse navbar-collapse" id="navbarNav">
46
- <ul className="navbar-nav">
47
- <li className="nav-item">
48
- <NavLink className="nav-link" to="/">Home</NavLink>
49
- </li>
50
- <li className="nav-item">
51
- <NavLink className="nav-link" to="/profile">Profile</NavLink>
52
- </li>
53
- <li className="nav-item">
54
- <NavLink className="nav-link" to="/profile-secure-component">Secure Profile Component</NavLink>
55
- </li>
56
- <li className="nav-item">
57
- <NavLink className="nav-link" to="/profile-secure-hoc">Secure Profile Hoc</NavLink>
58
- </li>
59
- <li className="nav-item">
60
- <NavLink className="nav-link" to="/user-fetch-secure-hoc">Secure User Fetch Hoc</NavLink>
61
- </li>
62
- <li className="nav-item">
63
- <NavLink className="nav-link" to="/user-fetch-secure-hook">Secure User Fetch Hook</NavLink>
64
- </li>
65
- <li className="nav-item">
66
- <NavLink className="nav-link" to="/multi-auth">Multi Auth</NavLink>
67
- </li>
68
- </ul>
69
- </div>
70
- </nav>
71
-
72
- <div>
73
- <Routes>
74
- <Route path="/" element={<Home></Home>} />
75
- <Route path="/profile" element={<Profile></Profile>} />
76
- <Route path="/profile-secure-component" element={<SecureProfile></SecureProfile>} />
77
- <Route path="/profile-secure-hoc" element={<OidcSecureHoc></OidcSecureHoc>} />
78
- <Route path="/user-fetch-secure-hoc" element={<FetchUserHoc></FetchUserHoc>} />
79
- <Route path="/user-fetch-secure-hook" element={<FetchUserHook></FetchUserHook>} />
80
- <Route path="/multi-auth/*" element={<MultiAuthContainer></MultiAuthContainer>} />
81
- </Routes>
82
- </div>
83
-
84
- </BrowserRouter>
85
- </OidcProvider>
86
- <div className="container-fluid mt-3">
87
- <div className="card">
88
- <div className="card-body" >
89
- <h5 className="card-title">Default configuration Events</h5>
90
- <div style={{"overflowX": "hidden", "overflowY": "scroll", "maxHeight": "400px"}}>
91
- {events.map(e => {
92
- const date = new Date(e.date);
93
- const dateFormated = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
94
- return <p key={e.id}>{dateFormated} {e.name}: { JSON.stringify(e.data)}</p>
95
- })}
96
- </div>
97
- </div>
98
- </div>
99
- </div></>
100
- );
101
- }
102
-
103
- export default App;
package/src/FetchUser.tsx DELETED
@@ -1,53 +0,0 @@
1
- import React, {useEffect, useState} from 'react';
2
-
3
- import {useOidcFetch, withOidcFetch} from "./oidc/FetchToken";
4
- import {OidcSecure} from "./oidc";
5
-
6
- const DisplayUserInfo = ({ fetch }) => {
7
- const [oidcUser, setOidcUser] = useState(null);
8
- const [isLoading, setLoading] = useState(true);
9
-
10
- useEffect(() => {
11
- const fetchUserInfoAsync = async () => {
12
- const res = await fetch("https://demo.duendesoftware.com/connect/userinfo");
13
- if (res.status != 200) {
14
- return null;
15
- }
16
- return res.json();
17
- };
18
- let isMounted = true;
19
- fetchUserInfoAsync().then((userInfo) => {
20
- if(isMounted) {
21
- setLoading(false);
22
- setOidcUser(userInfo)
23
- }
24
- })
25
- return () => {
26
- isMounted = false;
27
- };
28
- },[]);
29
-
30
- if(isLoading){
31
- return <>Loading</>;
32
- }
33
-
34
- return (
35
- <div className="container mt-3">
36
- <div className="card text-white bg-success mb-3">
37
- <div className="card-body">
38
- <h5 className="card-title">User information</h5>
39
- {oidcUser != null && <p className="card-text">{JSON.stringify(oidcUser)}</p>}
40
- </div>
41
- </div>
42
- </div>
43
- )
44
- };
45
-
46
- const UserInfoWithFetchHoc = withOidcFetch(fetch)(DisplayUserInfo);
47
-
48
- export const FetchUserHoc= () => <OidcSecure><UserInfoWithFetchHoc/></OidcSecure>;
49
-
50
- export const FetchUserHook= () => {
51
- const {fetch} = useOidcFetch();
52
- return <OidcSecure><DisplayUserInfo fetch={fetch} /></OidcSecure>
53
- }
package/src/Home.tsx DELETED
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import {useOidc} from "./oidc";
3
-
4
- export const Home = () => {
5
-
6
- const { login, logout, renewTokens, isAuthenticated} = useOidc();
7
-
8
- return (
9
- <div className="container-fluid mt-3">
10
- <div className="card">
11
- <div className="card-body">
12
- <h5 className="card-title">Home</h5>
13
- <p className="card-text">React Demo Application protected by OpenId Connect. More info on about oidc on <a href="https://github.com/AxaGuilDEv/react-oidc">GitHub @axa-fr/react-oidc</a></p>
14
- {!isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => login('/profile')}>Login</button></p>}
15
- {isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => logout('/profile')}>logout /profile</button></p>}
16
- {isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => logout()}>logout</button></p>}
17
- {isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => logout(null)}>logout whithout callbackredirect</button></p>}
18
- {isAuthenticated && <p><button type="button" className="btn btn-primary" onClick={() => renewTokens()}>renew tokens</button></p>}
19
- </div>
20
- </div>
21
- </div>
22
- )
23
- };
package/src/MultiAuth.tsx DELETED
@@ -1,129 +0,0 @@
1
- import React, {useState} from 'react';
2
- import {OidcProvider, useOidc, useOidcAccessToken, useOidcIdToken} from "./oidc";
3
- import { configurationIdentityServer, configurationIdentityServerWithHash, configurationGoogle} from "./configurations";
4
- import AuthenticatingError from "./override/AuthenticateError.component"
5
- import Authenticating from "./override/Authenticating.component"
6
- import Loading from "./override/Loading.component"
7
- import {CallBackSuccess} from "./override/Callback.component"
8
- import SessionLost from "./override/SessionLost.component"
9
- import ServiceWorkerNotSupported from "./override/ServiceWorkerNotSupported.component"
10
-
11
- const MultiAuth = ( {configurationName, handleConfigurationChange }) => {
12
- const { login, logout, isAuthenticated} = useOidc(configurationName);
13
- const { isAuthenticated: isAuthenticatedDefault} = useOidc("default");
14
- const [fname, setFname] = useState("")
15
-
16
- const handleChange = e => {
17
- setFname(e.target.value)
18
- }
19
- return (
20
- <div className="container-fluid mt-3">
21
- <div className="card">
22
- <div className="card-body">
23
- <h5 className="card-title">Multiple Authentication</h5>
24
- <form>
25
- <label>
26
- First Name:{" "}
27
- <input type="text" value={fname} onChange={handleChange} />
28
- </label>
29
- </form>
30
- <p className="card-text">React Demo Application protected by OpenId Connect with MultipleAuthentication.
31
- <br/>For example, config_1 can have other sensitive scope, config_2 does not ask for the "offline_access" so it does not retrieve the most sensitive token "refresh_token" for very sensitive operation, it retrive only access_token valid for a small amout of time.</p>
32
- <select value={configurationName} onChange={handleConfigurationChange} >
33
- <option value="config_classic">config_classic</option>
34
- <option value="config_without_refresh_token">config_without_refresh_token</option>
35
- <option value="config_without_silent_login">config_without_silent_login</option>
36
- <option value="config_without_refresh_token_silent_login">config_without_refresh_token_silent_login</option>
37
- <option value="config_google">google</option>
38
- <option value="config_with_hash">config_with_hash</option>
39
- </select>
40
- {!isAuthenticated && <button type="button" className="btn btn-primary" onClick={() => login()}>Login</button>}
41
- {!isAuthenticated && isAuthenticatedDefault && <button type="button" className="btn btn-primary" onClick={() => login(undefined, undefined, true)}>Silent Login</button>}
42
- {isAuthenticated && <button type="button" className="btn btn-primary" onClick={() => logout()}>logout</button>}
43
- </div>
44
- </div>
45
- </div>
46
- );
47
- };
48
-
49
- if(!sessionStorage.configurationName){
50
- sessionStorage.configurationName = "config_classic";
51
- }
52
-
53
- export const MultiAuthContainer = () => {
54
- const [isSessionLost, setIsSessionLost] = useState(false)
55
- const [configurationName, setConfigurationName] = useState(sessionStorage.configurationName);
56
- const callBack = window.location.origin+"/multi-auth/authentification/callback2";
57
- const silent_redirect_uri = window.location.origin+"/multi-auth/authentification/silent-callback2";
58
- const configurations = {
59
- config_classic: {...configurationIdentityServer,
60
- redirect_uri:callBack,
61
- silent_redirect_uri,
62
- scope: 'openid profile email api offline_access'
63
- },
64
- config_without_refresh_token: {...configurationIdentityServer,
65
- redirect_uri:callBack,
66
- silent_redirect_uri,
67
- scope: 'openid profile email api'
68
- },
69
- config_without_silent_login: {...configurationIdentityServer,
70
- redirect_uri:callBack,
71
- silent_redirect_uri: "",
72
- scope: 'openid profile email api offline_access'
73
- },
74
- config_without_refresh_token_silent_login: {...configurationIdentityServer,
75
- redirect_uri:callBack,
76
- silent_redirect_uri: "",
77
- scope: 'openid profile email api'},
78
- config_google: { ...configurationGoogle },
79
- config_with_hash: { ...configurationIdentityServerWithHash }
80
- }
81
- const handleConfigurationChange = (event) => {
82
- const configurationName = event.target.value;
83
- sessionStorage.configurationName = configurationName;
84
- setConfigurationName(configurationName);
85
- }
86
-
87
- const onSessionLost = ()=>{
88
- setIsSessionLost(true);
89
- }
90
-
91
- return (
92
- <>
93
- <OidcProvider configuration={configurations[configurationName]}
94
- configurationName={configurationName}
95
- loadingComponent={Loading}
96
- authenticatingErrorComponent={AuthenticatingError}
97
- authenticatingComponent={Authenticating}
98
- serviceWorkerNotSupportedComponent={ServiceWorkerNotSupported}
99
- callbackSuccessComponent={CallBackSuccess}
100
- onSessionLost={onSessionLost}
101
- >
102
- { isSessionLost && <SessionLost configurationName={configurationName}/>}
103
- <MultiAuth configurationName={configurationName} handleConfigurationChange={handleConfigurationChange} />
104
- <DisplayAccessToken configurationName={configurationName} />
105
- </OidcProvider>
106
- </>
107
- );
108
- };
109
-
110
- const DisplayAccessToken = ({configurationName}) => {
111
- const{ accessToken, accessTokenPayload } = useOidcAccessToken(configurationName);
112
- const{ idTokenPayload } = useOidcIdToken(configurationName);
113
-
114
- if(!accessToken){
115
- return <p>you are not authentified</p>
116
- }
117
- return (
118
- <div className="card text-white bg-info mb-3">
119
- <div className="card-body">
120
- <h5 className="card-title">Access Token</h5>
121
- <p style={{color:'red', "backgroundColor": 'white'}}>Please consider to configure the ServiceWorker in order to protect your application from XSRF attacks. "access_token" and "refresh_token" will never be accessible from your client side javascript.</p>
122
- {<p className="card-text">Access Token: {JSON.stringify(accessToken)}</p>}
123
- {accessTokenPayload != null && <p className="card-text">Access Token Payload: {JSON.stringify(accessTokenPayload)}</p>}
124
- <h5 className="card-title">Id Token</h5>
125
- {idTokenPayload != null && <p className="card-text">Access Token Payload: {JSON.stringify(idTokenPayload)}</p>}
126
- </div>
127
- </div>
128
- )
129
- };
package/src/Profile.tsx DELETED
@@ -1,81 +0,0 @@
1
- import React from 'react';
2
-
3
- import {OidcSecure, useOidcAccessToken, useOidcIdToken, useOidcUser, OidcUserStatus} from "./oidc";
4
- import { OidcUserInfo } from './oidc/User';
5
-
6
- interface OidcUserRoleInfo extends OidcUserInfo{
7
- role?: string[]
8
- }
9
-
10
- const DisplayUserInfo = () => {
11
- const{ oidcUser, oidcUserLoadingState } = useOidcUser<OidcUserRoleInfo>();
12
-
13
- switch (oidcUserLoadingState){
14
- case OidcUserStatus.Loading:
15
- return <p>User Information are loading</p>;
16
- case OidcUserStatus.Unauthenticated:
17
- return <p>you are not authenticated</p>;
18
- case OidcUserStatus.LoadingError:
19
- return <p>Fail to load user information</p>;
20
- default:
21
- return (
22
- <div className="card text-white bg-success mb-3">
23
- <div className="card-body">
24
- <h5 className="card-title">User information</h5>
25
- <p className="card-text">{JSON.stringify(oidcUser)}</p>
26
- </div>
27
- </div>
28
- );
29
- }
30
- };
31
-
32
- export const Profile = () => {
33
-
34
- return (
35
- <div className="container mt-3">
36
- <DisplayAccessToken/>
37
- <DisplayIdToken/>
38
- <DisplayUserInfo/>
39
- </div>
40
- );
41
- }
42
-
43
- const DisplayAccessToken = () => {
44
- const{ accessToken, accessTokenPayload } = useOidcAccessToken();
45
-
46
- if(!accessToken){
47
- return <p>you are not authenticated</p>
48
- }
49
- return (
50
- <div className="card text-white bg-info mb-3">
51
- <div className="card-body">
52
- <h5 className="card-title">Access Token</h5>
53
- <p style={{color:'red', "backgroundColor": 'white'}}>Please consider to configure the ServiceWorker in order to protect your application from XSRF attacks. "access_token" and "refresh_token" will never be accessible from your client side javascript.</p>
54
- {<p className="card-text">Access Token: {JSON.stringify(accessToken)}</p>}
55
- {accessTokenPayload != null && <p className="card-text">Access Token Payload: {JSON.stringify(accessTokenPayload)}</p>}
56
- </div>
57
- </div>
58
- )
59
- };
60
-
61
-
62
- const DisplayIdToken =() => {
63
- const{ idToken, idTokenPayload } = useOidcIdToken();
64
-
65
- if(!idToken){
66
- return <p>you are not authenticated</p>
67
- }
68
-
69
- return (
70
- <div className="card text-white bg-info mb-3">
71
- <div className="card-body">
72
- <h5 className="card-title">ID Token</h5>
73
- {<p className="card-text">IdToken: {JSON.stringify(idToken)}</p>}
74
- {idTokenPayload != null && <p className="card-text">IdToken Payload: {JSON.stringify(idTokenPayload)}</p>}
75
- </div>
76
- </div>
77
- );
78
- }
79
-
80
-
81
- export const SecureProfile = () => <OidcSecure><Profile /></OidcSecure>;
@@ -1,73 +0,0 @@
1
- import {TokenRenewMode} from "./oidc";
2
-
3
- export const configurationIdentityServer = {
4
- client_id: 'interactive.public.short',
5
- redirect_uri: window.location.origin + '/authentication/callback',
6
- silent_redirect_uri: window.location.origin + '/authentication/silent-callback',
7
- //silent_login_uri: window.location.origin+'/authentication/silent-login',
8
- scope: 'openid profile email api offline_access',
9
- authority: 'https://demo.duendesoftware.com',
10
- //authority_time_cache_wellknowurl_in_second: 60* 60,
11
- refresh_time_before_tokens_expiration_in_second: 40,
12
- service_worker_relative_url:'/OidcServiceWorker.js',
13
- service_worker_only: false,
14
- //storage: sessionStorage,
15
- //silent_login_timeout: 3333000
16
- //monitor_session: true,
17
- token_renew_mode : TokenRenewMode.access_token_invalid
18
- };
19
-
20
- export const configurationIdentityServerWithHash = {
21
- client_id: 'interactive.public.short',
22
- redirect_uri: window.location.origin+'/multi-auth/authentification#authentication-callback',
23
- silent_redirect_uri: window.location.origin+'/multi-auth/authentification#authentication-silent-callback',
24
- silent_login_uri: window.location.origin+'/multi-auth/authentification#authentication-silent-login',
25
- scope: 'openid profile email api offline_access',
26
- authority: 'https://demo.duendesoftware.com',
27
- refresh_time_before_tokens_expiration_in_second: 10,
28
- service_worker_relative_url:'/OidcServiceWorker.js',
29
- service_worker_only: false,
30
- };
31
-
32
- export const configurationIdentityServerWithoutDiscovery = {
33
- client_id: 'interactive.public.short',
34
- redirect_uri: window.location.origin+'/authentication/callback',
35
- silent_redirect_uri: window.location.origin+'/authentication/silent-callback',
36
- scope: 'openid profile email api offline_access',
37
- authority: 'https://demo.duendesoftware.com',
38
- authority_configuration: {
39
- authorization_endpoint: 'https://demo.duendesoftware.com/connect/authorize',
40
- token_endpoint: 'https://demo.duendesoftware.com/connect/token',
41
- userinfo_endpoint: 'https://demo.duendesoftware.com/connect/userinfo',
42
- end_session_endpoint: 'https://demo.duendesoftware.com/connect/endsession',
43
- revocation_endpoint: 'https://demo.duendesoftware.com/connect/revocation',
44
- check_session_iframe: 'https://demo.duendesoftware.com/connect/checksession'
45
- },
46
- refresh_time_before_tokens_expiration_in_second: 10,
47
- service_worker_relative_url:'/OidcServiceWorker.js',
48
- service_worker_only: false,
49
- };
50
-
51
- export const configurationAuth0 = {
52
- client_id: 'xGZxEAJhzlkuQUlWl90y1ntIX-0UDWHx',
53
- redirect_uri: window.location.origin+'/callback',
54
- scope: 'openid profile email api offline_access',
55
- authority: 'https://kdhttps.auth0.com',
56
- refresh_time_before_tokens_expiration_in_second: 10,
57
- service_worker_relative_url:'/OidcServiceWorker.js',
58
- service_worker_only: false,
59
- };
60
-
61
- export const configurationGoogle = {
62
- client_id: '908893276222-f2drloh56ll0g99md38lv2k810d0nk0p.apps.googleusercontent.com',
63
- redirect_uri: `${window.location.origin}/multi-auth/callback-google`,
64
- silent_redirect_uri: window.location.origin+'/multi-auth/silent-callback-google',
65
- scope: 'openid profile email',
66
- authority: 'https://accounts.google.com/',
67
- service_worker_relative_url:'/OidcServiceWorker.js',
68
- service_worker_only: false,
69
- token_request_extras: {
70
- client_secret : "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"
71
- },
72
- monitor_session: false,
73
- };
package/src/index.css DELETED
@@ -1,13 +0,0 @@
1
- body {
2
- margin: 0;
3
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
- sans-serif;
6
- -webkit-font-smoothing: antialiased;
7
- -moz-osx-font-smoothing: grayscale;
8
- }
9
-
10
- code {
11
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
- monospace;
13
- }
package/src/index.tsx DELETED
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import './index.css';
4
- import App from './App';
5
- import 'bootstrap/dist/css/bootstrap.min.css';
6
-
7
- const container = document.getElementById('root');
8
- const root = createRoot(container); // createRoot(container!) if you use TypeScript
9
- root.render(<React.StrictMode><App/></React.StrictMode>);
package/src/logo.svg DELETED
@@ -1,7 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
2
- <g fill="#61DAFB">
3
- <path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
4
- <circle cx="420.9" cy="296.5" r="45.7"/>
5
- <path d="M520.5 78.1z"/>
6
- </g>
7
- </svg>
package/src/setupTests.js DELETED
@@ -1,5 +0,0 @@
1
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
- // allows you to do things like:
3
- // expect(element).toHaveTextContent(/react/i)
4
- // learn more: https://github.com/testing-library/jest-dom
5
- import '@testing-library/jest-dom/extend-expect';