Class: OmniAuth::Strategies::OAuth

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/oauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token


19
20
21
# File 'lib/omniauth/strategies/oauth.rb', line 19

def access_token
  @access_token
end

Instance Method Details

#callback_phaseObject


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/omniauth/strategies/oauth.rb', line 45

def callback_phase
  raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil?

  request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))

  opts = {}
  if session['oauth'][name.to_s]['callback_confirmed']
    opts[:oauth_verifier] = request['oauth_verifier']
  else
    opts[:oauth_callback] = callback_url
  end

  @access_token = request_token.get_access_token(opts)
  super
rescue ::Timeout::Error => e
  fail!(:timeout, e)
rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
  fail!(:service_unavailable, e)
rescue ::OAuth::Unauthorized => e
  fail!(:invalid_credentials, e)
rescue ::MultiJson::DecodeError => e
  fail!(:invalid_response, e)
rescue ::OmniAuth::NoSessionError => e
  fail!(:session_expired, e)
end

#consumerObject


21
22
23
24
25
26
# File 'lib/omniauth/strategies/oauth.rb', line 21

def consumer
  consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
  consumer.http.open_timeout = options.open_timeout if options.open_timeout
  consumer.http.read_timeout = options.read_timeout if options.read_timeout
  consumer
end

#request_phaseObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omniauth/strategies/oauth.rb', line 28

def request_phase
  request_token = consumer.get_request_token({:oauth_callback => callback_url}, options.request_params)
  session['oauth'] ||= {}
  session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}

  if request_token.callback_confirmed?
    redirect request_token.authorize_url(options[:authorize_params])
  else
    redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
  end

rescue ::Timeout::Error => e
  fail!(:timeout, e)
rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
  fail!(:service_unavailable, e)
end