Class: Warden::OAuth::Strategy
- Inherits:
-
Strategies::Base
- Object
- Strategies::Base
- Warden::OAuth::Strategy
- Extended by:
- StrategyBuilder
- Defined in:
- lib/warden_oauth/strategy.rb
Overview
Holds all the main logic of the OAuth authentication, all the generated OAuth classes will extend from this class
Class Method Summary collapse
-
.access_token_user_finders ⇒ Object
Strategy Logic ###.
Instance Method Summary collapse
- #access_token ⇒ Object
-
#authenticate! ⇒ Object
Manages the OAuth authentication process, there can be 3 outcomes from this Strategy: 1.
-
#consumer ⇒ Object
OAuth Logic ###.
-
#fail!(msg) ⇒ Object
:nodoc:.
- #request_token ⇒ Object
-
#valid? ⇒ Boolean
An OAuth strategy will be valid to execute if: * A ‘warden_oauth_provider’ parameter is given, with the name of the OAuth service * A ‘oauth_token’ is being receive on the request (response from an OAuth provider).
Methods included from StrategyBuilder
access_token_user_finder, build
Class Method Details
.access_token_user_finders ⇒ Object
Strategy Logic ###
14 15 16 |
# File 'lib/warden_oauth/strategy.rb', line 14 def self.access_token_user_finders (@_user_token_finders ||= {}) end |
Instance Method Details
#access_token ⇒ Object
81 82 83 |
# File 'lib/warden_oauth/strategy.rb', line 81 def access_token @access_token ||= request_token.get_access_token(:oauth_verifier => params["oauth_verifier"]) end |
#authenticate! ⇒ Object
Manages the OAuth authentication process, there can be 3 outcomes from this Strategy:
-
The OAuth credentials are invalid and the FailureApp is called
-
The OAuth credentials are valid, but there is no user associated to them. In this case the FailureApp is called, but the env[:oauth] will be available.
-
The OAuth credentials are valid, and the user is authenticated successfuly
If you want to signup users with the twitter credentials, you can manage the creation of a new user in the FailureApp with the given access_token
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/warden_oauth/strategy.rb', line 40 def authenticate! if params.include?("warden_oauth_provider") store_request_token_on_session redirect!(request_token.) throw(:warden) elsif params.include?("oauth_token") load_request_token_from_session if missing_stored_token? fail!("There is no OAuth authentication in progress") elsif !stored_token_match_recieved_token? fail!("Received OAuth token didn't match stored OAuth token") else user = find_user_by_access_token(access_token) if user.nil? fail!("User with access token not found") throw_error_with_oauth_info else success!(user) end end end end |
#consumer ⇒ Object
OAuth Logic ###
72 73 74 |
# File 'lib/warden_oauth/strategy.rb', line 72 def consumer @consumer ||= ::OAuth::Consumer.new(config.consumer_key, config.consumer_secret, config.) end |
#fail!(msg) ⇒ Object
:nodoc:
63 64 65 66 |
# File 'lib/warden_oauth/strategy.rb', line 63 def fail!(msg) #:nodoc: errors.add(service_param_name.to_sym, msg) super end |
#request_token ⇒ Object
76 77 78 79 |
# File 'lib/warden_oauth/strategy.rb', line 76 def request_token host_with_port = Warden::OAuth::Utils.host_with_port(request) @request_token ||= consumer.get_request_token(:oauth_callback => host_with_port) end |
#valid? ⇒ Boolean
An OAuth strategy will be valid to execute if:
-
A ‘warden_oauth_provider’ parameter is given, with the name of the OAuth service
-
A ‘oauth_token’ is being receive on the request (response from an OAuth provider)
23 24 25 26 |
# File 'lib/warden_oauth/strategy.rb', line 23 def valid? (params.include?("warden_oauth_provider") && params["warden_oauth_provider"] == config.provider_name.to_s) || params.include?("oauth_token") end |