我们正在使用具有域范围授权的 Google API Ruby 客户端来更新用户的联系人,解析电子邮件以将它们与我们的数据库配对等。在 4 月 1 日之前一切正常,但是,从那时起我们得到了unauthorized_client
错误响应。
Signet::AuthorizationError (Authorization failed. Server message:)
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
}
我已经尝试了什么?
我已经尝试更新google-api-ruby-client
和googleauth
宝石到最新版本。没有改变。
我还尝试(两次)生成新的服务帐户,为 DWD 启用它,并使用服务帐户的客户端 ID 在 G Suite 管理控制台中添加所需的范围。在管理控制台中添加范围后,我等待了 24 小时,但没有任何改变。
请注意,过去使用相同的设置一切正常。
最少的测试代码
这是引发错误的最小代码。
require 'googleauth'
require 'google/apis/gmail_v1'
creds = ENV['GOOGLE_SERVICE_ACCOUNT'] # JSON downloaded from cloud console
# is saved in this ENV variable
creds_json = JSON.parse(creds)
creds_json_io = StringIO.new(creds_json.to_json)
auth = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: creds_json_io,
scope: [Google::Apis::GmailV1::AUTH_GMAIL_MODIFY]
)
auth.sub = 'admin@slideslive.com' # without this line everything works fine
# and I get the access token
auth.fetch_access_token
据我所知,我们正在根据可用的文档做所有事情。请问有人有什么建议吗?
更新
我还尝试在同一组织下创建一个新的 Google Cloud Platform 项目,只添加了服务帐户,但一切都保持不变。