Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requireAuthOnInitialize not working and no docs on how to use with routes #31

Open
gcacars opened this issue Jul 16, 2020 · 1 comment

Comments

@gcacars
Copy link

gcacars commented Jul 16, 2020

Certain routes in my application require authentication. And I don't know how to make it work with routes.
So, I set the requireAuthOnInitialize option in the plugin and set it to true, but it doesn't work either.
The browser shows an error when I open it:

image

How can I set authentication per route to avoid visual flick?

[Option 1]

  {
    path: '/explorer',
    name: 'Explorer',
    component: () => import(/* webpackChunkName: "explorer" */ '../views/LogExplorer.vue'),
    beforeRouteEnter(to from, next) {
      if (!this.$msal || !this.$msal.isAuthenticated()) {
        this.$msal.signIn();
      }
    }
  },

It is not possible to use this and vue-msal does not export these methods.

[Option 2]

Vue.use(msal, {
  auth: {
    clientId: process.env.VUE_APP_CLIENT_ID,
    requireAuthOnInitialize: true,
  },
  graph: {
    callAfterInit: false,
  },
});
@daglenn1960
Copy link

Observation: we ran into this same issue using simple/default Vue.js app.

What we observed was that not explicitly setting a "redirectUri" value gives an incorrect redirectUri to the MS auth flow. We were seeing the following (and the iframe/allow-top-navigation error above), which is missing the required '&' to delineate the initial id_token parm:

http://localhost:8080/#id_token=eyJ0eXAiOiJKV

What we changed to get a working redirectUri was explicitly setting 'redirect Uri' with:

auth: {
    redirectUri: "http://localhost:8080",

and now the correct redirectUri (with & before the id_token parm) is passed to MS auth flow correctly, and redirects back correctly.

Could this be an issue/bug with a default redirectUri vs explicitly set redirectUri?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants