Module: OmniAuth::Strategy::Paths
- Included in:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategy/paths.rb,
sig/omniauth.rbs
Overview
Works out the request, callback, and setup paths for a strategy and whether the current request is on one of them, plus the full URLs built from them.
Constant Summary collapse
- CURRENT_PATH_REGEX =
%r{/$}.freeze
- FORMAT_EXTENSION_REGEX =
/\.\w+\z/.freeze
- EMPTY_STRING =
''.freeze
- SSL_ENV_VALUES =
Rack env values that mean the request came in over HTTPS.
{ 'HTTPS' => 'on', 'HTTP_X_FORWARDED_SSL' => 'on', 'HTTP_X_FORWARDED_SCHEME' => 'https', 'rack.url_scheme' => 'https' }.freeze
Instance Method Summary collapse
- #callback_path ⇒ String
- #callback_url ⇒ String
-
#current_path ⇒ String
Repeated slashes are collapsed, as Rails routing does, so a proxy that sends //auth/:provider still reaches the strategy.
- #custom_path(kind) ⇒ String?
-
#full_host ⇒ String
The scheme and host for URLs such as callback_url: the strategy's :full_host option, else OmniAuth.config.full_host, else the request's.
-
#on_auth_path? ⇒ Boolean
Returns true if the environment recognizes either the request or callback path.
- #on_callback_path? ⇒ Boolean
- #on_path?(path) ⇒ Boolean
- #on_request_path? ⇒ Boolean
- #path_prefix ⇒ String
- #query_string ⇒ String
- #request_path ⇒ String
- #script_name ⇒ String
- #setup_path ⇒ String
Instance Method Details
#callback_path ⇒ String
53 54 55 |
# File 'lib/omniauth/strategy/paths.rb', line 53 def callback_path @callback_path ||= callback_path_option || custom_path(:request_path) || "#{script_name}#{path_prefix}/#{name}/callback" end |
#callback_url ⇒ String
86 87 88 |
# File 'lib/omniauth/strategy/paths.rb', line 86 def callback_url full_host + callback_path + query_string end |
#current_path ⇒ String
Repeated slashes are collapsed, as Rails routing does, so a proxy that sends //auth/:provider still reaches the strategy.
66 67 68 |
# File 'lib/omniauth/strategy/paths.rb', line 66 def current_path @current_path ||= request.path.downcase.squeeze('/').sub(CURRENT_PATH_REGEX, EMPTY_STRING) end |
#custom_path(kind) ⇒ String?
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omniauth/strategy/paths.rb', line 33 def custom_path(kind) if [kind].respond_to?(:call) result = .fetch(kind).call(env) return nil unless result.is_a?(String) result else [kind] end end |
#full_host ⇒ String
The scheme and host for URLs such as callback_url: the strategy's :full_host option, else OmniAuth.config.full_host, else the request's. Either setting can be a string or a proc taking the env.
77 78 79 80 81 82 83 84 |
# File 'lib/omniauth/strategy/paths.rb', line 77 def full_host host = [:full_host] || OmniAuth.config.full_host case host when String then host when Proc then host.call(env) else full_host_from_request end end |
#on_auth_path? ⇒ Boolean
Returns true if the environment recognizes either the request or callback path.
9 10 11 |
# File 'lib/omniauth/strategy/paths.rb', line 9 def on_auth_path? on_request_path? || on_callback_path? end |
#on_callback_path? ⇒ Boolean
21 22 23 |
# File 'lib/omniauth/strategy/paths.rb', line 21 def on_callback_path? on_path?(callback_path) || current_path.sub(FORMAT_EXTENSION_REGEX, EMPTY_STRING).casecmp(callback_path).zero? end |
#on_path?(path) ⇒ Boolean
25 26 27 |
# File 'lib/omniauth/strategy/paths.rb', line 25 def on_path?(path) current_path.casecmp(path).zero? end |
#on_request_path? ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/omniauth/strategy/paths.rb', line 13 def on_request_path? if [:request_path].respond_to?(:call) .fetch(:request_path).call(env) else on_path?(request_path) end end |
#path_prefix ⇒ String
29 30 31 |
# File 'lib/omniauth/strategy/paths.rb', line 29 def path_prefix [:path_prefix] || OmniAuth.config.path_prefix end |
#query_string ⇒ String
70 71 72 |
# File 'lib/omniauth/strategy/paths.rb', line 70 def query_string request.query_string.empty? ? '' : "?#{request.query_string}" end |
#request_path ⇒ String
44 45 46 47 48 49 50 51 |
# File 'lib/omniauth/strategy/paths.rb', line 44 def request_path @request_path ||= if [:request_path].is_a?(String) .fetch(:request_path) else "#{script_name}#{path_prefix}/#{name}" end end |
#script_name ⇒ String
90 91 92 93 94 95 |
# File 'lib/omniauth/strategy/paths.rb', line 90 def script_name current_env = @env return '' if current_env.nil? current_env['SCRIPT_NAME'] || '' end |
#setup_path ⇒ String
57 58 59 |
# File 'lib/omniauth/strategy/paths.rb', line 57 def setup_path [:setup_path] || "#{path_prefix}/#{name}/setup" end |