* dont let refresh attempt bust API

This commit is contained in:
Seth Call 2015-10-08 07:50:20 -05:00
parent 276442a9b4
commit 509cc56cdb
1 changed files with 6 additions and 1 deletions

View File

@ -20,6 +20,7 @@ module JamRuby
# if we have an auth that will expire in less than 10 minutes
if auth && auth.refresh_token && auth.token_expiration < Time.now - 60 * 10
begin
oauth_client = OAuth2::Client.new(
Rails.application.config.google_client_id, Rails.application.config.google_secret,
:site => "https://accounts.google.com",
@ -27,8 +28,12 @@ module JamRuby
:authorize_url => "/o/oauth2/auth")
access_token = OAuth2::AccessToken.from_hash(oauth_client, {:refresh_token => auth.refresh_token})
access_token = access_token.refresh!
rescue Exception => e
# couldn't refresh; probably the user has revoked the app's rights
nil
end
auth.token = access_token.token
puts "access_token #{Time.now + access_token.expires_in} #{access_token.expires_in}"
auth.token_expiration = Time.now + access_token.expires_in
auth.save
auth