Updates across ui code on api calling and error handling

This commit is contained in:
Matthew Garrett 2022-06-01 15:54:25 -07:00
Родитель 10375827ef
Коммит e6a9ea5c36
16 изменённых файлов: 374 добавлений и 231 удалений

Просмотреть файл

@ -193,6 +193,16 @@ Function Deploy-IPAMApplications {
Value = "access_as_user"
}
)
# PreAuthorizedApplication = @(
# @{
# AppId = "1950a258-227b-4e31-a9cf-717495945fc2" # Azure PowerShell
# DelegatedPermissionId = @( $engineApiGuid )
# },
# @{
# AppId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46" # Azure CLI
# DelegatedPermissionId = @( $engineApiGuid )
# }
# )
RequestedAccessTokenVersion = 2
}

Просмотреть файл

@ -2,6 +2,7 @@ import * as React from "react";
import { styled } from '@mui/material/styles';
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError, InteractionStatus } from "@azure/msal-browser";
import { callMsGraphUsers } from "../../msal/graph";
import { useSnackbar } from 'notistack';
@ -43,15 +44,15 @@ import { apiRequest } from "../../msal/authConfig";
function CustomToolbar(props) {
const { admins, loadedAdmins, setAdmins, selectionModel, refresh } = props;
const { instance, accounts } = useMsal();
const { instance, inProgress, accounts } = useMsal();
const { enqueueSnackbar } = useSnackbar();
const [open, setOpen] = React.useState(false);
const [options, setOptions] = React.useState([]);
const [options, setOptions] = React.useState(null);
const [selected, setSelected] = React.useState(null);
const [sending, setSending] = React.useState(false);
const loading = open && options.length === 0;
const loading = open && !options
// const selectedAdmin = admins.find(obj => { return obj.id === selectionModel[0] });
const changed = isEqual(admins, loadedAdmins);
@ -59,25 +60,31 @@ function CustomToolbar(props) {
let active = true;
function SearchUsers() {
(async () => {
const request = {
scopes: ["Directory.Read.All"],
account: accounts[0],
};
const request = {
scopes: ["Directory.Read.All"],
account: accounts[0],
};
try {
const response = await instance.acquireTokenSilent(request);
const userData = await callMsGraphUsers(response.accessToken);
setOptions(userData.value);
refresh();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
})();
if (!options && inProgress === InteractionStatus.None) {
(async () => {
try {
const response = await instance.acquireTokenSilent(request);
const userData = await callMsGraphUsers(response.accessToken);
setOptions(userData.value);
refresh();
} catch (e) {
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
}
})();
}
}
if (!loading) {
@ -97,7 +104,7 @@ function CustomToolbar(props) {
React.useEffect(() => {
if (!open) {
setOptions([]);
setOptions(null);
}
}, [open]);
@ -119,12 +126,12 @@ function CustomToolbar(props) {
}
function onSave() {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -132,11 +139,15 @@ function CustomToolbar(props) {
enqueueSnackbar("Successfully updated admins", { variant: "success" });
refresh();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
} finally {
setSending(false);
}
@ -185,7 +196,7 @@ function CustomToolbar(props) {
}}
isOptionEqualToValue={(option, value) => option.displayName === value.displayName}
getOptionLabel={(option) => `${option.displayName} (${option.userPrincipalName})`}
options={options}
options={options || []}
loading={loading}
renderInput={(params) => (
<TextField
@ -252,12 +263,12 @@ export default function Administration() {
}, []);
function refreshData() {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setLoading(true);
const response = await instance.acquireTokenSilent(request);
@ -265,11 +276,15 @@ export default function Administration() {
setAdmins(data);
setLoadedAdmins(data);
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching admins", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching admins", { variant: "error" });
}
} finally {
setLoading(false);
}

Просмотреть файл

@ -5,6 +5,7 @@ import GlobalStyles from '@mui/material/GlobalStyles';
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError, InteractionStatus } from "@azure/msal-browser";
import {
Box,
@ -37,7 +38,7 @@ const StyledDiv = styled('div')({
});
export default function AnalysisTool() {
const { instance, accounts } = useMsal();
const { instance, inProgress, accounts } = useMsal();
const { enqueueSnackbar } = useSnackbar();
const [open, setOpen] = React.useState(false);
@ -50,25 +51,31 @@ export default function AnalysisTool() {
const ref = React.useRef(null);
React.useEffect(() => {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
try {
const response = await instance.acquireTokenSilent(request);
const data = await fetchTreeView(response.accessToken);
if (!options && inProgress === InteractionStatus.None) {
(async () => {
try {
const response = await instance.acquireTokenSilent(request);
const data = await fetchTreeView(response.accessToken);
setOptions(data);
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching Tree View", { variant: "error" });
}
})();
setOptions(data);
} catch (e) {
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching Tree View", { variant: "error" });
}
}
})();
}
}, []);
React.useEffect(() => {

Просмотреть файл

@ -3,6 +3,7 @@ import * as React from "react";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
Box,
@ -46,12 +47,12 @@ export default function AddBlock(props) {
cidr: cidr.value
};
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -59,11 +60,15 @@ export default function AddBlock(props) {
refresh();
onCancel();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -4,6 +4,7 @@ import { styled } from "@mui/material/styles";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
Box,
@ -45,12 +46,12 @@ export default function ConfirmDelete(props) {
if(force & !verify) {
setVerify(true);
} else {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -58,11 +59,15 @@ export default function ConfirmDelete(props) {
refresh();
handleCancel();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e.response.data.error);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e.response.data.error);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -4,6 +4,7 @@ import { styled } from "@mui/material/styles";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import { DataGrid, GridOverlay } from "@mui/x-data-grid";
@ -199,16 +200,16 @@ export default function EditReservations(props) {
}, [timer, copied]);
function refreshData() {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
scopes: apiRequest.scopes,
account: accounts[0],
};
setReservations([]);
setSelectionModel([]);
setLoading(true);
setReservations([]);
setSelectionModel([]);
setLoading(true);
(async () => {
if(space && block) {
try {
setRefreshing(true);
@ -216,11 +217,15 @@ export default function EditReservations(props) {
const data = await fetchBlockResv(response.accessToken, space, block);
setReservations(data);
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching available IP Block reservations", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching available IP Block reservations", { variant: "error" });
}
} finally {
setRefreshing(false);
}
@ -233,12 +238,12 @@ export default function EditReservations(props) {
}
function onSubmit() {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -247,11 +252,15 @@ export default function EditReservations(props) {
enqueueSnackbar("Successfully deleted IP Block reservations", { variant: "success" });
refreshData();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -7,6 +7,7 @@ import { isEqual } from 'lodash';
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import { DataGrid, GridOverlay } from "@mui/x-data-grid";
@ -74,17 +75,16 @@ export default function EditVnets(props) {
}, [refreshingState]);
function refreshData() {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
setVNets([]);
setLoading(true);
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
setVNets([]);
setLoading(true);
if(space && block) {
console.log(block);
try {
setRefreshing(true);
const response = await instance.acquireTokenSilent(request);
@ -92,11 +92,15 @@ export default function EditVnets(props) {
setVNets(data);
setSelectionModel(block['vnets']);
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching available IP Block networks", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching available IP Block networks", { variant: "error" });
}
} finally {
setRefreshing(false);
}
@ -114,12 +118,12 @@ export default function EditVnets(props) {
}
function onSubmit() {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -129,11 +133,15 @@ export default function EditVnets(props) {
refresh();
refreshData();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -2,7 +2,10 @@ import * as React from "react";
import { useSelector, useDispatch } from 'react-redux';
import { styled } from "@mui/material/styles";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import SpaceDataGrid from "./space/space";
import BlockDataGrid from "./block/block";
@ -58,6 +61,7 @@ const BottomSection = styled("div")(({ theme }) => ({
export default function ConfigureIPAM() {
const { instance, accounts } = useMsal();
const { enqueueSnackbar } = useSnackbar();
const [refreshing, setRefreshing] = React.useState(false);
const [selectedSpace, setSelectedSpace] = React.useState(null);
@ -77,10 +81,22 @@ export default function ConfigureIPAM() {
};
(async() => {
const response = await instance.acquireTokenSilent(request);
setRefreshing(true);
await dispatch(fetchSpacesAsync(response.accessToken));
setRefreshing(false);
try {
const response = await instance.acquireTokenSilent(request);
setRefreshing(true);
await dispatch(fetchSpacesAsync(response.accessToken));
setRefreshing(false);
} catch (e) {
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
}
})();
}

Просмотреть файл

@ -3,6 +3,7 @@ import * as React from "react";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
Box,
@ -46,12 +47,12 @@ export default function AddSpace(props) {
desc: description.value
};
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -61,11 +62,15 @@ export default function AddSpace(props) {
refresh();
handleClose();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error creating space", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error creating space", { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -4,6 +4,7 @@ import { styled } from "@mui/material/styles";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
Box,
@ -45,12 +46,12 @@ export default function ConfirmDelete(props) {
if(force & !verify) {
setVerify(true);
} else {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -58,11 +59,15 @@ export default function ConfirmDelete(props) {
refresh();
handleCancel();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e.response.data.error);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e.response.data.error);
console.log("------------------");
enqueueSnackbar(e.response.data.error, { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -3,6 +3,7 @@ import * as React from "react";
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
Box,
@ -70,12 +71,12 @@ export default function EditSpace(props) {
{ "op": "replace", "path": "/desc", "value": description.value }
];
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -83,11 +84,15 @@ export default function EditSpace(props) {
refresh();
onCancel();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error updating space", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error updating space", { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -1,6 +1,9 @@
import * as React from "react";
import { useSelector, useDispatch } from 'react-redux';
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError, InteractionStatus } from "@azure/msal-browser";
import { useSnackbar } from "notistack";
import { styled, alpha } from "@mui/material/styles";
@ -8,7 +11,6 @@ import { SvgIcon } from "@mui/material";
import { Routes, Route, Link, Navigate } from "react-router-dom";
import { useMsal } from "@azure/msal-react";
import { callMsGraph } from "../../msal/graph";
import {
@ -124,7 +126,7 @@ const StyledInputBase = styled(InputBase)(({ theme }) => ({
}));
export default function NavDrawer() {
const { instance, accounts } = useMsal();
const { instance, inProgress, accounts } = useMsal();
const { enqueueSnackbar } = useSnackbar();
const [menuAnchorEl, setMenuAnchorEl] = React.useState(null);
@ -221,30 +223,59 @@ export default function NavDrawer() {
]
];
React.useEffect(() => {
let graphTimer = setTimeout(() => {
const request = {
// ...loginRequest,
scopes: ["User.Read"],
account: accounts[0],
forceRefresh: true,
};
// React.useEffect(() => {
// let graphTimer = setTimeout(() => {
// const request = {
// // ...loginRequest,
// scopes: ["User.Read"],
// account: accounts[0],
// forceRefresh: true,
// };
// (async() => {
// try {
// const response = await instance.acquireTokenSilent(request);
// const graphResponse = await callMsGraph(response.accessToken);
// await setGraphData(graphResponse);
// } catch {
// setGraphError(x => !x);
// }
// })();
// }, 5000);
// return () => {
// clearTimeout(graphTimer);
// };
// }, [graphError]);
React.useEffect(() => {
const request = {
// ...loginRequest,
scopes: ["User.Read"],
account: accounts[0],
forceRefresh: true,
};
if (!graphData && inProgress === InteractionStatus.None) {
(async() => {
try {
const response = await instance.acquireTokenSilent(request);
const graphResponse = await callMsGraph(response.accessToken);
await setGraphData(graphResponse);
} catch {
setGraphError(x => !x);
} catch (e) {
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
// enqueueSnackbar(e.response.data.error, { variant: "error" });
}
}
})();
}, 5000);
return () => {
clearTimeout(graphTimer);
};
}, [graphError]);
}
}, [instance, accounts, inProgress, graphData]);
// React.useEffect(() => {
// const request = {
@ -363,23 +394,27 @@ export default function NavDrawer() {
);
function RequestToken() {
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
const response = await instance.acquireTokenSilent(request);
navigator.clipboard.writeText(response.accessToken);
handleMenuClose();
enqueueSnackbar('Token copied to clipboard!', { variant: 'success' });
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching access token", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error fetching access token", { variant: "error" });
}
}
})();
}

Просмотреть файл

@ -6,6 +6,8 @@ import {
useIsAuthenticated
} from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
getRefreshInterval,
refreshAllAsync,
@ -20,7 +22,6 @@ function Refresh() {
const { instance, accounts } = useMsal();
const [intervalAllId, setIntervalAllId] = React.useState();
const [intervalMeId, setIntervalMeId] = React.useState();
const isAuthenticated = useIsAuthenticated();
const refreshInterval = useSelector(getRefreshInterval);
const dispatch = useDispatch();
const refreshAllRef = React.useRef();
@ -33,17 +34,19 @@ function Refresh() {
};
(async() => {
const response = await instance.acquireTokenSilent(request).catch((e) => {
if (e.errorCode === "consent_required" || e.errorCode === "interaction_required" || e.errorCode === "login_required") {
instance.acquireTokenPopup(request).catch((e) => {
console.log("TOKEN ERROR:");
console.log("--------------");
console.error(e);
console.log("--------------");
});
try {
const response = await instance.acquireTokenSilent(request)
dispatch(refreshAllAsync(response.accessToken))
} catch (e) {
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
}
});
dispatch(refreshAllAsync(response.accessToken))
}
})();
}, []);
@ -54,17 +57,15 @@ function Refresh() {
};
(async() => {
const response = await instance.acquireTokenSilent(request).catch((e) => {
if (e.errorCode === "consent_required" || e.errorCode === "interaction_required" || e.errorCode === "login_required") {
instance.acquireTokenPopup(request).catch((e) => {
console.log("LOGIN ERROR:");
console.log("--------------");
console.error(e);
console.log("--------------");
});
}
});
dispatch(getMeAsync(response.accessToken))
try {
const response = await instance.acquireTokenSilent(request)
dispatch(getMeAsync(response.accessToken))
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
}
})();
}, []);

Просмотреть файл

@ -4,6 +4,7 @@ import { useSelector } from 'react-redux';
import { useSnackbar } from "notistack";
import { useMsal } from "@azure/msal-react";
import { InteractionRequiredAuthError } from "@azure/msal-browser";
import {
Box,
@ -65,12 +66,12 @@ export default function UserSettings(props) {
{ "op": "replace", "path": "/apiRefresh", "value": refreshValue }
];
(async () => {
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
const request = {
scopes: apiRequest.scopes,
account: accounts[0],
};
(async () => {
try {
setSending(true);
const response = await instance.acquireTokenSilent(request);
@ -79,11 +80,15 @@ export default function UserSettings(props) {
await getMeAsync(response.accessToken);
handleClose();
} catch (e) {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error updating refresh timeout", { variant: "error" });
if (e instanceof InteractionRequiredAuthError) {
instance.acquireTokenRedirect(request);
} else {
console.log("ERROR");
console.log("------------------");
console.log(e);
console.log("------------------");
enqueueSnackbar("Error updating refresh timeout", { variant: "error" });
}
} finally {
setSending(false);
}

Просмотреть файл

@ -8,17 +8,28 @@ const Login = () => {
const { instance, inProgress } = useMsal();
const isAuthenticated = useIsAuthenticated();
// React.useEffect(() => {
// if (!isAuthenticated && inProgress === InteractionStatus.None) {
// instance.loginRedirect(loginRequest).catch((e) => {
// if (e.errorCode === "consent_required" || e.errorCode === "interaction_required" || e.errorCode === "login_required") {
// instance.acquireTokenPopup(loginRequest).catch((e) => {
// console.log("LOGIN ERROR:");
// console.log("--------------");
// console.error(e);
// console.log("--------------");
// });
// }
// });
// }
// }, [isAuthenticated, inProgress, instance]);
React.useEffect(() => {
if (!isAuthenticated && inProgress === InteractionStatus.None) {
instance.loginRedirect(loginRequest).catch((e) => {
if (e.errorCode === "consent_required" || e.errorCode === "interaction_required" || e.errorCode === "login_required") {
instance.acquireTokenPopup(loginRequest).catch((e) => {
console.log("LOGIN ERROR:");
console.log("--------------");
console.error(e);
console.log("--------------");
});
}
console.log("LOGIN ERROR:");
console.log("--------------");
console.error(e);
console.log("--------------");
});
}
}, [isAuthenticated, inProgress, instance]);

Просмотреть файл

@ -16,9 +16,10 @@ export const msalConfig = {
// Add scopes here for ID token to be used at Microsoft identity platform endpoints.
export const loginRequest = {
scopes: [`api://${ENGINE_APP_ID}/.default`],
// scopes: [`api://${ENGINE_APP_ID}/.default`],
scopes: [`api://${ENGINE_APP_ID}/access_as_user`],
// scopes: ["https://management.azure.com/user_impersonation"],
// extraScopesToConsent: ["User.Read", "Directory.Read.All"]
extraScopesToConsent: ["openid", "profile", "offline_access", "User.Read", "Directory.Read.All"]
};
// Add scopes here for ID token to be used at Microsoft identity platform endpoints.