Skip to content

Commit

Permalink
fix to refresh the access token properly
Browse files Browse the repository at this point in the history
no test!
  • Loading branch information
jugyo committed May 18, 2011
1 parent c34f9dc commit 43ecdfb
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions oa-oauth/lib/omniauth/strategies/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,7 @@ def callback_phase
end

@access_token = build_access_token

if @access_token.expires? && @access_token.expires_in <= 0
client.request(:post, client.access_token_url, {
'client_id' => client_id,
'grant_type' => 'refresh_token',
'client_secret' => client_secret,
'refresh_token' => @access_token.refresh_token
}.merge(options))
@access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
end
@access_token = client.web_server.refresh_access_token(@access_token.refresh_token) if @access_token.expired?

super
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
Expand All @@ -84,11 +75,8 @@ def callback_phase
fail!(:timeout, e)
end

def verifier
request.params['code']
end

def build_access_token
verifier = request.params['code']
client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
end

Expand Down

0 comments on commit 43ecdfb

Please sign in to comment.