microsoft-authentication-library-for-js: msal2: you cannot determine current login state so handleRedirectPromise() becomes awkward

msal2:

The instructions and vanilla example app both show calling agent.handleRedirectPromise() after a redirect login. However, there is no method to determine if a there is a “pending” redirect to handle. The only way to determine that is to appear to login in again and catch an exception (BrowserAuthError, with code=interaction_in_progress). I’m assuming that the page behavior is app page => ms redirect login pages => app page.

This makes UI login logic more difficult to handle.

Is there a way to determine if a login is in progress and hence, one should not call login, but chain handleRedirectPromise()?

Or is that completely left up to the app e.g. set some “login processing” state into local storage?

It appears from the documentation that handleRedirectPromise() must be called after login redirect request as well as after token redirect request.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (8 by maintainers)

Most upvoted comments

If you want to know if you are in a login step (vs access token step), you can pass state=“login” to the login request options and check the state inside the handleRedirectPromise. Similarly, if you are issuing an access token request, you can set state=“token” and check for that inside handleRedirectPromise.

I agree that a token is a token. I do pass in the same scopes to both login redirect and the “get token” redirect. I’ll have to look up if that’s not needed under the code authorization flow and then decide if I can differentiate with that. I think your general thought is that I should be able to differentiate on the login processing state based solely on the token returned at each step, and that seems to make sense and potentially is the missing piece for me.