google / google-api-ruby-client-samples

Samples for the Google API Ruby Client
327 stars 164 forks source link

Problem with login - JWT #40

Closed renatocassino closed 8 years ago

renatocassino commented 8 years ago

Hello guys. I'm using this gem to make a login in analytics.

  scope="https://www.googleapis.com/auth/analytics.readonly"
  file = "#{File.expand_path File.dirname(__FILE__) }/../myfiletologin.p12"
  key = Google::APIClient::PKCS12.load_key(file, "keepthissecret")
  service_account = Google::APIClient::JWTAsserter.new("bigkeyclient@developer.gserviceaccount.com", scope, key)
  client.authorization = service_account.authorize # ERROR!

I'm receiving error:

#<Signet::AuthorizationError: Authorization failed.  Server message:
{
  "error" : "invalid_grant",
  "error_description" : "Invalid JWT: Token must be a short-lived token and in a reasonable timeframe"
}>

How can I do to solve this? What's a possible problem?

renatocassino commented 8 years ago

This code is deprecated:

Source: https://docs.omniref.com/ruby/gems/google-api-client/0.6.2/symbols/Google::APIClient::JWTAsserter#doc_uncollapsed=true&line=21

But the error keep for me

renatocassino commented 8 years ago

My date and time was wrong in my Mac! ¬¬'' Solved! Thanks!