Class: OmniAuth::Strategies::OAuth2
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::OAuth2
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/oauth2.rb
Overview
Authentication strategy for connecting with APIs constructed using the OAuth 2.0 Specification. You must generally register your application with the provider and utilize an application id and secret in order to authenticate using OAuth 2.0.
Defined Under Namespace
Classes: CallbackError
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Class Method Summary collapse
Instance Method Summary collapse
-
#authorize_params ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
#callback_phase ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #client ⇒ Object
- #request_phase ⇒ Object
- #token_params ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
44 45 46 |
# File 'lib/omniauth/strategies/oauth2.rb', line 44 def access_token @access_token end |
Class Method Details
.inherited(subclass) ⇒ Object
17 18 19 |
# File 'lib/omniauth/strategies/oauth2.rb', line 17 def self.inherited(subclass) OmniAuth::Strategy.included(subclass) end |
Instance Method Details
#authorize_params ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omniauth/strategies/oauth2.rb', line 62 def # rubocop:disable Metrics/AbcSize, Metrics/MethodLength .[:state] = SecureRandom.hex(24) if OmniAuth.config.test_mode @env ||= {} @env["rack.session"] ||= {} end params = . .merge(("authorize")) .merge() session["omniauth.pkce.verifier"] = .pkce_verifier if .pkce session["omniauth.state"] = params[:state] params end |
#callback_phase ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/omniauth/strategies/oauth2.rb', line 84 def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity error = request.params["error_reason"] || request.params["error"] if !.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state")) fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected")) elsif error fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"])) else self.access_token = build_access_token self.access_token = access_token.refresh! if access_token.expired? super end rescue ::OAuth2::Error, CallbackError => e fail!(:invalid_credentials, e) rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e fail!(:timeout, e) rescue ::SocketError => e fail!(:failed_to_connect, e) end |
#client ⇒ Object
46 47 48 |
# File 'lib/omniauth/strategies/oauth2.rb', line 46 def client ::OAuth2::Client.new(.client_id, .client_secret, deep_symbolize(.)) end |
#request_phase ⇒ Object
58 59 60 |
# File 'lib/omniauth/strategies/oauth2.rb', line 58 def request_phase redirect client.auth_code.({:redirect_uri => callback_url}.merge()) end |
#token_params ⇒ Object
80 81 82 |
# File 'lib/omniauth/strategies/oauth2.rb', line 80 def token_params .token_params.merge(("token")).merge(pkce_token_params) end |