Class: OmniAuth::Strategies::XAuth
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::XAuth
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/xauth.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_options ⇒ Object
Returns the value of attribute consumer_options.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #callback_phase ⇒ Object
- #consumer ⇒ Object
- #get_credentials ⇒ Object
-
#initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block) ⇒ XAuth
constructor
A new instance of XAuth.
- #request_phase ⇒ Object
Constructor Details
#initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block) ⇒ XAuth
Returns a new instance of XAuth.
12 13 14 15 16 17 |
# File 'lib/omniauth/strategies/xauth.rb', line 12 def initialize(app, name, consumer_key=nil, consumer_secret=nil, ={}, ={}, &block) self.consumer_key = consumer_key self.consumer_secret = consumer_secret self. = super end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
8 9 10 |
# File 'lib/omniauth/strategies/xauth.rb', line 8 def consumer_key @consumer_key end |
#consumer_options ⇒ Object
Returns the value of attribute consumer_options.
8 9 10 |
# File 'lib/omniauth/strategies/xauth.rb', line 8 def @consumer_options end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
8 9 10 |
# File 'lib/omniauth/strategies/xauth.rb', line 8 def consumer_secret @consumer_secret end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/omniauth/strategies/xauth.rb', line 7 def name @name end |
Instance Method Details
#auth_hash ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/omniauth/strategies/xauth.rb', line 53 def auth_hash OmniAuth::Utils.deep_merge(super, { 'credentials' => { 'token' => @access_token.token, 'secret' => @access_token.secret }, 'extra' => { 'access_token' => @access_token } }) end |
#callback_phase ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omniauth/strategies/xauth.rb', line 40 def callback_phase @access_token = consumer.get_access_token(nil, {}, session['omniauth.xauth']) super rescue ::Net::HTTPFatalError => e fail!(:service_unavailable, e) rescue ::OAuth::Unauthorized => e fail!(:invalid_credentials, e) rescue ::MultiJson::DecodeError => e fail!(:invalid_response, e) ensure session['omniauth.xauth'] = nil end |
#consumer ⇒ Object
36 37 38 |
# File 'lib/omniauth/strategies/xauth.rb', line 36 def consumer ::OAuth::Consumer.new(consumer_key, consumer_secret, .merge([:client_options] || [:consumer_options] || {})) end |
#get_credentials ⇒ Object
29 30 31 32 33 34 |
# File 'lib/omniauth/strategies/xauth.rb', line 29 def get_credentials OmniAuth::Form.build([:title] || "xAuth Credentials") do text_field 'Username', 'username' password_field 'Password', 'password' end.to_response end |
#request_phase ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/omniauth/strategies/xauth.rb', line 19 def request_phase session['oauth'] ||= {} if env['REQUEST_METHOD'] == 'GET' get_credentials else session['omniauth.xauth'] = { 'x_auth_mode' => 'client_auth', 'x_auth_username' => request['username'], 'x_auth_password' => request['password'] } redirect callback_path end end |