lib/omniauth/strategies/oauth2.rb in oa-oauth-0.2.5 vs lib/omniauth/strategies/oauth2.rb in oa-oauth-0.2.6
- old
+ new
@@ -47,11 +47,11 @@
def client
::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
end
def callback_url
- full_host + callback_path
+ full_host + script_name + callback_path
end
protected
def request_phase
@@ -62,35 +62,28 @@
if request.params['error'] || request.params['error_reason']
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
end
@access_token = build_access_token
+ @access_token = client.web_server.refresh_access_token(@access_token.refresh_token) if @access_token.expired?
- 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
-
super
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
fail!(:invalid_credentials, e)
rescue ::MultiJson::DecodeError => e
fail!(:invalid_response, e)
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
+ fail!(:timeout, e)
end
def build_access_token
verifier = request.params['code']
client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
end
def auth_hash
credentials = {'token' => @access_token.token}
- credentials.merge('refresh_token' => @access_token.refresh_token) if @access_token.expires?
+ credentials.merge!('refresh_token' => @access_token.refresh_token) if @access_token.expires?
OmniAuth::Utils.deep_merge(super, {'credentials' => credentials})
end
end
end