import { Injectable } from '@angular/core'; import { IPublicClientApplication, PublicClientApplication, InteractionType, LogLevel } from '@azure/msal-browser'; import { MsalInterceptorConfiguration, MsalGuardConfiguration } from '@azure/msal-angular'; declare let CONFIG: any; const isIE = window.navigator.userAgent.indexOf("MSIE ") > -1 || window.navigator.userAgent.indexOf("Trident/") > -1; @Injectable({ providedIn: 'root', }) export class AzureAuthUtils { static loggerCallback(logLevel: LogLevel, message: string) { // console.log(message); } static MSALInstanceFactory(): IPublicClientApplication { const auth = CONFIG.AZURE.auth; return new PublicClientApplication({ auth: { clientId: auth.clientId, authority: auth.authority, redirectUri: auth.redirectUri, postLogoutRedirectUri: auth.postLogoutRedirectUri, knownAuthorities: auth.knownAuthorities }, cache: { cacheLocation: auth.cacheLocation, storeAuthStateInCookie: isIE, // set to true for IE 11 }, system: { loggerOptions: { loggerCallback : AzureAuthUtils.loggerCallback, logLevel: LogLevel.Info, piiLoggingEnabled: false } } }); } static MSALInterceptorConfigFactory(): MsalInterceptorConfiguration { const apiConfig = CONFIG.AZURE.apiConfig; const protectedResourceMap = new Map>(); protectedResourceMap.set(apiConfig.uri, apiConfig.scopes); return { interactionType: InteractionType.Redirect, protectedResourceMap, }; } static MSALGuardConfigFactory(): MsalGuardConfiguration { const apiConfig = CONFIG.AZURE.apiConfig; return { interactionType: InteractionType.Redirect, authRequest: { scopes: [...apiConfig.scopes], }, loginFailedRoute: '/' }; } }