Class: OmniAuth::Strategies::OAuth
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::OAuth
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/oauth.rb
Direct Known Subclasses
Blogger, Dopplr, Douban, Dropbox, Evernote, Flattr, Flickr, Goodreads, Google, GoogleHealth, GoogleHealthSandbox, Hyves, Identica, LinkedIn, Meetup, Miso, MySpace, Netflix, Orkut, Plurk, Qzone, Rdio, SmugMug, T163, Tqq, TradeMe, TripIt, Tsina, Tsohu, Tumblr, Twitter, TypePad, Vimeo, Xing, Yahoo, YouTube
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
-
#initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block) ⇒ OAuth
constructor
A new instance of OAuth.
- #request_phase ⇒ Object
- #unique_id ⇒ Object
Constructor Details
#initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block) ⇒ OAuth
Returns a new instance of OAuth.
10 11 12 13 14 15 16 17 18 |
# File 'lib/omniauth/strategies/oauth.rb', line 10 def initialize(app, name, consumer_key=nil, consumer_secret=nil, ={}, ={}, &block) self.consumer_key = consumer_key self.consumer_secret = consumer_secret self. = super self.[:open_timeout] ||= 30 self.[:read_timeout] ||= 30 self.[:authorize_params] = [:authorize_params] || {} end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
28 29 30 |
# File 'lib/omniauth/strategies/oauth.rb', line 28 def consumer_key @consumer_key end |
#consumer_options ⇒ Object
Returns the value of attribute consumer_options.
28 29 30 |
# File 'lib/omniauth/strategies/oauth.rb', line 28 def @consumer_options end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
28 29 30 |
# File 'lib/omniauth/strategies/oauth.rb', line 28 def consumer_secret @consumer_secret end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/omniauth/strategies/oauth.rb', line 27 def name @name end |
Instance Method Details
#auth_hash ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/omniauth/strategies/oauth.rb', line 73 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/omniauth/strategies/oauth.rb', line 47 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 ::NoMethodError, ::MultiJson::DecodeError => e fail!(:invalid_response, e) rescue ::OmniAuth::NoSessionError => e fail!(:session_expired, e) end |
#consumer ⇒ Object
20 21 22 23 24 25 |
# File 'lib/omniauth/strategies/oauth.rb', line 20 def consumer consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, .merge([:client_options] || [:consumer_options] || {})) consumer.http.open_timeout = [:open_timeout] if [:open_timeout] consumer.http.read_timeout = [:read_timeout] if [:read_timeout] consumer end |
#request_phase ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omniauth/strategies/oauth.rb', line 30 def request_phase request_token = consumer.get_request_token(:oauth_callback => callback_url) 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_params]) else redirect request_token.([: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 |
#unique_id ⇒ Object
84 85 86 |
# File 'lib/omniauth/strategies/oauth.rb', line 84 def unique_id nil end |