Merge branch 'feat/trigger-oauth-logout' into 'main'

Dashboard logout should trigger OAuth logout endpoint

See merge request stackspin/dashboard!32
This commit is contained in:
Maarten de Waard 2022-06-10 08:19:02 +00:00
commit f36023db68
4 changed files with 11 additions and 2 deletions

2
.env.example Normal file
View file

@ -0,0 +1,2 @@
REACT_APP_API_URL=http://127.0.0.1:5000/api/v1
REACT_APP_HYDRA_PUBLIC_URL=https://sso.init.stackspin.net

View file

@ -19,6 +19,8 @@ data:
KRATOS_PUBLIC_URL: {{ .Values.backend.kratos.publicUrl }} KRATOS_PUBLIC_URL: {{ .Values.backend.kratos.publicUrl }}
KRATOS_ADMIN_URL: {{ .Values.backend.kratos.adminUrl }} KRATOS_ADMIN_URL: {{ .Values.backend.kratos.adminUrl }}
HYDRA_PUBLIC_URL: {{ .Values.backend.oidc.baseUrl }} HYDRA_PUBLIC_URL: {{ .Values.backend.oidc.baseUrl }}
# React can only read this env variable if it's prepended with REACT_APP
REACT_APP_HYDRA_PUBLIC_URL: {{ .Values.backend.oidc.baseUrl }}
HYDRA_ADMIN_URL: {{ .Values.backend.hydra.adminUrl }} HYDRA_ADMIN_URL: {{ .Values.backend.hydra.adminUrl }}
LOGIN_PANEL_URL: {{ .Values.backend.loginPanelUrl }} LOGIN_PANEL_URL: {{ .Values.backend.loginPanelUrl }}
DATABASE_URL: {{ .Values.backend.databaseUrl }} DATABASE_URL: {{ .Values.backend.databaseUrl }}

View file

@ -1,2 +1,2 @@
export { isTouched } from './is-touched'; export * from './is-touched';
export { addParamsToLink } from './add-params-to-link'; export * from './add-params-to-link';

View file

@ -24,6 +24,8 @@ function filterNavigationByDashboardRole(isAdmin: boolean) {
return navigation.filter((item) => !item.requiresAdmin); return navigation.filter((item) => !item.requiresAdmin);
} }
const HYDRA_URL = process.env.REACT_APP_HYDRA_PUBLIC_URL;
// eslint-disable-next-line @typescript-eslint/no-empty-interface // eslint-disable-next-line @typescript-eslint/no-empty-interface
interface HeaderProps {} interface HeaderProps {}
@ -40,6 +42,8 @@ const Header: React.FC<HeaderProps> = () => {
const navigationItems = filterNavigationByDashboardRole(isAdmin); const navigationItems = filterNavigationByDashboardRole(isAdmin);
const signOutUrl = `${HYDRA_URL}/oauth2/sessions/logout`;
return ( return (
<> <>
<Disclosure as="nav" className="bg-white shadow relative z-10"> <Disclosure as="nav" className="bg-white shadow relative z-10">
@ -120,6 +124,7 @@ const Header: React.FC<HeaderProps> = () => {
{({ active }) => ( {({ active }) => (
<a <a
onClick={() => logOut()} onClick={() => logOut()}
href={signOutUrl}
className={classNames( className={classNames(
active ? 'bg-gray-100 cursor-pointer' : '', active ? 'bg-gray-100 cursor-pointer' : '',
'block px-4 py-2 text-sm text-gray-700 cursor-pointer', 'block px-4 py-2 text-sm text-gray-700 cursor-pointer',