Nuxt Auth 刷新令牌 - 身份验证失败

时间:2021-06-23 11:43:12

标签: express jwt nuxt.js nuxt-auth

我使用@nuxtjs/auth-next,我一定有配置问题,但我尝试了多个配置但没有成功。

我将此示例用于服务器部分 https://github.com/cornflourblue/node-mongo-signup-verification-api

这是我当前的配置:

auth: {
  redirect: {
    login: '/login',
    logout: '/',
    callback: '/login',
    home: '/'
  },
  strategies: {
    local: {
      scheme: 'refresh',
      token: {
        property: 'jwtToken',
        maxAge: 1800,
        global: true,
        // type: 'Bearer'
      },
      refreshToken: {
        property: 'refreshToken',
        data: 'refreshToken',
        maxAge: 60 * 60 * 24 * 30
      },
      user: {
        property: false,
        autoFetch: false
      },
      endpoints: {
        login: { url: '/accounts/authenticate', method: 'post', propertyName: 'data.jwtToken' },
        refresh: { url: '/accounts/refresh-token', method: 'post' },
        user: false,
        //user: { url: '/accounts/refresh-token', method: 'post', propertyName: null },
        logout: { url: '/accounts/revoke-token', method: 'post' }
      },
      // autoLogout: false
    }
  }
}

Response

Cookies

我认为饼干和答案是正确的。 怎么了?

1 个答案:

答案 0 :(得分:0)

使用此配置“工作”:

  auth: {
    redirect: {
      login: '/login',
      logout: '/',
      callback: '/login',
      home: '/'
    },
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'jwtToken',
          maxAge: 1800,
          global: true,
          //type: ''
        },
        refreshToken: {
          property: 'jwtToken',
          data: 'refreshToken',
          maxAge: 60 * 60 * 24 * 30
        },
        user: {
          property: false,
          autoFetch: false
        },
        endpoints: {
          login: { url: '/accounts/authenticate', method: 'post', propertyName: 'jwtToken' },
          refresh: { url: '/accounts/refresh-token', method: 'post' },
          user: false,
          //user: { url: '/accounts/refresh-token', method: 'post', propertyName: null },
          logout: { url: '/accounts/revoke-token', method: 'post' }
        },
        // autoLogout: false
      }
    }
  }

但实际上刷新令牌是由服务器在 HTTP Only cookie 中发送的,因此它不起作用。 @nuxtjs/auth-next 是否涵盖了这种情况,还是必须在 API 响应中包含刷新令牌?