英文:
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 设置。
我的用户 API 路由,指向 https://app.faduense.com/api/users/
我不知道该说什么了。
我已经尝试过的事情,
我尝试更改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.
My user API routes which go to https://app.faduense.com/api/users/
And my popup on the front end which looks the following.
Finally my credentials which look like this:
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:
最终问题解决了。
我不知道具体是怎么解决的,但这是我做的:
-
首先,我在Google API控制台中删除了凭据。
-
然后,我直接使用我的子域名URL创建了新的凭据。
-
我在Passport JS中更改了我的秘密和客户端ID,还在前端更改了我的URL。
-
在开发环境中进行测试,出现了redirect_uri错误,但这没关系,因为我在使用localhost,并且我的凭据已设置为最终的URL。
-
我使用Putty进入了我的EC2实例,运行了sudo systemctl stop nginx来停止服务器。
-
我从GitHub中拉取了带有新凭据的更新存储库。
-
在AWS面板上重新启动了实例。
-
最后,我再次启动了Nginx,运行了sudo systemctl start nginx。
-
在线上测试,一切正常运行。
英文:
Finally I solved it.
I do not know how exactly I did it, but this is what I did:
-
First, I deleted the credentials in the google api console.
-
Then I created new credentials directly with my subdomain url.
-
I changed my secret and client id on passport JS; as well as changing my url on the frontend.
-
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.
-
Used putty to get into my EC2 instance, I did sudo systemctl stop nginx, to stop the server.
-
I pulled my updated repo from github with the new secret, and client ID from the new credentials.
-
Rebooted the instance on AWS panel.
-
Finally, I started nginx again, sudo systemctl start nginx.
-
Test it live, and its working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论