question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ctx.isAuthenticated() is false inside onAuthentication

See original GitHub issue

Hi,

Thanks for putting vue-msal together. It is generally working for me. However I noticed that the isAuthenticated() value is false within the onAuthentication handler:

onAuthentication: (ctx, error, response) => {
  console.log({ ctx, error, response });
  console.log(">>> isAuthenticated = " + ctx.isAuthenticated());
}

With this code I can see there is no error, but isAuthenticated is still false. If I peak at the the response I can see a valid response.

The next strange thing about all of this is if I call ctx.acquireToken() within onAuthentication, the returned promise of acquireToken is simply never resolved:

onAuthentication: (ctx, error, response) =>
{
  console.log({ ctx, error, response });
  console.log(">>> isAuthenticated = " + ctx.isAuthenticated());

  // Nothing is printed beyond this point, even though acquireToken yields a valid promise...
  ctx.acquireToken().then(
    () => {
      console.log(">>> success");
    },
    () => {
      console.log(">>> error");
    },
    () => {
      console.log(">>> rejected");
    });
}

So using vue-msal, what would be an appropriate technique to get the auth token immediately after a successful authentication? I am trying to make my code reactive based on that state. If I wait to call acquireToken, for example, from a click event, everything works. But I need to get the token ASAP.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Agendumcommented, Oct 28, 2019

You mentioned:

you should use the data object provided by the plugin.

But I have noticed vue-msal’s login state / data.accessToken is not automatically renewed when the token’s exp elapses. Creating a timer to renew the access token at exp-minus-tokenRenewalOffsetSeconds time is trivial, but me manually updating data.accessToken also doesn’t update any other vue-msal’s data properties. For my scenario, this is actually okay, but I am not sure this is a good pattern and the inconsistent state makes me uncomfortable. What is your opinion on the matter?

1reaction
Agendumcommented, Oct 24, 2019

Thanks this does make a lot of sense. I didn’t trust that msal.accessToken was reactive and it sure is. I now don’t need to custom watch anything at all, actually. Once I wired up vue-msal using globalMixin, everything just worked in all of my components without any extra business logic. Well, the only thing I had to do with toggle the config ‘requireAuthOnInitialize’ based on window.location.pathname for my signedout route because it doesn’t seem the vue router is ready yet. But other than that, it made this whole auth story so painless. I even ended up dropping the group checking and went with checking for app roles instead, so no graph calls needed even.

Great job on vue-msal!

Read more comments on GitHub >

github_iconTop Results From Across the Web

koa-passport w/ passport-steam: ctx.isAuthenticated() always ...
ctx.isAuthenticated() is always false, despite correctly logging in through Steam. I have been looking at plenty of other SO questions and ...
Read more >
Adding custom claims to a user during authentication with ...
How to add custom claims such as roles to a user after they sign in. OpenID Connect and JWT Bearer token authentication used...
Read more >
@pavelstancik/vue-msal - npm
isAuthenticated() : Returns true if the user has been authenticated and false otherwise. ❕ Note: This function should not be used for ...
Read more >
Context.User.Identity.IsAuthenticated is always false in jwt ...
I just write the token to the client. need I use other like SignInAsync? var token = new JwtSecurityTokenHandler().WriteToken(tokenWriter);.
Read more >
org.springframework.security.core.Authentication ...
Authentication#isAuthenticated. ... Authentication#isAuthenticated() ... isDebugEnabled()) { logger.debug("Unable to get certificates in request from " + ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found