itpropro / nuxt-oidc-auth

OIDC (OpenID connect) focused auth module for Nuxt
https://nuxtoidc.cloud
MIT License
83 stars 22 forks source link

Feat: Make 5 minute cookie expiration for login process customizable #55

Open AsbDaryaee opened 1 month ago

AsbDaryaee commented 1 month ago

Screenshot 2024-09-21 183434

Hi, I've been using nuxt-oidc-auth for a while and everything seems fine, but some users have trouble with authentication. When user is done with authentication and redirects to the redirectUri, the error appears.

I Checked the console and the error below was there:

Screenshot 2024-09-21 185552

Also this message was in my terminal: WARN [Vue Router warn]: No match found for location with path "/auth/oidc/login"

Can anyone help me figure it out and fix the problem?

itpropro commented 1 month ago

Can you first check if you have the most current version and if you use Nuxt SSR? There were some changes in route handling in the last few versions. For further troubleshooting I would need your oidc nuxt config and .env (if applies) of course without secrets and other sensitive info.

AsbDaryaee commented 1 month ago

I use v0.12.0 and Yes I do use SSR for my project.

And this is my config from nuxt.config.ts file:

  oidc: {
    defaultProvider: "oidc",
    providers: {
      oidc: {
        clientId: [Client ID],
        clientSecret: [Client Secret],
        redirectUri: "[Address]/auth/oidc/callback",
        scope: [
          "openid",
          "profile",
          "offline_access",
          "page_api",
        ],
        responseMode: "query",
        responseType: "code",
        authorizationUrl: "[address]/connect/authorize",
        tokenUrl: "[Address]/connect/token",
        userinfoUrl: "[Address]/connect/userinfo",
        logoutUrl: "[Address]/connect/endsession",
        pkce: true,
        tokenRequestType: "form-urlencoded",
        exposeAccessToken: true,
      },
    },
    middleware: {
      globalMiddlewareEnabled: false,
      customLoginPage: false,
    },
    session: {
      expirationCheck: true,
      automaticRefresh: true,
      maxAge: 3600 * 24 * 2, // 2 Days
    },
  },
itpropro commented 1 month ago

Please update to the most current version and verify, if the problems are still the same. Which oidc provider do you use, so I can check if I am able to reproduce? If your OIDC provider doesn't support the state challenge, you can disable that. There are 3 significant settings provided in nuxt-oidc-auth for this:

Option Type Default Description
pkce boolean (optional) false Use PKCE (Proof Key for Code Exchange)
state boolean (optional) true Use state parameter with a random value. If state is not used, the nonce parameter is used to identify the flow.
nonce boolean (optional) false Use nonce parameter with a random value.
AsbDaryaee commented 1 month ago

After updating to the latest version, I no longer receive reports about this issue. However, I was able to reproduce the error under specific conditions: If a user takes a long time to log in (approximately 5 minutes), the cookie that library creates expires. When the user finally returns to the callback page, they encounter an error. It seems that the library might occasionally fail to initialize correctly or handle the deletion of the old cookie, which leads to this error.

itpropro commented 3 weeks ago

After updating to the latest version, I no longer receive reports about this issue. However, I was able to reproduce the error under specific conditions: If a user takes a long time to log in (approximately 5 minutes), the cookie that library creates expires. When the user finally returns to the callback page, they encounter an error. It seems that the library might occasionally fail to initialize correctly or handle the deletion of the old cookie, which leads to this error.

Hi @AsbDaryaee, this is currently by design, as 5 minutes should be more than enough to return to the callback page in case you are doing a registration etc.. This will be a configurable setting in one of the later version.

AsbDaryaee commented 3 weeks ago

Thank you @itpropro