Nuxtjs 身份验证模块 - 身份验证策略配置中的令牌端点永远不会被调用

时间:2021-05-06 07:30:15

标签: javascript vue.js nuxtjs nuxt-auth

我们有两个端点 /auth/token。端点 /auth 返回调用 /token 以获取访问令牌时可以使用的授权代码。

使用 NuxtJS auth 模块成为了可行的方法。据我所知,登录过程 this.$auth.loginWith("company") 工作正常。我被重定向到登录页面。我可以输入我的凭据,当这些凭据有效时,我会被重定向到配置的 URL。

到目前为止,一切都按预期进行。重定向将授权代码作为请求参数传递。

网址如下:

http://localhost:3000/?state=Y6CWcCZanJ&session_state=2c966cd9-5834-4045-9bfb-6aa9f616f841&code=fbabf615-cd5e-4479-818a-6a7ba72de01b.2c966cd9-5834-4045-9bfb-6aa9f616f841.553d562b-c454-4681-83ae-98cd93dbfa90

但是对于这个 code,我希望 auth 模块自动调用 /token 端点。但事实并非如此。这是为什么?

在使用 this.$auth.loginWith("company") 后是否需要显式调用它?类似的东西:

this.$auth.loginWith("company");
this.$auth.fetchToken();

还是隐含地做的?

这是nuxt.config.js中的配置

...
  auth: {
    strategies: {
      company: {
        scheme: "oauth2",
        endpoints: {
          authorization:
            "https://login.mycompany.com/auth/realms/apps/protocol/openid-connect/auth",
          token:
            "https://login.mycompany.com/auth/realms/apps/protocol/openid-connect/token",
          userInfo:
            "https://login.mycompany.com/auth/realms/apps/protocol/openid-connect/userinfo",
          logout: "http://localhost:3000/logout"
        },
        token: {
          name: "Authorization",
          property: "access_token",
          type: "Bearer",
          maxAge: 1800
        },
        refreshToken: {
          property: "refresh_token",
          maxAge: 60 * 60 * 24 * 30
        },
        responseType: "code",
        grantType: "authorization_code",
        accessType: undefined,
        redirectUri: "http://localhost:3000",
        logoutRedirectUri: undefined,
        clientId:
          process.env.CLIENT_ID ||
          "3004761-241-dab74c5e-ad70-11eb-bea4-4193bd361dc612123",
        scope: ["all"],
        codeChallengeMethod: "S256"
      }
    }
  },
...

0 个答案:

没有答案