Class: OmniAuth::Strategies::Auth

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

Direct Known Subclasses

Sina

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



18
19
20
# File 'lib/omniauth/strategies/auth.rb', line 18

def access_token
  @access_token
end

Instance Method Details

#callback_phaseObject



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

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



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

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



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

def request_phase
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
  session['oauth'] ||= {}
  session['oauth'][name.to_s] = {'callback_confirmed' => options[: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