atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
974 stars 91 forks source link

Google Auth: redirect_uri_mismatch #142

Closed luminous8 closed 2 months ago

luminous8 commented 3 months ago

Hi,

I've recently updated to nuxt-auth-utils 0.3.4 and my code stopped working (i made some other changes but not related to auth so i'm not sure where the issue comes from)

When doing a Google Auth, I'm getting an Error 400: redirect_uri_mismatch that i didn't had before

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you're the app developer, register the redirect URI in the Google Cloud Console.
Request details: redirect_uri=http://localhost/api/auth/google flowName=GeneralOAuthFlow

For some reasons the redirect_uri is localhost where i'm on my prod server (works fine on localhost as you can guess) From what i've seens redirect_uri is based on redirectUrl const redirectURL = config.redirectURL || getRequestURL(event).href; I have no idea where config.redirectURL comes from but i haven't defined "NUXT_OAUTH_GOOGLE_REDIRECT_URL" so it should take the current url which is api/auth/google

Any idea where to look? i had this bug for a week but cannot find a way to fix it

Thanks

luminous8 commented 3 months ago

So i fixed it by using the new NUXTOAUTH_REDIRECT_URL but it feels like it's overkill in my case (i'm only deploying it on a vps)

i'm still interested if that the new expected behaviour

atinux commented 2 months ago

This might be a bug @luminous8 sorry about this and thanks for reporting

luminous8 commented 2 months ago

thanks for the update @atinux 🙏

tcarterBAMF commented 2 months ago

For some reasons the redirect_uri is localhost where i'm on my prod server (works fine on localhost as you can guess) From what i've seens redirect_uri is based on redirectUrl const redirectURL = config.redirectURL || getRequestURL(event).href; I have no idea where config.redirectURL comes from but i haven't defined "NUXT_OAUTH_GOOGLE_REDIRECT_URL" so it should take the current url which is api/auth/google

@luminous8

config.redirectUrl comes from nuxt.config.ts as runtimeConfig.oauth.<provider>.redirectUrl. You could set it there if it makes more sense than using the NUXT_ var.

luminous8 commented 2 months ago

Both work for me; it's just that by default, when your config isn't "specific" (i.e., there's no added value in using the redirectUrl), it should work as it did before

atinux commented 2 months ago

Can you confirm that pinning the version to 0.3.3 that the issue is gone @luminous8 ?

The way it's implemented I don't see where config.redirectURL could be defined and take over the redirectUrl.

Are you behind a reverse proxy for your production deployment?

It works for me with latest version of nuxt-auth-utils in production on https://draw.nuxt.dev/draw

luminous8 commented 2 months ago

I've reverted to 0.3.3 and it worked then updated to 0.3.4 and... it worked as well!

So i'm not sure what was the issue before but it works

fyi, it's deployed on CF with nuxthub (great product btw)