function setTokenRedirectToLocalStorage(req) { auth.acquireTokenSilent(req) .then(function(response) { window.localStorage.setItem("token", response.accessToken); }) .catch(function(error) { // }); }
const getAccessToken = async () => { // Get the access token silently // If the cache contains a non-expired token, this function // will just return the cached token. Otherwise, it will // make a request to the Azure OAuth endpoint to get a token try { const token = window.localStorage.getItem("token"); if (!token) { const response = await auth.acquireTokenSilent(GRAPH_REQUESTS.LOGIN); return response.accessToken; } return token; } catch (error) { if (requiresInteraction(error.errorCode)) { return auth.acquireTokenRedirect(GRAPH_REQUESTS.LOGIN); } else { console.error("Non-interactive error:", error.errorCode); } } }