【问题标题】:Google OAuth - Incorrect JSON while Validating Access TokenGoogle OAuth - 验证访问令牌时 JSON 不正确
【发布时间】:2015-05-28 00:00:58
【问题描述】:

我从发送到服务器的 Android SDK 获取访问令牌。在服务器端,我正在调用以下 API 来验证我的令牌:

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=<token here>

来自 Google,我收到以下回复(添加了部分回复):

{\"statusCode\":200,\"body\":\"{n \"issued_to\": 
\"407408718192.apps.googleusercontent.com\",n \"audience\":
\"407408718192.apps.googleusercontent.com\",n \"user_id\": 
\"110586055381870434283\",n \"scope\": 
\"https://www.googleapis.com/auth/plus.login 
https://www.googleapis.com/auth/plus.me"}

不幸的是,这个 JSON 不可解析,因为有反斜杠,我无法验证令牌身份。

这是 Google API 的问题还是我需要应用任何正则表达式?

【问题讨论】:

  • 您能找到解决方案吗?我有同样的问题。

标签: json node.js oauth google-oauth


【解决方案1】:

Google 会发回不带斜线的正确 JSON,这正是您粘贴的输出的“正文”元素内的部分(当然不带斜线)。

因此,您的 Node.js HTTP 客户端使用 HTTP 状态代码元素将其包装起来并放入斜杠,因此您的客户端需要自行将其转换回来。

【讨论】:

  • 有什么方法可以将其转换回来?我找不到解决办法
  • 不只是打印输出添加了斜线吗?你在哪里/如何打印出来?
  • 我在响应本身中得到了斜杠。我正在使用 npm 模块“请求”来访问 API。响应由 JSON.stringify() 打印
猜你喜欢
  • 1970-01-01
  • 2019-08-08
  • 1970-01-01
  • 2013-05-26
  • 2021-04-03
  • 1970-01-01
  • 2017-06-09
  • 2014-03-19
  • 1970-01-01
相关资源
最近更新 更多