13

我正在开发一个 Symfony2 应用程序。我正在使用 FOSUserBundle 处理身份验证,最近使用本教程将其与 FOSUserBundle 集成:https ://gist.github.com/danvbe/4476697 。

问题是:我可以在 localhost 上使用 google api 登录,一切正常。

但是,当我尝试登录真实服务器时,我得到:

Error: invalid_request

device_id and device_name are required for private IP: http://<server_ip>/login/check-google

请求详情:

response_type=code
scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
redirect_uri=http://<server_ip>/login/check-google
client_id=<my_id>

谷歌文档没有提到这两个参数。我尝试手动发送一个请求,其中 device_id 为 UUID,device_name 设置为“notes”。这次我得到的回应是:

Error: invalid_request

Device info can be set only for native apps.

请求详情:

cookie_policy_enforce=false
response_type=code
device_name=notes
scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
redirect_uri=http://<server_ip>/login/check-google
device_id=4b3403665fea6
client_id=<my_id>

现在,我做错了什么?

4

2 回答 2

4

在进行 Oauth 或 API 调用时,Google 不会接受本地(私有)IP 地址。我的解决方法是在我的 Windows 主机文件中为本地 IP 添加一个条目:

\Windows\System32\drivers\etc

192.168.1.2   fakedomain.com

然后在他们的开发控制台中向谷歌注册。这对他们来说似乎是一个“真实”域,但仍会在您的浏览器或代码中解析为本地 IP。我确信 Mac 或 Linux 上的类似方法也可以。

于 2014-09-24T16:11:40.173 回答
2

看起来您确实使用了错误的 oauth 风格。device_id 与Devices一起使用。我真的希望您使用WebServer流程​​。您可能需要其他流程之一,因为我在这里看不到足够的细节来判断,但它们都可以在链接中找到。

于 2014-07-09T23:52:21.297 回答