在尝试将Legato gem与service accounts一起使用时,我们收到来自Google Authorization failed. Server message: { "error" : "invalid_grant” }
的错误。
def token
OAuth2::AccessToken.new(oauth_client, client_authorization.access_token,
expires_in: 1.hour
)
end
def oauth_client
OAuth2::Client.new("", "", {
authorize_url: "https://accounts.google.com/o/oauth2/auth",
token_url: "https://accounts.google.com/o/oauth2/token",
})
end
def client_authorization
@_client_authorization ||= client.authorization = service_account.authorize
end
def service_account
Google::APIClient::JWTAsserter.new({{ secret email address }},
"https://www.googleapis.com/auth/analytics.readonly",
key)
end
def key
Google::APIClient::KeyUtils.load_from_pem({{ secret keyfile path }}, {{ not so secret keyfile passphrase }})
end
def client
Google::APIClient.new(
application_name: {{ app name }},
application_version: 1,
)
end
我们知道一些事情:
假设问题: