Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
This repository was archived by the owner on May 17, 2024. It is now read-only.

Angular router.navigate not working inside a subscribe of acquireTokenSilent or loginPopup #297

@pjr1ga

Description

@pjr1ga

Issue

Please provide us with the following information:

This issue is for the sample

    - [x ] 1-1) Sign-in with Azure AD
    - [ ] 1-2) Sign-in with Azure AD B2C
    - [ ] 2-1) Acquire a Token and call Microsoft Graph
    - [ ] 3-1) Protect and call a web API on Azure AD
    - [ ] 3-2) Protect and call a web API on Azure AD B2C
    - [ ]   4) Deploy to Azure Storage and App Service
    - [ ] 5-1) Call a web API using App Roles
    - [ ] 5-2) Call a web API using Security Groups
    - [ ] 6-1) Call Microsoft Graph using on-behalf-of flow
    - [ ] 6-2) Call a multi-tenant web API

This issue is for a

    - [x ] bug report -> please search issues before submitting
    - [ ] question
    - [ ] feature request
    - [ ] documentation issue or request

Minimal steps to reproduce

In the angular project I´m working I´m migrating to use the MsalService. I have already working and the pop up appears, and it gives back a successful response. I have the below code:

      this.msalService.loginPopup().subscribe(
        (response: AuthenticationResult)=>{
          console.log(response);
          this.isLoginInProcess=false;
          this.msalService.instance.setActiveAccount(response.account);
           this.router.navigate(['/theRouteIWantToOpen']);
        }
      );

At the end of the login I want to open the route: theRouteIWantToOpen however that it is not happening, the route keeps being the http://localhost:4200/
I tried to check if an error was happening by adding a "then" after the call of navigate, and added a console.log on the sucess response, and it indeed goes to the flow of expected successful response, but the router does goes to the theRouteIWantToOpen.

The same happened when there is an active account, and I try to call the acquireTokenSilent to validate the access.

this.msalService.acquireTokenSilent(request).toPromise().then(
      (result)=>{
        console.log("Success acquiring token");
        this.router.navigate(['/theRouteIWantToOpen']);
      }
    ).catch((error)=>{
      console.log("ERROR aquiring token");
      this.router.navigateByUrl('/login');
    });

Nothing happens on success.

A msalGuard is not configured, a custom guard is configured.

Any log messages given by the failure

There are no error messages, the last messages are:

[Wed, 01 Mar 2023 20:52:42 GMT] : @azure/msal-browser@2.33.0 : Info - Emitting event: msal:acquireTokenSuccess
msal-config.ts:25 [Wed, 01 Mar 2023 20:52:42 GMT] : @azure/msal-browser@2.33.0 : Verbose - Emitting event to callback e4bee3fb-5b51-4c92-a061-5de8b50f84e6: msal:acquireTokenSuccess
msal-config.ts:25 [Wed, 01 Mar 2023 20:52:42 GMT] : [xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx] : @azure/msal-browser@2.33.0 : Verbose - PerformanceClient: Measurement found for acquireTokenSilent
msal-config.ts:25 [Wed, 01 Mar 2023 20:52:42 GMT] : [xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx] : @azure/msal-browser@2.33.0 : Verbose - PerformanceClient: Submeasurement for acquireTokenSilent already exists for standardInteractionClientGetDiscoveredAuthority, ignoring
msal-config.ts:25 [Wed, 01 Mar 2023 20:52:42 GMT] : [xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx] : @azure/msal-browser@2.33.0 : Verbose - PerformanceClient: Emitting performance events

Expected/desired behavior

navigate to other route once the popup login is finished or when the token was acquired silently in the first login

Library version

"@angular/core": "~10.1.0",
"@azure/msal-angular": "^2.0.2",
"@azure/msal-browser": "^2.16.0",

Browser and version

Chrome Version 109.0.5414.120 (Official Build) (64-bit)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions