From 509cc56cdb774983aa7083e08b786d3687a7daf9 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Thu, 8 Oct 2015 07:50:20 -0500 Subject: [PATCH] * dont let refresh attempt bust API --- ruby/lib/jam_ruby/models/user_authorization.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ruby/lib/jam_ruby/models/user_authorization.rb b/ruby/lib/jam_ruby/models/user_authorization.rb index 7dfa2168c..10b126d75 100644 --- a/ruby/lib/jam_ruby/models/user_authorization.rb +++ b/ruby/lib/jam_ruby/models/user_authorization.rb @@ -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