AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.66k stars 2.65k forks source link

BrowserAuthError: no_token_request_cache_error: No token request found in cache #6791

Closed vinothkummar closed 10 months ago

vinothkummar commented 10 months ago

Core Library MSAL.js (@azure/msal-browser)

Core Library Version "@azure/msal-browser": "^2.22.1"

Wrapper Library MSAL Angular (@azure/msal-angular)

Wrapper Library Version "@azure/msal-angular": "^2.1.2",

Public or Confidential Client? Public

Description After login with the credentials it is keep redirecting to the same page again in a loop and the policy behind custom policy in order for me to set up the office 365 identity provider sign up. => this is behaviour I see it in the edge browser.

If I run the application in the visual studio code debut mode and which open in the open chrome browser; it takes credentials and throws error BrowserAuthError: no_token_request_cache_error: No token request found in cache. at BrowserAuthError.AuthError [as constructor] (AuthError.js:27:24) at new BrowserAuthError (BrowserAuthError.js:197:28) at BrowserAuthError.createNoTokenRequestCacheError (BrowserAuthError.js:354:16) at BrowserCacheManager.getCachedRequest (BrowserCacheManager.js:802:19) at RedirectClient. (RedirectClient.js:222:61) at step (_tslib.js:75:23) at Object.next (_tslib.js:56:53) at _tslib.js:49:71 at new ZoneAwarePromise (zone.js:1427:29) at __awaiter (_tslib.js:45:12)

Error: Uncaught (in promise): ClientAuthError: state_not_found: State not found: Cached State ClientAuthError: state_not_found: State not found: Cached State at ClientAuthError.AuthError [as constructor] (AuthError.js:27:24) at new ClientAuthError (ClientAuthError.js:206:28) at ClientAuthError.createStateNotFoundError (ClientAuthError.js:282:16) at RedirectHandler. (RedirectHandler.js:96:35) at step (_tslib.js:75:23) at Object.next (_tslib.js:56:53) at _tslib.js:49:71 at new ZoneAwarePromise (zone.js:1427:29) at __awaiter (_tslib.js:45:12) at RedirectHandler.handleCodeResponseFromHash (RedirectHandler.js:81:25) at resolvePromise (zone.js:1211:31) at zone.js:1118:17 at zone.js:1134:33 at _ZoneDelegate.invoke (zone.js:372:26) at Object.onInvoke (core.mjs:26491:33) at _ZoneDelegate.invoke (zone.js:371:52) at Zone.run (zone.js:134:43) at zone.js:1275:36 at _ZoneDelegate.invokeTask (zone.js:406:31) at Object.onInvokeTask (core.mjs:26478:33)

MSAL Configuration export const environment = { production: false, mockServer: false, webapi: "https://localhost:55376/api/v1/", webapibase: "https://localhost:55376", i18n: "assets/i18n/", brokerStylesPath: "", webapiversion: "1", auth: { scopes: ['https://EmporosClientPortalQAT.b2clogin.com/0c1439c2-8fea-4c39-9a2d-2791cb535902/access_as_user'], clientId: "0c1439c2-8fea-4c39-9a2d-2791cb535902", authDomain: "https://EmporosClientPortalQAT.b2clogin.com/", baseAuthority: "https://EmporosClientPortalQAT.b2clogin.com/EmporosClientPortalQAT.onmicrosoft.com/B2C_1A_", knownAuthorities: ["EmporosClientPortalQAT.b2clogin.com"], redirectUri: "http://localhost:4200", postLogoutRedirectUri: "http://localhost:4200", azureRedirectUri: "http://localhost:4200", subdomainRedirectUri: "", }, files: { maxfileSize: 5242880 } }; Relevant Code Snippets import { NgModule, APP_INITIALIZER } from '@angular/core'; import { IPublicClientApplication, PublicClientApplication, BrowserCacheLocation, InteractionType, Configuration} from '@azure/msal-browser'; import { MsalGuard, MsalInterceptor, MsalBroadcastService, MsalInterceptorConfiguration, MsalModule, MsalService, MSAL_GUARD_CONFIG, MSAL_INSTANCE, MSAL_INTERCEPTOR_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular'; import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { ConfigService } from './msal-config.service'; import { environment } from '../../../../environments/environment';

const environmentAuth = { ...environment.auth };

export function initializerFactory(configService: ConfigService): any { const promise = configService.init().then((value) => {

});
return () => promise;

}

export function MSALInstanceFactory(configService: ConfigService): IPublicClientApplication { let config = msalConfig; config.auth.authority = configService.getAuthority(); config.auth.redirectUri = configService.getRedirectPath(); config.auth.postLogoutRedirectUri = configService.getLogoutPath();

return new PublicClientApplication(config); }

export function MSALInterceptorConfigFactory(config: ConfigService): MsalInterceptorConfiguration { const protectedResourceMap = new Map<string, Array>(); protectedResourceMap.set(environment.webapi, environmentAuth.scopes);

return {
  interactionType: InteractionType.Redirect,
  protectedResourceMap,
  authRequest: {
    authority: config.getAuthority(),
    redirectUri: config.getRedirectPath(),
  }
};

}

export function MSALGuardConfigFactory(config: ConfigService): MsalGuardConfiguration { return { interactionType: InteractionType.Redirect, loginFailedRoute: config.getRedirectPath(),

  authRequest: {
    authority: config.getAuthority(),
    redirectUri: config.getRedirectPath(),
    scopes: environmentAuth.scopes
  }

}; }

export const msalConfig: Configuration = { auth: environmentAuth, cache: { cacheLocation: BrowserCacheLocation.SessionStorage, storeAuthStateInCookie: false, secureCookies: false }, system: { loggerOptions: { loggerCallback: (level: any, message: any, containsPii: any) => { if (containsPii) { return; } }, piiLoggingEnabled: false } } };

@NgModule({ providers: [], imports: [MsalModule] }) export class MsalConfigDynamicModule {

static forRoot() { return { ngModule: MsalConfigDynamicModule, providers: [ ConfigService,

            {
                provide: APP_INITIALIZER, useFactory: initializerFactory,
                deps: [ConfigService],
                multi: true
            },
            {
                provide: MSAL_INSTANCE,
                useFactory: MSALInstanceFactory,
                deps: [ConfigService]
            },
            {
                provide: MSAL_GUARD_CONFIG,
                useFactory: MSALGuardConfigFactory,
                deps: [ConfigService]
            },
            {
                provide: MSAL_INTERCEPTOR_CONFIG,
                useFactory: MSALInterceptorConfigFactory,
                deps: [ConfigService]
            },
            MsalService,
            MsalGuard,
            MsalBroadcastService,
            {
                provide: HTTP_INTERCEPTORS,
                useClass: MsalInterceptor,
                multi: true
            }
        ]
    };
}

} Identity Provider Azure B2C Custom Policy

Source External (Customer)

please help to resolve this and I have gone through all you previous response but non of them helps me in order resolve the issue. I'm stuck in this issue almost 2 weeks.

github-actions[bot] commented 10 months ago

Invalid Issue Template: Please open a new issue and use one of the provided issue templates. Thanks!