auth-module icon indicating copy to clipboard operation
auth-module copied to clipboard

Token not refreshed with openIDConnect scheme

Open jedjebari opened this issue 3 years ago • 2 comments

Version

module: "@nuxtjs/auth-next": "5.0.0-1637745161.ea53f98", nuxt: 2.15.7

Nuxt configuration

mode:

  • [x] universal
  • [ ] spa

Nuxt configuration

  auth: {
    strategies: {
      keycloak: {
        scheme: 'openIDConnect',
        endpoints: {
          configuration: `http://localhost:8081/auth/realms/myrealm/.well-known/openid-configuration`,
        },
        clientId: 'myclient',
      },
    },
  },

What is expected?

Refresh token should be used to get a new token when it is expired (when using axios)

What is actually happening?

Refresh is not triggered. Axios continues sending requests with an expired token (although refresh token is available and correctly set in cookies)

Steps to reproduce

After getting a new token, wait until it is expired, and send a request with axios

Workaround

If I switch to oauth2 scheme, then it works (a request is sent to authorization server with refresh token)

  auth: {
    strategies: {
      keycloak: {
        scheme: 'oauth2',
        endpoints: {
          authorization:
            'http://localhost:8081/auth/realms/myrealm/protocol/openid-connect/auth',
          token:
            'http://localhost:8081/auth/realms/myrealm/protocol/openid-connect/token',
          userInfo:
            'http://localhost:8081/auth/realms/myrealm/protocol/openid-connect/userinfo',
          logout:
            'http://localhost:8081/auth/realms/myrealm/protocol/openid-connect/logout',
        },
        clientId: 'myclient',
        redirectUri: 'htttp://localhost:3000',
        scope: ['openid', 'profile', 'email'],
        grantType: 'authorization_code',
        responseType: 'code',
        codeChallengeMethod: 'S256',
      },
    },
  },

jedjebari avatar Dec 22 '21 20:12 jedjebari

I'm facing same issue, but worst.

Nuxt auth save the token and refresh token in cookies, but the axios doesn't put it no header, all requests are without token

auth: {
    strategies: {
      local: false,
      keycloak: {
        scheme: 'oauth2',
        endpoints: {
          authorization: keycloakURL.authorization,
          token: keycloakURL.token,
          userInfo: keycloakURL.userInfo,
          logout: keycloakURL.logout,
        },
        token: {
          property: 'access_token',
          type: 'Bearer',
          maxAge: 300,
        },
        refreshToken: {
          property: 'refresh_token',
          maxAge: 60 * 60 * 24 * 30,
        },
        token_type: 'Bearer',
        token_key: 'access_token',
        responseType: 'code',
        grantType: 'authorization_code',
        clientId: 'account',
        scope: ['openid', 'profile', 'email'],
        codeChallengeMethod: 'S256',
      },
    },
    redirect: {
      login: '/entrar',
      logout: '/entrar',
      home: '/',
    },
  },
  

CavalcanteLeo avatar Mar 15 '22 19:03 CavalcanteLeo

I'm facing same issue, but worst.

Nuxt auth save the token and refresh token in cookies, but the axios doesn't put it no header, all requests are without token

auth: {
    strategies: {
      local: false,
      keycloak: {
        scheme: 'oauth2',
        endpoints: {
          authorization: keycloakURL.authorization,
          token: keycloakURL.token,
          userInfo: keycloakURL.userInfo,
          logout: keycloakURL.logout,
        },
        token: {
          property: 'access_token',
          type: 'Bearer',
          maxAge: 300,
        },
        refreshToken: {
          property: 'refresh_token',
          maxAge: 60 * 60 * 24 * 30,
        },
        token_type: 'Bearer',
        token_key: 'access_token',
        responseType: 'code',
        grantType: 'authorization_code',
        clientId: 'account',
        scope: ['openid', 'profile', 'email'],
        codeChallengeMethod: 'S256',
      },
    },
    redirect: {
      login: '/entrar',
      logout: '/entrar',
      home: '/',
    },
  },
  

It works on my side. Did you set correctly the axios baseUrl in your nuxt.config.js file ? Are you using relative or absolute paths when running axios requests ?

jedjebari avatar Mar 21 '22 20:03 jedjebari