Module: UserPlane::OmniAuth

Defined in:
lib/user_plane/omniauth.rb

Defined Under Namespace

Classes: Builder

Class Method Summary collapse

Class Method Details

.callback_path_criteria_for(provider) ⇒ Object



15
16
17
18
19
20
# File 'lib/user_plane/omniauth.rb', line 15

def self.callback_path_criteria_for provider
  lambda do |env|
    path_parameters = env["action_dispatch.request.path_parameters"]
    path_parameters[:action] == 'oauth_callback'
  end
end

.custom_path(env) ⇒ Object



22
23
24
25
26
27
# File 'lib/user_plane/omniauth.rb', line 22

def self.custom_path env
  path_parameters = env["action_dispatch.request.path_parameters"]
  custom_callback_path = path_parameters.merge(action: 'oauth_callback',
                                               only_path: true)
  env['action_dispatch.routes'].url_for custom_callback_path
end

.middleware(&block) ⇒ Object

Configures the omniauth middleware for the application



30
31
32
33
34
35
36
37
38
# File 'lib/user_plane/omniauth.rb', line 30

def self.middleware &block
  controllers = [User::SignInsController,
                 User::SignUpsController,
                 User::InvitesController]

  controllers.each do |controller|
    controller.middleware.use Builder, &block
  end
end

.request_path_criteria_for(provider) ⇒ Object

Lets actiondispatch figure out the request path. Looks like request_path needs to return the callback path to generate the correct link



8
9
10
11
12
13
# File 'lib/user_plane/omniauth.rb', line 8

def self.request_path_criteria_for provider
  lambda do |env|
    path_parameters = env["action_dispatch.request.path_parameters"]
    path_parameters[:action] == 'oauth_request' && UserPlane::OmniAuth.custom_path(env)        
  end
end