问题描述
我正在将 Google Oauth2 添加到 Rails 应用中,但一直无法通过早期阶段.
I'm adding Google Oauth2 to a Rails app, but have been unable to get past the early stages.
我已经设置了一个应用程序,并定义了客户端 ID 和密码.但是我得到了 Invalid parameter value for redirect_uri: Non-public domain not allowed: http://localhost/path/to/callback
I've set up an app, and defined client ID and secret.But I'm getting Invalid parameter value for redirect_uri: Non-public domains not allowed: http://localhost/path/to/callback
这是什么意思?这是因为我正在本地开发环境中进行测试吗?
What does this mean? Is this because I'm testing on a local dev environment?
感谢您的任何想法.
编辑
这可能是因为应用的 URI 与发送 URI 不同.但是当我去 Google 并尝试授权我的开发应用程序的路径时,我得到 OAuth2 重定向无效
.这是使用本地托管应用程序的限制吗?
This might be because the app's URI differs from the sending URI. But when I go to Google and try to authorize the path to my dev app, I get OAuth2 redirect is invalid
. Is this a limitation of using a locally hosted app?
编辑 2
我生成的请求如下所示:
The request I'm generating looks like this:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=###########&redirect_uri=http%3A%2F%2Fmyapp.dev%2Fusers%2Fauth%2Fgoogle_oauth2%2Fcallback&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&approval_prompt=&access_type=offline
这是正确的.我已经尝试使用 client_id 包括和排除 .apps.googleusercontent.com
部分.两者似乎都不起作用.
Is this correct. I've tried this with client_id including and excluding the .apps.googleusercontent.com
section. Neither seems to work.
推荐答案
对于发现此问题的其他人,我的问题是几个问题的组合.
For anyone else finding this, my problem was combination of several things.
我无法在本地机器上获得回调.控制台 API 控制台表明这是可能的,但我无法让它工作.不确定这与服务有关,还是与我的网络/连接/防火墙/等有关.
I could not get callbacks to work on a local machine. The console API console suggests it is possible, but I couldn't get it working. Not sure of this is down to the service, or to my network/ connection/ firewall/ etc.
在 API 控制台中,您必须指定完整的重定向 URI,而不仅仅是返回应用程序的根 url.
In the API console you must specify the full redirect URI, not just the root url back to your app.
Google 在此处列出范围参数 https://developers.google.com/gdata/常见问题#AuthScopes.此信息似乎已过时,这些信息的正确格式现在是 https://www.googleapis.com/auth/plus.me、https://www.googleapis.com/auth/youtube 等.也许其他人可以确认这一点?
Google lists scope parameters here https://developers.google.com/gdata/faq#AuthScopes. It seems this information is outdated, and the correct format for these is now https://www.googleapis.com/auth/plus.me, https://www.googleapis.com/auth/youtube, etc. Maybe someone else can confirm this?
我还有其他一些事情要做.我在 SO 上写了关于我的另一个问题的完整解释.不幸的是,我的评论被删除而不是被版主移动,因为我发错了地方.我现在不记得我写的所有内容了.对于其他面临类似问题的人,请随时发表评论,它可能会勾起我的记忆,以便我提供一些想法.
I had a few other things going on as well. I had written a full explanation on another of my questions here on SO. Unfortunately my comments were deleted instead of moved by a moderator because I posted in the wrong place. I can't now remember all that I wrote. For others facing similar issue, feel free to comment, it may jog my memory so I can offer some ideas.
这篇关于为什么 Google Oauth 在我的 Rails 应用程序中返回“无效的redirect_urI"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!