Google oauth2将子域重定向请求到主域

huangapple go评论79阅读模式
英文:

Google oauth2 redirecting requests from subdomain to main domain

问题

I have a domain, https://faduense.com, where I have succesfully implemented login with google Oauth2 using passport. The app is a Mern App, which handles login via the API done in Node.

现在,由于应用程序有点重,我想将我的应用程序移到子域 https://app.faduense.com,我已经这样做了,它在自己的服务器上运行。

问题出在以下地方:我已经在我的前端和后端内部更改了所有设置,但当我点击使用Google登录时,它仍然将我的请求发送到主域 https://faduense.com

我甚至尝试通过Google控制台创建不同的应用程序,并放置新的客户端和秘密ID,但它仍然通过主域路由。

以下是我的设置:
Passport 设置。

Google oauth2将子域重定向请求到主域

我的用户 API 路由,指向 https://app.faduense.com/api/users/

Google oauth2将子域重定向请求到主域

以及我的前端弹出窗口如下。Google oauth2将子域重定向请求到主域

最后,我的凭据如下所示:
Google oauth2将子域重定向请求到主域

我不知道该说什么了。
我已经尝试过的事情,

我尝试更改Google控制台中创建的主域应用程序的重定向URI,但出现了redirect_uri_mismatch错误。

我尝试将我的子域重定向URI添加到Google控制台中创建的主域应用程序中,但没有任何效果。

我尝试操纵通过浏览器地址栏发送的参数,但没有成功。

如果您转到 https://app.faduense.com/login 并单击通过Google登录,请求URL将发送到以下URL:https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=https%3A%2F%2Ffaduense.com%2Fapi%2Fusers%2Fauth%2Fgoogle%2Fusuario&scope=profile%20email&client_id=54622388608-9ml71v7gsj9f2avru52hpgmh0auudbur.apps.googleusercontent.com

您可以清楚地看到重定向URI缺少子域。
我没有太多经验,我已经搜索了很多,但我认为我唯一的出路是寻求更有经验的人的帮助。
有什么线索吗?
谢谢

英文:

I have a domain, https://faduense.com, where I have succesfully implemented login with google Oauth2 using passport. The app is a Mern App, which handles login via the API done in Node.

Now, since the app is a bit heavy, I want to move my app to the subdomain, https://app.faduense.com, which I already did, its working in its own server.

The issue comes to the following: I've changed all my settings inside my back and front end, but when I press login with google it still sends my requests to the main domain: https://faduense.com

I even tried creating a different app through the google console, and putting a new client and secret ID, but it still routes it via the main domain.

These are my settings:
Passport settings.

Google oauth2将子域重定向请求到主域

My user API routes which go to https://app.faduense.com/api/users/

Google oauth2将子域重定向请求到主域

And my popup on the front end which looks the following.Google oauth2将子域重定向请求到主域

Finally my credentials which look like this:
Google oauth2将子域重定向请求到主域

I am at loss of words.
What I have done,

I tried changing my redirect uri in the main domain app created at google console, which gave the redirect_uri_mismatch error

I tried adding my subdomain redirect uri to the main domain app created at google console, that did nothing.

I tried to manipulate the parameters sent via the browser adress bar, to no avail.

If you go to https://app.faduense.com/login and click on login via google, the request url sends the following url: https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=https%3A%2F%2Ffaduense.com%2Fapi%2Fusers%2Fauth%2Fgoogle%2Fusuario&scope=profile%20email&client_id=54622388608-9ml71v7gsj9f2avru52hpgmh0auudbur.apps.googleusercontent.com

You can see the redirect_uri clearly is missing the subdomain.
I do not have much experience, I have searched a lot, but I see my only way out here is to ask someone with more experience.
Any clues?
thanks

答案1

得分: 0

I'm here to provide the translated content. Here it is:

最终问题解决了。
我不知道具体是怎么解决的,但这是我做的:

  1. 首先,我在Google API控制台中删除了凭据。

  2. 然后,我直接使用我的子域名URL创建了新的凭据。

  3. 我在Passport JS中更改了我的秘密和客户端ID,还在前端更改了我的URL。

  4. 在开发环境中进行测试,出现了redirect_uri错误,但这没关系,因为我在使用localhost,并且我的凭据已设置为最终的URL。

  5. 我使用Putty进入了我的EC2实例,运行了sudo systemctl stop nginx来停止服务器。

  6. 我从GitHub中拉取了带有新凭据的更新存储库。

  7. 在AWS面板上重新启动了实例。

  8. 最后,我再次启动了Nginx,运行了sudo systemctl start nginx。

  9. 在线上测试,一切正常运行。

英文:

Finally I solved it.
I do not know how exactly I did it, but this is what I did:

  1. First, I deleted the credentials in the google api console.

  2. Then I created new credentials directly with my subdomain url.

  3. I changed my secret and client id on passport JS; as well as changing my url on the frontend.

  4. Tested in dev enviroment, was getting a redirect_uri error, but thats ok, since I was using localhost, and my credentials were set with my final url.

  5. Used putty to get into my EC2 instance, I did sudo systemctl stop nginx, to stop the server.

  6. I pulled my updated repo from github with the new secret, and client ID from the new credentials.

  7. Rebooted the instance on AWS panel.

  8. Finally, I started nginx again, sudo systemctl start nginx.

  9. Test it live, and its working.

huangapple
  • 本文由 发表于 2020年1月7日 01:38:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616567.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定