SohoHouse / nuxt-oauth

Simple OAuth2 integration for your Nuxt app
MIT License
122 stars 27 forks source link

OAuth consent screen not redirecting to default current page #30

Open setyoaji21 opened 5 years ago

setyoaji21 commented 5 years ago

I have successfully redirecting user to google oauth consent screen. But, after the access granted it won't return to default current page

samtgarson commented 5 years ago

Will need a lot more information than this to be able to help.

cedricium commented 5 years ago

In many OAuth authentication libraries, they provide you (the developer) the option to set the redirect uri which is the uri that the OAuth provider (i.e. Google, Twitter, Reddit, etc.) will redirect back to in the case that the user consents to having their account used.

nuxt-oauth does not provide the option to set the redirect uri and after some digging, it seems that the uri is set to ${protocol}://${this.req.headers.host}/auth/callback. I'm using this to authenticate with reddit so YMMV, but I successfully redirect the user to reddit's oauth consent screen, however, after "Allow" is clicked, reddit tries to redirect to http://localhost:3000/auth/callback. This is where the issue occurs - if you manually go to http://localhost:3000/auth/callback, my Nuxt app redirects to reddit's oauth consent screen - ultimately the user will not be able to get back to my Nuxt app after consenting since the redirect uri that is used by nuxt-oauth also redirects to the oauth provider.

I assume this is the same issue @setyoaji21 is seeing. Hopefully this makes sense and we can get this worked out.

samtgarson commented 5 years ago

@cedricium why does Reddit not successfully redirect you back to your callback URL?

The reason you get bounced out again when you hit it manually is that you don't have the required URL params that the OAuth provider should include when redirecting you back.

I would check what URL Reddit is redirecting you back to. It should be your callback URL with some URL params including token and some others.

iiAbady commented 5 years ago

this actually happend to me when I return a huge data on fetchUser hook.

samtgarson commented 5 years ago

@Abady321x123 could you provide some more detail? I'm not sure it's the same issue if it's happening during the fetchUser hook as that means the app has successfully authenticated initially.