generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement keycloak protection for /admin endpoints
- Loading branch information
1 parent
ef4325f
commit af1b4c7
Showing
9 changed files
with
152 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Response, Request } from 'express'; | ||
|
||
const getBlah = async (req: Request, res: Response) => { | ||
res.status(200).send('Blah blah blah'); | ||
}; | ||
|
||
export default getBlah; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from 'express'; | ||
import getBlah from '../controllers/admin-controller'; | ||
|
||
const router = express.Router(); | ||
|
||
router.route('/foo').get(getBlah); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as healthRouter } from './health-router'; | ||
export { default as developersRouter } from './developers-route'; | ||
export { default as adminRouter } from './admin-router'; |
34 changes: 34 additions & 0 deletions
34
frontend/src/components/common/DialogModal/DialogModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable react/button-has-type */ | ||
// This is copy-pasted from RefreshExpiryDialog in citz-imb-sso-react | ||
|
||
import { Dispatch, SetStateAction } from 'react'; | ||
|
||
type DialogModalProps = { | ||
text: string; | ||
isVisible: boolean; | ||
setIsVisible: Dispatch<SetStateAction<boolean>>; | ||
}; | ||
|
||
export default function DialogModal({ text, isVisible, setIsVisible }: DialogModalProps) { | ||
if (!isVisible) return null; | ||
|
||
return ( | ||
<> | ||
<div className="ssor_dialog-overlay" /> | ||
<dialog | ||
className="ssor_dialog" | ||
open={isVisible} | ||
> | ||
<div className="ssor_dialog-content"> | ||
<p className="ssor_dialog-message">{text}</p> | ||
<button | ||
className="ssor_button" | ||
onClick={() => setIsVisible(false)} | ||
> | ||
Ok | ||
</button> | ||
</div> | ||
</dialog> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useSSO } from '@bcgov/citz-imb-sso-react'; | ||
import { ReactNode } from 'react'; | ||
import { Navigate } from 'react-router-dom'; | ||
|
||
type ProtectedRouteProps = { | ||
requiredRole: string; | ||
children: ReactNode; | ||
}; | ||
|
||
export default function ProtectedRoute({ requiredRole, children }: ProtectedRouteProps) { | ||
const { hasRoles } = useSSO(); | ||
|
||
if (!hasRoles([requiredRole])) { | ||
return ( | ||
<Navigate | ||
to="/" | ||
replace | ||
state={{ text: 'Sorry, only authorized users can access that page.' }} | ||
/> | ||
); | ||
} | ||
return children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters