Comments (5)
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.
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.
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.
@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.
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)
- No longer 'other' type HOT 2
- badRequest: The requested conversion is not supported. (Google::Apis::ClientError) HOT 2
- Google::Apis::ClientError: forbiddenForServiceAccounts: Service accounts cannot invite attendees without Domain-Wide Delegation of Authority HOT 1
- Support for attributes on ApplicationPolicy (androidmanagement_v1) HOT 1
- Rails console freezes when using gmail api gem HOT 6
- Is there a way of use addressvalidation using this gem? HOT 1
- NoMethodError: undefined method `discovered_api' for nil:NilClass HOT 1
- list_generatedapks issus
- `forbidden` exception when calling `commit_edit` HOT 1
- Need to support dataset.list and jobs.list API new field feature
- Vertex API (gemini-pro model) undefined method `has_key?' for ...
- add hook for http requests
- Google::Apis::Core::BaseService#root_url documented as an Addressable::URI, now treated as String HOT 3
- uninitialized constant Google::Apis::Core::DownloadCommand::Pathname HOT 2
- Adsense generate_account_report_csv returns nil due to content_type
- Support for Method: presentations.pages.getThumbnail in Slides HOT 2
- 404 not found HOT 1
- Insert table request is not able to copy already created table and paste it in another doc
- Add `Errno::ECONNRESET` to retriable network errors HOT 2
- Causing many GRPC requests per calling discovery engine search api once HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-api-ruby-client.