【发布时间】:2015-10-09 23:04:34
【问题描述】:
直到最近(即我相信是几个月),我们仅使用我们的 Oauth2 消费者密钥和秘密就能够成功地针对 https://www.googleapis.com/appsmarket/v2/customerLicense 和 https://www.googleapis.com/appsmarket/v2/licenseNotification 发出 GET 请求。
这些请求现在失败,状态为 401,正文如下:
{"error"=>{"code"=>401, "message"=>"Invalid OAuth consumer key", "errors"=>[{"message"=>"Invalid OAuth consumer key", "reason"=>"authError", "locationType"=>"header", "domain"=>"global", "location"=>"Authorization"}]}}
这是我们生成 licenseNotification 请求的 Ruby 代码
def self.google_apps_licenses(since=Time.zone.now-10.years)
oauth_consumer = OAuth::Consumer.new(GOOGLE_APPS_MARKETPLACE_CONSUMER_KEY_V2, GOOGLE_APPS_MARKETPLACE_CONSUMER_SECRET_V2)
access_token = OAuth::AccessToken.new(oauth_consumer)
response = access_token.get("https://www.googleapis.com/appsmarket/v2/licenseNotification/#{GOOGLE_APPS_MARKETPLACE_APPLICATION_ID_V2}?timestamp=#{(since.to_i * 1000)}")
result = JSON.parse(response.body)
end
任何帮助将不胜感激。我们现在需要用我们的证书签名还是使用 JWT 断言?奇怪的是,这在某一时刻起作用然后停止了。
【问题讨论】:
-
我认为消费者密钥和秘密与 Oauth 1.0 一起使用,该 Oauth 1.0 已于 2015 年 4 月 20 日弃用并停止工作。您必须使用 Oauth 2.0。 support.google.com/a/answer/162105?hl=en
-
嗨@gerado 谢谢你的回复!可能的愚蠢问题:应用程序如何发出不代表用户的 Oauth2 请求?
-
要授权用户,您可以使用正常的 Oauth 2 流程。您必须创建凭据,并使用这些凭据对用户进行身份验证。查看相关文档:developers.google.com/identity/protocols/OAuth2 并查看 Oauth Playground,您可以在其中逐步查看流程:developers.google.com/oauthplayground