Module: Authpwn::Routes::MapperMixin

Defined in:
lib/authpwn_rails/routes.rb

Overview

:nodoc: mixed into ActionPack’s route mapper.

Instance Method Summary collapse

Instance Method Details

#authpwn_session(options = {}) ⇒ Object

Draws the routes for a session controller.

Parameters:

  • options (Object) (defaults to: {})

Options Hash (options):

  • controller (String)

    the name of the controller; defaults to “session” for SessionController

  • paths (String)

    the prefix of the route paths; defaults to the controller name

  • method_names (String)

    the root of name used in the path methods; defaults to “session”, which will generate names like session_path, new_session_path, and token_session_path

  • omniauth_path_prefix (String)

    the prefix of the OmniAuth route paths; defaults to ‘/auth’; this option should equal OmniAuth.config.path_prefix



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/authpwn_rails/routes.rb', line 24

def authpwn_session(options = {})
  controller = options[:controller] || 'session'
  paths = options[:paths] || controller
  methods = options[:method_names] || 'session'
  oa_prefix = options[:omniauth_path_prefix] || '/auth'

  get "/#{paths}/token/:code", controller: controller, action: 'token',
                               as: :"token_#{methods}"

  get "/#{paths}", controller: controller, action: 'show',
                   as: :"#{methods}"
  get "/#{paths}/new", controller: controller, action: 'new',
                       as: :"new_#{methods}"
  post "/#{paths}", controller: controller, action: 'create'
  delete "/#{paths}", controller: controller, action: 'destroy'

  get "/#{paths}/api_token", controller: controller, action: 'api_token',
                             as: "api_token_#{methods}"
  delete "/#{paths}/api_token", controller: controller,
                                action: 'destroy_api_token',
                                as: "destroy_api_token_#{methods}"
  get "/#{paths}/change_password", controller: controller,
                                  action: 'password_change',
                                  as: "change_password_#{methods}"
  post "/#{paths}/change_password", controller: controller,
                                   action: 'change_password'
  post "/#{paths}/reset_password", controller: controller,
                                   action: 'reset_password',
                                   as: "reset_password_#{methods}"

  match "#{oa_prefix}/:provider/callback", via: [:get, :post],
                                           controller: controller,
                                           action: 'omniauth',
                                           as: "omniauth_#{methods}"
  get "#{oa_prefix}/failure", controller: controller,
                              action: 'omniauth_failure',
                              as: "omniauth_failure_#{methods}"
end