6

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...

7
  • 3
    I am looking for an example of this usage also. The github samples don't seem to deal with expiring tokens, etc. Commented Aug 19, 2020 at 16:22
  • It’s still on our ToDo list... currently we’re just happy to have tamed Azure AD into graciously allowing us to sign in without returning reams of exceptions :-( Commented Aug 19, 2020 at 22:13
  • Did you find anything on this?
    – Derek J.
    Commented Oct 13, 2020 at 22:28
  • Unfortunately no; we’re just wrapping up some feature work, but planning on going back, updating the packages and trying again. The Microsoft identity / msal packages seem to be evolving towards .net 5 so maybe breaking changes which resolve the issues...? Commented Oct 14, 2020 at 6:37
  • 2
    I am using this code for redirecting to login when token is expired: const sub = this.broadcastService.subscribe('msal:acquireTokenFailure', x => { sub.unsubscribe(); console.error('acquireTokenFailure :: token is expired.') this.authService.loginRedirect(); }); Commented Apr 8, 2021 at 2:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.