* deal with no refresh token better

This commit is contained in:
Seth Call 2015-10-08 11:36:16 -05:00
parent 509cc56cdb
commit aa51114e8a
2 changed files with 17 additions and 13 deletions

View File

@ -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

View File

@ -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()
}
)