I'm trying to use the ruby client for google apis to access cloud storage and invariably I get the following error:
/usr/local/lib/ruby/gems/1.9.1/gems/signet-0.4.5/lib/signet/oauth_2/client.rb:875:in `fetch_access_token': Authorization failed. Server message: (Signet::AuthorizationError)
{
"error" : "invalid_scope"
}
I've followed the (slightly different) examples both on github and the google developers pages for the api client with the same result. Here's the code from both instances:
require 'google/api_client'
apiClient = Google::APIClient.new({'application_name' => 'myApp'})
key = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret')
client = "xxxxxxxxxxxx@developer.gserviceaccount.com"
api = "https://www.googleapis.com/auth/"
access = "devstorage.readonly"
service_account = Google::APIClient::JWTAsserter.new(client, api+access, key)
client.authorization = service_account.authorize
I also get the same error if I try....
require 'google/api_client'
apiClient = Google::APIClient.new({'application_name' => 'myApp'})
key = Google::APIClient::KeyUtils.load_from_pkcs12('client.p12', 'notasecret')
client = "xxxxxxxxxxxx@developer.gserviceaccount.com"
api = "https://www.googleapis.com/auth/"
access = "devstorage.readonly"
apiClient.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => "#{api}#{access}",
:issuer => client,
:signing_key => key)
apiClient.authorization.fetch_access_token!
In both cases I've tried setting the access variable to 'storage', 'devstorage', 'storage.readonly' or 'devstorage.readonly' also to no avail.
Any ideas?
Thanks!