Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh Token Expire Date #944

Open
abolix opened this issue Nov 13, 2024 · 3 comments
Open

Refresh Token Expire Date #944

abolix opened this issue Nov 13, 2024 · 3 comments
Labels
question A question about NuxtAuth

Comments

@abolix
Copy link

abolix commented Nov 13, 2024

Environment

Reproduction

  auth: {
    isEnabled: true,
    globalAppMiddleware: true,
    baseURL: 'http://127.0.0.1:8000/userarea/',
    provider: {
      type: 'local',
      token: {
        signInResponseTokenPointer: '/access',
        type: 'Bearer',
        cookieName: 'auth.access',
        headerName: 'Authorization',
        maxAgeInSeconds: 60 * 3,
        sameSiteAttribute: 'lax',
        secureCookieAttribute: false,
        httpOnlyCookieAttribute: false,
      },
      endpoints: {
        signIn: { path: 'login', method: 'POST' },
        signOut: { path: 'logout', method: 'POST' },
        getSession: { path: 'user-info', method: 'GET' },
        signUp: false
      },
      refresh: {
        isEnabled:true,
        refreshOnlyToken: true,
        token: {
          signInResponseRefreshTokenPointer: '/refresh',
          refreshRequestTokenPointer: '/refresh',
          cookieName: 'auth.refresh',
          maxAgeInSeconds: 1800,
          sameSiteAttribute: 'lax',
          secureCookieAttribute: false,
          httpOnlyCookieAttribute: false,
        },
        endpoint: {
          path: 'refresh',
          method: 'POST',
        },
      },
    },
    sessionRefresh: {
      enablePeriodically: 1000 * 30,
      enableOnWindowFocus: true,
    },
  },

Describe the bug

I have Django JWT Backed with access (5 minutes exp) & refresh token (90 days exp)
the refresh token rotation is not active so I used refreshOnlyToken:true.

I want my refresh token cookie to be expired in 90 days. but I can't set maxAgeInSeconds to 60 * 60 * 24 * 90 because max time is 24 days.

what is the approach here ?

Additional context

No response

Logs

No response

@abolix abolix added bug A bug that needs to be resolved pending An issue waiting for triage labels Nov 13, 2024
@phoenix-ru
Copy link
Collaborator

because max time is 24 days.

Could you please elaborate why? Is it a technical limitation from JavaScript side, our library or Django? Afaik, browser limits on cookie age are high enough for your usecase

@phoenix-ru phoenix-ru added question A question about NuxtAuth and removed bug A bug that needs to be resolved pending An issue waiting for triage labels Nov 21, 2024
@abolix
Copy link
Author

abolix commented Nov 22, 2024

I want my user to have the refresh token cookie for 90 days. because it's standard to keep the refresh token for this amount of days but I can't set the maxAgeInSeconds to 90 days. so it's gonna be expired after 24 days but it should be kept for 90.

@phoenix-ru
Copy link
Collaborator

phoenix-ru commented Nov 28, 2024

I don't understand what you mean? You mean that the max delay argument supplied to the setInterval function is 24.8 days?
https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval#return_value

const intervalTime = provider.refresh.token.maxAgeInSeconds * 1000
this.refreshTokenIntervalTimer = setInterval(() => {
if (this.auth?.refreshToken.value) {
this.auth.refresh()
}
}, intervalTime)

Yes, it's logical that you can't set the timer longer than 24 days, but you have to keep in mind that setInterval is only valid while the browser tab is active and it won't persist across reloads. As it's highly improbably of anyone keeping the tab open for over 24 days (or your 90 days), I am not sure what exactly are you trying to achieve?

Maybe a better implementation would've been to set the interval to the actual expiry date of the refresh token, but that's another story.


Adding to it, I have also checked the useCookie implementation in Nuxt, which in turn uses cookie-es. Their implementation explicitly checks the maxAge:
https://github.com/unjs/cookie-es/blob/d83ac9456e1dae5033abb187017d5b43f982b17b/src/cookie/serialize.ts#L51-L59

Are you getting any errors from cookie-es? The value you want to use is absolutely correct and shouldn't trigger any issues. Please verify that the issue is not in your setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about NuxtAuth
Projects
None yet
Development

No branches or pull requests

2 participants