From aa51114e8a2642b32e9b0573b842ea5e8a18153d Mon Sep 17 00:00:00 2001 From: Seth Call Date: Thu, 8 Oct 2015 11:36:16 -0500 Subject: [PATCH] * deal with no refresh token better --- .../lib/jam_ruby/models/user_authorization.rb | 26 +++++++++---------- .../stores/VideoUploaderStore.js.coffee | 4 +++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ruby/lib/jam_ruby/models/user_authorization.rb b/ruby/lib/jam_ruby/models/user_authorization.rb index 10b126d75..f4c1523eb 100644 --- a/ruby/lib/jam_ruby/models/user_authorization.rb +++ b/ruby/lib/jam_ruby/models/user_authorization.rb @@ -21,22 +21,22 @@ module JamRuby 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", - :token_url => "/o/oauth2/token", - :authorize_url => "/o/oauth2/auth") - access_token = OAuth2::AccessToken.from_hash(oauth_client, {:refresh_token => auth.refresh_token}) - access_token = access_token.refresh! + oauth_client = OAuth2::Client.new( + Rails.application.config.google_client_id, Rails.application.config.google_secret, + :site => "https://accounts.google.com", + :token_url => "/o/oauth2/token", + :authorize_url => "/o/oauth2/auth") + access_token = OAuth2::AccessToken.from_hash(oauth_client, {:refresh_token => auth.refresh_token}) + access_token = access_token.refresh! + + auth.token = access_token.token + auth.token_expiration = Time.now + access_token.expires_in + auth.save + return auth rescue Exception => e # couldn't refresh; probably the user has revoked the app's rights - nil + return nil end - - auth.token = access_token.token - auth.token_expiration = Time.now + access_token.expires_in - auth.save - auth else auth end diff --git a/web/app/assets/javascripts/react-components/stores/VideoUploaderStore.js.coffee b/web/app/assets/javascripts/react-components/stores/VideoUploaderStore.js.coffee index cf6f6f375..1a93887ba 100644 --- a/web/app/assets/javascripts/react-components/stores/VideoUploaderStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/VideoUploaderStore.js.coffee @@ -204,6 +204,10 @@ VideoUploaderActions = @VideoUploaderActions VideoUploaderStore.errorReason = reason VideoUploaderStore.errorDetail = detail + # if reason == "create_video_failed" && errorDetail = "401" + # then don't trigger state, instead ask server for a fresh token + # + VideoUploaderStore.triggerState() } )