Skip to content

Commit

Permalink
Load auth options from API
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Nov 30, 2023
1 parent aec0635 commit 7fb1d3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 3 additions & 12 deletions src/GeoCop.Frontend/public/client-settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"oauth": {
"auth": {
"clientId": "ac09549e-6cf8-40fe-91a9-25515ec71954",
"authority": "https://login.microsoftonline.com/16e916d3-12c9-4353-ad04-5a4319422e03/",
"redirectUri": "/",
"postLogoutRedirectUri": "/",
"navigateToLoginRequestUrl": false
},
"cache": {
"cacheLocation": "localStorage",
"storeAuthStateInCookie": false
}
"authCache": {
"cacheLocation": "localStorage",
"storeAuthStateInCookie": false
},
"authScopes": ["user.read", "openid", "profile", "email"],
"application": {
Expand Down
16 changes: 13 additions & 3 deletions src/GeoCop.Frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const App = () => {
const [showModalContent, setShowModalContent] = useState(false);
const [showBannerContent, setShowBannerContent] = useState(false);
const [clientSettings, setClientSettings] = useState({});
const [auth, setAuth] = useState(undefined);
const [backendVersion, setBackendVersion] = useState("");
const [datenschutzContent, setDatenschutzContent] = useState(null);
const [impressumContent, setImpressumContent] = useState(null);
Expand All @@ -44,6 +45,12 @@ export const App = () => {
.then(setClientSettings);
}, []);

useEffect(() => {
fetch("/api/v1/user/auth")
.then((res) => res.headers.get("content-type")?.includes("application/json") && res.json())
.then(setAuth);
}, []);

useEffect(() => {
fetch("api/v1/version")
.then((res) => res.headers.get("content-type")?.includes("text/plain") && res.text())
Expand Down Expand Up @@ -88,10 +95,13 @@ export const App = () => {
const openModalContent = (content, type) =>
setModalContent(content) & setModalContentType(type) & setShowModalContent(true);

const oauth = clientSettings?.oauth;
const authCache = clientSettings?.authCache;
const msalInstance = useMemo(() => {
return new PublicClientApplication(oauth ?? {});
}, [oauth]);
return new PublicClientApplication({
auth,
cache: authCache,
});
}, [auth, authCache]);

return (
<MsalProvider instance={msalInstance}>
Expand Down

0 comments on commit 7fb1d3d

Please sign in to comment.