oosato
oosato

Reputation: 1

How to use refresh_token in @nuxtjs/auth-next?

I'm sorry if there are any mistakes because my native language is not English. I'm using this module with the configuration below, but when I run auth/rerfresh it's requesting using the access_token. I get the Authorization header on the server side, and when I decode the JWT, the content is access_token. I am assuming that with this module, when the access_token expires, it will set the refresh_token in the Authorization header and run api/auth/refresh.

Please let me know if there are any mistakes...

   auth: {
    redirect: {
      login:    '/login', 
      logout:   '/login',
      callback: '/login', 
      home:     '/'      
    },
    strategies: {
      local: {
        scheme:     'refresh',
        autoLogout: true,
        token: {
          property: 'access_token',
          maxAge:   1800,
          global:   true,
          // type: 'Bearer'
        },
        refreshToken: {
          property: 'refresh_token',
          data:     'refresh_token',
          maxAge:   60 * 60 * 24 * 30
        },
        user: {
          property:   false,
          autoFetch:  true
        },
        endpoints: {
          login: {
            url:          '/auth/login',
            method:       'post',
            propertyName: 'access_token',
            headers: {
              "Content-Type": "application/x-www-form-urlencoded",
              "grant_type":   "password"
            },
          },
          refresh:  { url: '/auth/refresh', method: 'get'                       },
          logout:   { url: '/auth/logout',  method: 'post',                     },
          user:     { url: '/auth/me',      method: 'get', propertyName: false  }
        }
      },
[/auth/login response]
{
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzX3Rva2VuIiwiZXhwIjoxNjc0NTI1OTA3LCJzdGFmZl9pZCI6ImFiY2RlMTIzIn0.68BPtgr93lwHgSfSQxieEJUJtGPe9bafQMpnbdHEqy0",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaF90b2tlbiIsImV4cCI6MTY3NzExNzg0Nywic3RhZmZfaWQiOiJhYmNkZTEyMyJ9.71B1iofZIsoaduUOH7ahuTi2gc2NCp5fpsRrsZaGPMg",
    "token_type": "bearer"
}

[Cookies]

Name Value Expires/Max-Age Priority
auth._token_expiration.local 1674525907000 Session Medium
auth._refresh_token.local eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaF90b2tlbiIsImV4cCI6MTY3NzExNzg0Nywic3RhZmZfaWQiOiJhYmNkZTEyMyJ9.71B1iofZIsoaduUOH7ahuTi2gc2NCp5fpsRrsZaGPMg Session Medium
auth._token.local Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzX3Rva2VuIiwiZXhwIjoxNjc0NTI1OTA3LCJzdGFmZl9pZCI6ImFiY2RlMTIzIn0.68BPtgr93lwHgSfSQxieEJUJtGPe9bafQMpnbdHEqy0 Session Medium
auth._refresh_token_expiration.local 1677117847000 Session Medium
auth.strategy local Session Medium

Upvotes: 0

Views: 360

Answers (1)

oosato
oosato

Reputation: 1

refresh:  { url: '/auth/refresh', method: 'post' },

Changed as above.

I expected refresh_token to be included in the Authorization header, but it seems to be included in the request body. Changed to refer to the request body in server-side processing.

Upvotes: 0

Related Questions