【问题标题】:Nuxtjs auth module - token endpoint in auth strategies configuration is never calledNuxtjs 身份验证模块 - 身份验证策略配置中的令牌端点永远不会被调用
【发布时间】:2021-05-06 07:30:15
【问题描述】:

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

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

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

这就是 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"
      }
    }
  },
...

【问题讨论】:

    标签: javascript vue.js nuxtjs nuxt-auth


    【解决方案1】:

    您是否有任何机会忘记设置 @nuxtjs/axios 或显式配置 auth 中间件?

    // nuxt.config.js
    modules: ['@nuxtjs/auth-next', '@nuxtjs/axios'],
    
    router: {
      middleware: ['auth'],
    },
    

    【讨论】:

      猜你喜欢
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 2021-08-02
      • 1970-01-01
      • 2020-07-03
      相关资源
      最近更新 更多