Google 隐式 Oauth 流上的操作失败...出了啥问题?

Posted

技术标签:

【中文标题】Google 隐式 Oauth 流上的操作失败...出了啥问题?【英文标题】:Actions On Google Implicit Oauth Flow fails...What's wrong?Google 隐式 Oauth 流上的操作失败...出了什么问题? 【发布时间】:2019-04-24 10:53:19 【问题描述】:

我正在为此处定义的隐式 oauth 流实现我自己的 Oauth 服务器 https://developers.google.com/actions/identity/oauth2?oauth=implicit

看起来很简单,在检查客户详细信息后,我只需要重定向对吗?这就是我遇到问题的地方。文档说重定向 url 必须如下 -

https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID#access_token=ACCESS_TOKEN&token_type=bearer&state=STATE_STRING

注意 '#'

但是,当您重定向到此 URL 时,这似乎奇怪地弄乱了 google 上的操作,之后我们之前使用的“登录助手”意图暂时似乎起作用,然后失败了。它一定是失败了,但控制台没有显示任何错误

事实上,这个问题仍然存在,我发现删除它的唯一方法是重新创建项目。 (哦,痛苦:/)

但是,当我将“#”替换为“?”时像常规查询字符串一样,重定向后我们会收到 400 错误 -

查询字符串中必须设置参数“code”或“error”。

我不确定我在这里做错了什么。作为参考,这是构造重定向 url 的 JS -

//bearerToken already generated at this point in the code
var redirectUri = params.get("redirect_uri");
var state = params.get("state");
var redirectString = redirectUri;
redirectString+="#access_token="+bearerToken;
redirectString+="&token_type=bearer";
redirectString+="&state="+state;
window.location.href=redirectString;

【问题讨论】:

您是否尝试过将access_token 参数改为code 【参考方案1】:

我所做的唯一与你不同的事情是使用 window.location.replace 而不是 window.location.href

据我了解,window.location.replace 是模拟 HTTP 重定向的客户端方式。

我的网址看起来像这样https://oauth-redirect.googleusercontent.com/r/project-id#access_token=4cc355t0k3n&token_type=bearer&state=AB8b_TOEy...

【讨论】:

以上是关于Google 隐式 Oauth 流上的操作失败...出了啥问题?的主要内容,如果未能解决你的问题,请参考以下文章

Google Play 游戏服务测试 - OAuth 失败?

Google云端硬盘访问 - 服务帐户或OAuth - 读取/写入用户文件

Google Play 游戏服务 - 登录失败(OAUTH2:UNREGISTERED_ON_API_CONSOLE)

在 google plus 流上发帖

什么是 google oauth 同意屏幕值?

Google oAuth2 令牌越来越失效