【问题标题】:Google APIs OAuth refresh token url return 401 on http redirect uri?Google APIs OAuth 刷新令牌 url 在 http 重定向 uri 上返回 401?
【发布时间】:2018-06-25 21:13:32
【问题描述】:

我已经按照此步骤中的描述实现了接收授权码的代码:

https://developers.google.com/android-publisher/authorization#generating_a_refresh_token

我们将此代码部署到具有“https://...”域的一台服务器上,并且运行良好。我们可以获取access_token、refresh_token...

但现在我们需要将相同的代码部署到没有“https”的开发服务器上。

我使用开发服务器创建了一个带有重定向 uri 的新 OAuth 客户端 ID(没有 https,其余的 /api/v1/... 与之前的工作服务器相同)

现在每当我尝试访问此网址并允许访问时

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://dev_server/api/v1/...&client_id=dev_server_client_id

我得到了 401 Unauthorized。

我不知道为什么,但我能看到的唯一区别是“https”与“http”。

知道为什么吗? 非常感谢。

【问题讨论】:

  • 您在 Google 开发控制台中用于生产和开发的重定向 uri 是什么样的?我不认为问题出在 https
  • 谢谢@DaImTo。我的控制台中的值是正确的,但我忘了更新我的 .env 文件中的值

标签: google-api google-oauth google-api-nodejs-client


【解决方案1】:

其实我忘记更新代码中的对应值了

const oauth2Client = new OAuth2(
    config.googleApi.clientId,
    config.googleApi.clientSecret,
    config.googleApi.redirectUri // <= Especially this value
);

这些值需要更新为(除了谷歌控制台上的值)。

【讨论】:

    猜你喜欢
    • 2021-11-21
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 2013-05-10
    • 2020-07-21
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多