【问题标题】:Google+ Domains API via service account fails with 403 Forbidden通过服务帐户的 Google+ Domains API 失败并出现 403 Forbidden
【发布时间】:2014-05-20 02:16:00
【问题描述】:

我有一个简单的 Ruby 代码,它是从几个示例中组合而成的。它使用 Google+ 域 API。我按照所有步骤授权服务帐户 (https://developers.google.com/+/domains/authentication/delegation),但我的请求失败并出现 403 Forbidden:

{"error"=>{"errors"=>[
{"domain"=>"global", "reason"=>"forbidden", "message"=>"Forbidden"}], 
"code"=>403, "message"=>"Forbidden"}}

如果我使用 Google APIs Explorer 控制台执行相同的查询,它们可以正常工作。我认为这与服务帐户与用户帐户身份验证有关。我错过了什么?

完整代码在这里https://github.com/admitriyev/propellant/blob/master/main.rb

[已编辑] 我在相同的代码中添加了一个已安装的应用程序流,它运行良好(完整代码在上面的 Gihub 上)。不过,我仍然不知道我在服务流程中错过了什么。

【问题讨论】:

  • 您为 Google API 选择了哪种身份验证和授权机制?例如如果您为此选择了 Google 的 OAuth 方案,则应首先获取身份验证令牌
  • @cvibha 我不完全理解你的问题。它是具有服务帐户和域委托的 OAuth2。它不起作用。但是,我只是将其修改为使用已安装的应用程序流程,并且运行良好。
  • 这里是使用 Google API 的第三方服务的link

标签: ruby google-api-ruby-client google-domain-api


【解决方案1】:

我想通了,我错过了应该授权的实际域用户的电子邮件。我还改用了 Google::APIClient::JWTAsserter,它更干净 抽象:

client_asserter = Google::APIClient::JWTAsserter.new(
  config['client_email'],
  PLUS_LOGIN_SCOPE,
  key
)
$client.authorization = client_asserter.authorize(config['user_email'])

我的完整示例在这里:https://github.com/admitriyev/propellant/blob/master/main.rb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2022-11-08
    • 2023-04-09
    • 1970-01-01
    • 2018-03-16
    相关资源
    最近更新 更多