Giter VIP home page Giter VIP logo

Comments (5)

sporkmonger avatar sporkmonger commented on June 10, 2024

I'll investigate, but to some degree, this is "won't fix" because the approach you've taken is actually the correct approach in the overwhelming majority of cases. I am actually sorely tempted to remove the expiration methods entirely, but they can be useful for debugging.

The reason you want to do what you're doing (and why it's correct and not just a work-around) is because you want to avoid single points of failure. For example, let's say the token server dies but the APIs stay up. In a scenario like that, the provider of the API might elect to honor access tokens beyond their expiration while the token server is being restored to service.

from google-api-ruby-client.

sporkmonger avatar sporkmonger commented on June 10, 2024

As a compromise, I might alternatively mark the expiration methods as a "private" API method along with a note explaining it in the documentation. A bunch of our examples use the expiration check because it makes them easier to write, but we probably ought to just make them correct instead.

from google-api-ruby-client.

International avatar International commented on June 10, 2024

Thank you for taking the time to answer. I understand your explanation, and it makes perfect sense.The reason why I was thinking of this as a workaround is that when you're using a non-paid account, you lose one of those 5hits/second making a call just to see if the access token is still valid.
But, I can live with it :)

from google-api-ruby-client.

le0pard avatar le0pard commented on June 10, 2024
  @client.authorization.code = options[:oauth][:authorization_code]
  @client.authorization.update_token!(options[:oauth][:token_pair]) if options[:oauth][:token_pair]
  if @client.authorization.refresh_token && @client.authorization.expired?
    @client.authorization.fetch_access_token!
  end

The refresh after expire of not work.

Authorization failed.  Server message:
{
  "error" : "invalid_grant"
}
/Users/leo/.rvm/gems/ruby-1.9.3-p286/gems/signet-0.4.3/lib/signet/oauth_2/client.rb:725:in `fetch_access_token'
/Users/leo/.rvm/gems/ruby-1.9.3-p286/gems/signet-0.4.3/lib/signet/oauth_2/client.rb:738:in `fetch_access_token!'

How to fix this now?

token_pair data:

token_pair: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  refresh_token: 1/ZCkkpwbvOk2K8ms6mDfSIuAuTPCw_ceKhxXL6bd5Jdk
  access_token: ya29.AHES6ZTab9VNtWpkc8XBZbMHUFtZBg_3Gimo9swNUEYourbX0KcN8A
  expires_in: 3600
  issued_at: 2012-10-19 13:19:43.000000000 +03:00

from google-api-ruby-client.

sporkmonger avatar sporkmonger commented on June 10, 2024

So, going forward, I'd recommend using OmniAuth, as used in the Google+ sample application. That should largely solve this problem. I'm still planning to mark the various expiration methods as a private part of the API (so I'm not closing this issue yet).

@le0pard Basically, don't call the expired? method. There are essentially zero scenarios where that's a good idea. It simply won't give you reliable expiration information. It's more of a hint than a real expiration timestamp, and the token server may decide to honor an expired token anyways in certain somewhat theoretical, but important, circumstances. If you do get an invalid grant error, always refresh your access token and retry once. If you're still getting an error, raise the error.

from google-api-ruby-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.