Made things do things.
This commit is contained in:
@@ -21,6 +21,7 @@ const msalState = {
|
||||
displayName: null,
|
||||
|
||||
debugFullTokenResponse: null,
|
||||
msalRefreshTimer: null,
|
||||
}
|
||||
|
||||
async function initializeMSAL() {
|
||||
@@ -35,6 +36,7 @@ async function initializeMSAL() {
|
||||
redirectUri: window.location.protocol + '//' + window.location.host + '/',
|
||||
},
|
||||
}
|
||||
msalState.msalRefreshTimer = setInterval(__refreshToken, 10 * 60 * 1000)
|
||||
|
||||
msalState.msal = new msal.PublicClientApplication(msalConfig)
|
||||
|
||||
@@ -70,6 +72,22 @@ export function LogoutMsal() {
|
||||
msalState.msal.logout()
|
||||
}
|
||||
|
||||
async function __refreshToken() {
|
||||
if (!msalState.isLoggedIn) return
|
||||
msalState.debugFullTokenResponse = await msalState.msal
|
||||
.acquireTokenSilent({ scopes: RequestedScopes })
|
||||
.catch((error) => {
|
||||
if (error instanceof msal.InteractionRequiredAuthError) {
|
||||
// fallback to interaction when silent call fails
|
||||
return msalState.msal.acquireTokenRedirect({
|
||||
scopes: RequestedScopes,
|
||||
})
|
||||
}
|
||||
})
|
||||
__responseObjectToMsalState()
|
||||
__stateChanged()
|
||||
}
|
||||
|
||||
async function __handleResponse(response) {
|
||||
if (response !== null) {
|
||||
if (__isAccountAceptable(response.account)) {
|
||||
@@ -82,7 +100,7 @@ async function __handleResponse(response) {
|
||||
msalState.msal
|
||||
.getAllAccounts()
|
||||
.filter(__isAccountAceptable)
|
||||
.forEach(account => {
|
||||
.forEach((account) => {
|
||||
msalState.msal.setActiveAccount(account)
|
||||
})
|
||||
|
||||
@@ -90,7 +108,7 @@ async function __handleResponse(response) {
|
||||
if (account != null) {
|
||||
msalState.debugFullTokenResponse = await msalState.msal
|
||||
.acquireTokenSilent({ scopes: RequestedScopes })
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
if (error instanceof msal.InteractionRequiredAuthError) {
|
||||
// fallback to interaction when silent call fails
|
||||
return msalState.msal.acquireTokenRedirect({
|
||||
@@ -118,7 +136,7 @@ function __isAccountAceptable(account) {
|
||||
}
|
||||
|
||||
function __stateChanged() {
|
||||
msalState.stateChangeCallbacks.forEach(cb => cb())
|
||||
msalState.stateChangeCallbacks.forEach((cb) => cb())
|
||||
}
|
||||
|
||||
async function __loadAuthParameters() {
|
||||
|
Reference in New Issue
Block a user