Skip to content

Commit

Permalink
Enable OIDC redirect in dashboard (#3233)
Browse files Browse the repository at this point in the history
Enable OIDC redirect in the dashboard

PBENCH-1072
  • Loading branch information
npalaska committed Mar 31, 2023
1 parent 0c92e77 commit 06b0718
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
38 changes: 38 additions & 0 deletions dashboard/src/actions/authActions.js
Expand Up @@ -8,6 +8,44 @@ import { SUCCESS } from "assets/constants/overviewConstants";
import { showToast } from "actions/toastActions";
import { uid } from "../utils/helper";


// Create an Authentication Request
export const authenticationRequest = () => async (dispatch, getState) => {
try {
const endpoints = getState().apiEndpoint.endpoints;
const oidcServer = endpoints.openid.server;
const oidcRealm = endpoints.openid.realm;
const oidcClient = endpoints.openid.client;
// URI parameters ref: https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
// Refer Step 3 of pbench/docs/user_authentication/third_party_token_management.md
const uri = `${oidcServer}/realms/${oidcRealm}/protocol/openid-connect/auth`;
const queryParams = [
'client_id=' + oidcClient,
'response_type=code',
'redirect_uri=' + window.location.href.split('?')[0],
'scope=profile',
'prompt=login',
'max_age=120'
];
window.location.href = uri + '?' + queryParams.join('&');
} catch (error) {
const alerts = getState().userAuth.alerts;
dispatch(error?.response
? toggleLoginBtn(true)
: { type: TYPES.OPENID_ERROR }
);
const alert = {
title: error?.response ? error.response.data?.message : error?.message,
key: uid(),
};
dispatch({
type: TYPES.USER_NOTION_ALERTS,
payload: [...alerts, alert],
});
dispatch({ type: TYPES.COMPLETED });
}
};

export const makeLoginRequest =
(details, navigate) => async (dispatch, getState) => {
try {
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/actions/types.js
Expand Up @@ -10,6 +10,7 @@ export const SHOW_FAILURE_TOAST = "SHOW_FAILURE_TOAST";
export const LOADING = "LOADING";
export const COMPLETED = "COMPLETED";
export const NETWORK_ERROR = "NETWORK_ERROR";
export const OPENID_ERROR = "OPENID_ERROR";
export const DASHBOARD_LOADING = "DASHBOARD_LOADING";

/* USER AUTHENTICATION */
Expand Down
Expand Up @@ -18,7 +18,7 @@ import {
import { CheckIcon, CloseIcon, TimesIcon } from "@patternfly/react-icons";
import { useDispatch, useSelector } from "react-redux";
import { useNavigate, useOutletContext } from "react-router-dom";

import { authenticationRequest } from "actions/authActions";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import PBenchLogo from "assets/logo/pbench_logo.svg";
import React from "react";
Expand Down Expand Up @@ -117,9 +117,12 @@ export const AuthForm = () => {
<CardFooter>
<div className="log-in-alternate">Or log in with...</div>
<div className="alternate-btn-wrapper">
<Button variant="secondary">Red Hat SSO</Button>
<Button variant="secondary">GitHub</Button>
<Button variant="secondary">Gmail</Button>
<Button
variant="primary"
onClick={() => {dispatch(authenticationRequest())}}
>
Pbench OpenId
</Button>
</div>
<NoLoginComponent />
</CardFooter>
Expand Down
1 change: 1 addition & 0 deletions docs/user_authentication/third_party_token_management.md
Expand Up @@ -37,6 +37,7 @@ abox over Browser:Identity broker instructs the browser to \nload identity provi
deactivate Browser
Browser->Identity-Provider:GET identity provider auth page
note over Browser:Ref: https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
note right of Browser:GET request:\n<identity_provider_auth_URI>\n?client_id=<client_id as registered on identity provider>\n&response_type=code\n&redirect_uri=<identity_broker_URI>\n&scope=openid
Identity-Provider->Browser:303 Response\n(Redirect to identity provider auth page)
Expand Down

0 comments on commit 06b0718

Please sign in to comment.