Skip to content

Commit 94d4730

Browse files
committed
Dashboard integration with keyclok
- New dependency added @react-keycloak/web and keycloak-js - Checks the SSO session by wrapping the entire App inside KeycloakProvider. - Removed the current use of login and registration related components. PBENCH-1073
1 parent b3a052c commit 94d4730

File tree

19 files changed

+110
-1027
lines changed

19 files changed

+110
-1027
lines changed

dashboard/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@patternfly/patternfly": "^4.183.1",
1010
"@patternfly/react-core": "^4.198.19",
1111
"@patternfly/react-table": "^4.75.2",
12+
"@react-keycloak/web": "^3.4.0",
1213
"@testing-library/jest-dom": "^5.16.2",
1314
"@testing-library/react": "^12.1.4",
1415
"@testing-library/user-event": "^13.5.0",
@@ -21,6 +22,7 @@
2122
"gulp": "^4.0.2",
2223
"jest": "^27.5.1",
2324
"js-cookie": "^3.0.1",
25+
"keycloak-js": "^21.0.1",
2426
"less-watch-compiler": "^1.16.3",
2527
"patternfly": "^3.9.0",
2628
"react": "^17.0.2",

dashboard/src/App.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@ import { AuthForm } from "modules/components/AuthComponent/common-components";
1616
import AuthLayout from "modules/containers/AuthLayout";
1717
import ComingSoonPage from "modules/components/EmptyPageComponent/ComingSoon";
1818
import Cookies from "js-cookie";
19-
import LoginForm from "modules/components/AuthComponent/LoginForm";
2019
import MainLayout from "modules/containers/MainLayout";
2120
import NoMatchingPage from "modules/components/EmptyPageComponent/NoMatchingPage";
2221
import OverviewComponent from "modules/components/OverviewComponent";
2322
import ProfileComponent from "modules/components/ProfileComponent";
24-
import SignupForm from "modules/components/AuthComponent/SignupForm";
2523
import TableOfContent from "modules/components/TableOfContent";
2624
import TableWithFavorite from "modules/components/TableComponent";
2725
import favicon from "./assets/logo/favicon.ico";
2826
import { fetchEndpoints } from "./actions/endpointAction";
29-
import { getUserDetails } from "actions/authActions";
3027
import { showToast } from "actions/toastActions";
31-
import { useDispatch } from "react-redux";
28+
import { useDispatch, useSelector } from "react-redux";
29+
import { ReactKeycloakProvider } from '@react-keycloak/web';
3230

33-
const ProtectedRoute = ({ redirectPath = APP_ROUTES.AUTH_LOGIN, children }) => {
31+
const eventLogger = (event, error) => {
32+
// We might want to consider to refresh the tokens here
33+
// if the event === 'onTokenExpired'
34+
};
35+
36+
const tokenLogger = (tokens) => {
37+
// Placeholder for to perform action when new token is generated
38+
// console.log('onKeycloakTokens', tokens["refreshToken"]);
39+
};
40+
41+
const ProtectedRoute = ({ redirectPath = APP_ROUTES.AUTH, children }) => {
3442
const loggedIn = Cookies.get("isLoggedIn");
3543
const dispatch = useDispatch();
3644

@@ -47,25 +55,36 @@ const HomeRoute = ({ redirectPath = APP_ROUTES.HOME }) => {
4755

4856
const App = () => {
4957
const dispatch = useDispatch();
58+
const { keycloak } = useSelector(
59+
state => state.apiEndpoint
60+
);
5061

5162
useEffect(() => {
5263
const faviconLogo = document.getElementById("favicon");
5364
faviconLogo?.setAttribute("href", favicon);
5465

5566
dispatch(fetchEndpoints);
56-
dispatch(getUserDetails());
5767
}, [dispatch]);
5868

5969
return (
6070
<div className="App">
71+
{ keycloak && (
72+
<ReactKeycloakProvider
73+
authClient={keycloak}
74+
onEvent={eventLogger}
75+
onTokens={tokenLogger}
76+
initOptions={{
77+
onLoad:'check-sso',
78+
checkLoginIframe: true,
79+
enableLogging: true
80+
}}
81+
>
6182
<BrowserRouter>
6283
<Routes>
6384
<Route path="/" element={<HomeRoute />}></Route>
6485
<Route path={"/" + APP_ROUTES.HOME}>
6586
<Route element={<AuthLayout />}>
66-
<Route path={APP_ROUTES.AUTH_LOGIN} element={<LoginForm />} />
6787
<Route path={APP_ROUTES.AUTH} element={<AuthForm />} />
68-
<Route path={APP_ROUTES.AUTH_SIGNUP} element={<SignupForm />} />
6988
</Route>
7089
<Route element={<MainLayout />}>
7190
<Route index element={<TableWithFavorite />} />
@@ -97,6 +116,8 @@ const App = () => {
97116
</Route>
98117
</Routes>
99118
</BrowserRouter>
119+
</ReactKeycloakProvider>
120+
)}
100121
</div>
101122
);
102123
};

0 commit comments

Comments
 (0)