Class: OmniAuth::MultiProvider::Handler
- Inherits:
-
Object
- Object
- OmniAuth::MultiProvider::Handler
- Defined in:
- lib/omni_auth/multi_provider/handler.rb
Instance Attribute Summary collapse
-
#callback_path_regex ⇒ Object
readonly
Returns the value of attribute callback_path_regex.
-
#callback_suffix ⇒ Object
readonly
Returns the value of attribute callback_suffix.
-
#identity_provider_options_generator ⇒ Object
readonly
Returns the value of attribute identity_provider_options_generator.
-
#path_prefix ⇒ Object
readonly
Returns the value of attribute path_prefix.
-
#provider_instance_path_regex ⇒ Object
readonly
Returns the value of attribute provider_instance_path_regex.
-
#request_path_regex ⇒ Object
readonly
Returns the value of attribute request_path_regex.
Instance Method Summary collapse
- #callback_path?(env) ⇒ Boolean
-
#initialize(path_prefix:, identity_provider_id_regex:, callback_suffix: 'callback', **_options, &identity_provider_options_generator) ⇒ Handler
constructor
A new instance of Handler.
- #provider_options ⇒ Object
- #request_path?(env) ⇒ Boolean
- #setup(env) ⇒ Object
Constructor Details
#initialize(path_prefix:, identity_provider_id_regex:, callback_suffix: 'callback', **_options, &identity_provider_options_generator) ⇒ Handler
Returns a new instance of Handler.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 8 def initialize(path_prefix:, identity_provider_id_regex:, callback_suffix: 'callback', **, &) raise 'Missing provider options generator block' unless block_given? @path_prefix = path_prefix @identity_provider_options_generator = @identity_provider_id_regex = identity_provider_id_regex @callback_suffix = callback_suffix # Eagerly compute these since lazy evaluation will not be threadsafe @provider_instance_path_regex = /^#{@path_prefix}\/(?<identity_provider_id>#{@identity_provider_id_regex})/ @request_path_regex = /#{@provider_instance_path_regex}\/?$/ @callback_path_regex = /#{@provider_instance_path_regex}\/#{@callback_suffix}\/?$/ end |
Instance Attribute Details
#callback_path_regex ⇒ Object (readonly)
Returns the value of attribute callback_path_regex.
4 5 6 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 4 def callback_path_regex @callback_path_regex end |
#callback_suffix ⇒ Object (readonly)
Returns the value of attribute callback_suffix.
4 5 6 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 4 def callback_suffix @callback_suffix end |
#identity_provider_options_generator ⇒ Object (readonly)
Returns the value of attribute identity_provider_options_generator.
4 5 6 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 4 def @identity_provider_options_generator end |
#path_prefix ⇒ Object (readonly)
Returns the value of attribute path_prefix.
4 5 6 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 4 def path_prefix @path_prefix end |
#provider_instance_path_regex ⇒ Object (readonly)
Returns the value of attribute provider_instance_path_regex.
4 5 6 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 4 def provider_instance_path_regex @provider_instance_path_regex end |
#request_path_regex ⇒ Object (readonly)
Returns the value of attribute request_path_regex.
4 5 6 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 4 def request_path_regex @request_path_regex end |
Instance Method Details
#callback_path?(env) ⇒ Boolean
39 40 41 42 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 39 def callback_path?(env) path = current_path(env) !!callback_path_regex.match(path) end |
#provider_options ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 26 def { request_path: method(:request_path?), callback_path: method(:callback_path?), setup: method(:setup) } end |
#request_path?(env) ⇒ Boolean
34 35 36 37 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 34 def request_path?(env) path = current_path(env) !!request_path_regex.match(path) end |
#setup(env) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/omni_auth/multi_provider/handler.rb', line 44 def setup(env) identity_provider_id = extract_identity_provider_id(env) if identity_provider_id strategy = env['omniauth.strategy'] (strategy, identity_provider_id) (strategy, env, identity_provider_id) end end |