Class: OmniAuth::Strategies::OAuth2
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::OAuth2
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/oauth2.rb
Direct Known Subclasses
Defined Under Namespace
Classes: CallbackError
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
- #authorize_params ⇒ Object
- #callback_phase ⇒ Object
- #callback_url ⇒ Object
- #client ⇒ Object
- #request_phase ⇒ Object
- #token_params ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
26 27 28 |
# File 'lib/omniauth/strategies/oauth2.rb', line 26 def access_token @access_token end |
Instance Method Details
#authorize_params ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/omniauth/strategies/oauth2.rb', line 48 def .[:state] = SecureRandom.hex(24) params = ..merge(..inject({}){|h,k| h[k.to_sym] = [k] if [k]; h}) if OmniAuth.config.test_mode @env ||= {} @env['rack.session'] ||= {} end session['omniauth.state'] = params[:state] params end |
#callback_phase ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/omniauth/strategies/oauth2.rb', line 65 def callback_phase if request.params['error'] || request.params['error_reason'] raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']) end if !.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state')) raise CallbackError.new(nil, :csrf_detected) end self.access_token = build_access_token self.access_token = access_token.refresh! if access_token.expired? super rescue ::OAuth2::Error => e fail!(e.code, e) rescue CallbackError => e fail!(e.error_reason,e) rescue ::MultiJson::DecodeError => e fail!(:invalid_response, e) rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e fail!(:timeout, e) rescue ::SocketError => e fail!(:failed_to_connect, e) end |
#callback_url ⇒ Object
32 33 34 |
# File 'lib/omniauth/strategies/oauth2.rb', line 32 def callback_url full_host + script_name + callback_path end |
#client ⇒ Object
28 29 30 |
# File 'lib/omniauth/strategies/oauth2.rb', line 28 def client ::OAuth2::Client.new(.client_id, .client_secret, deep_symbolize(.)) end |
#request_phase ⇒ Object
44 45 46 |
# File 'lib/omniauth/strategies/oauth2.rb', line 44 def request_phase redirect client.auth_code.({:redirect_uri => callback_url}.merge()) end |
#token_params ⇒ Object
59 60 61 |
# File 'lib/omniauth/strategies/oauth2.rb', line 59 def token_params .token_params.merge(..inject({}){|h,k| h[k.to_sym] = [k] if [k]; h}) end |