What to implement when "msal:acquireTokenFailure" is thrown?

Viewed 1099

I know this should be simple, but a little help would be appreciated; we're all a bit new to using industrial strength typescript packages.

We're building an Angular App and using the @azure/msal-angular library, which for most part works OK; following the tutorials and examples and it generally all make sense.

Apart from what to implement when the "msal:acquireTokenFailure" event is broadcast?

In the ngOnInit() method of our AppComponent we have this line

    // Subscriptions and redirects are for jwtTokens
    this.subscription = this.broadcastService.subscribe("msal:acquireTokenFailure", () => {
      // ToDo: What should be implemented here?
    });

In a few posts to the GitHub page for the project contributors have suggested something along the lines of

    // Subscriptions and redirects are for jwtTokens
    this.subscription = this.broadcastService.subscribe("msal:acquireTokenFailure", () => {
      this.subscription.unsubscribe();
      this.authService.loginRedirect();
    });

Which, as far as I can, will redirect to an AzuerAD login screen but will lose the underlying call details that we trying to get a Token for.

What looks more useful (in pseudo-code) would be something like

// Subscriptions and redirects are for jwtTokens
    this.subscription = this.broadcastService.subscribe("msal:acquireTokenFailure", () => {
      this.subscription.unsubscribe();

      if (isIE) {
        this.authService.acquireTokenRedirect(userRequest);
      } else {
        this.authService.acquireTokenPopup(userRequest);
      }
    });

The question being, is this a valid approach; and where would we recover the userRequest parameters from?

Please, please, don't redirect me to the Microsoft docs; I've spent hours going round in circles following the same links...

0 Answers
Related