Trouble with Google Apps API and Service Accounts in Ruby

Trouble with Google Apps API and Service Accounts in Ruby

This looks to me like you are using an older example. I think that's how you used to do it about a year ago. Back in late 2012 that method of setting up the app was deprecated because Signet was updated to handle all aspects of the OAuth2 setup.

Here is the code I generally use to create a service account. You can tweak it to fit into your method.

client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => "https://www.googleapis.com/auth/drive",
:issuer => "<service account email>@developer.gserviceaccount.com",
:signing_key => Google::APIClient::KeyUtils.load_from_pkcs12("<private key file>-privatekey.p12", "notasecret"),
:person => "<users email address>")
client.authorization.fetch_access_token!

If you are still having issues let me know and I'll see if I can help.

How to set the Google API user to impersonate using a Service Account (Ruby Client)?

Here's the summary.

Do not use the OAuth2 gem from intridea if you are only trying to authenticate with Google. Rely on the signet Gem.

If you use a service account, you can specify a :person element and it will work so you impersonate that user and work on their behalf.

When you test your integration you must do so against the domain in which your project is hosted. You cannot test in a third-party domain until you've published your app!



Related Topics



Leave a reply



Submit