Module: DeviseJwtAuth

Defined in:
app/controllers/devise_jwt_auth/sessions_controller.rb,
lib/devise_jwt_auth.rb,
lib/devise_jwt_auth/engine.rb,
lib/devise_jwt_auth/errors.rb,
lib/devise_jwt_auth/version.rb,
lib/devise_jwt_auth/token_factory.rb,
lib/devise_jwt_auth/controllers/helpers.rb,
lib/devise_jwt_auth/controllers/url_helpers.rb,
lib/generators/devise_jwt_auth/install_generator.rb,
app/controllers/devise_jwt_auth/unlocks_controller.rb,
app/controllers/devise_jwt_auth/passwords_controller.rb,
app/controllers/devise_jwt_auth/application_controller.rb,
lib/generators/devise_jwt_auth/install_views_generator.rb,
app/controllers/devise_jwt_auth/confirmations_controller.rb,
app/controllers/devise_jwt_auth/refresh_token_controller.rb,
app/controllers/devise_jwt_auth/registrations_controller.rb,
lib/generators/devise_jwt_auth/install_generator_helpers.rb,
lib/generators/devise_jwt_auth/install_mongoid_generator.rb,
app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb

Overview

Defined Under Namespace

Modules: Controllers, Errors, InstallGeneratorHelpers, TokenFactory, Url Classes: ApplicationController, ConfirmationsController, Engine, InstallGenerator, InstallMongoidGenerator, InstallViewsGenerator, OmniauthCallbacksController, PasswordsController, RefreshTokenController, RegistrationsController, SessionsController, UnlocksController

Constant Summary collapse

VERSION =
'0.1.3'.freeze

Class Method Summary collapse

Class Method Details

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (DeviseJwtAuth)

    the object that the method was called on



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/devise_jwt_auth/engine.rb', line 54

def self.setup(&block)
  yield self

  Rails.application.config.after_initialize do
    if defined?(::OmniAuth)
      ::OmniAuth::config.path_prefix = Devise.omniauth_path_prefix = omniauth_prefix

      # Omniauth currently does not pass along omniauth.params upon failure redirect
      # see also: https://github.com/intridea/omniauth/issues/626
      OmniAuth::FailureEndpoint.class_eval do
        def redirect_to_failure
          message_key = env['omniauth.error.type']
          origin_query_param = env['omniauth.origin'] ? "&origin=#{CGI.escape(env['omniauth.origin'])}" : ''
          strategy_name_query_param = env['omniauth.error.strategy'] ? "&strategy=#{env['omniauth.error.strategy'].name}" : ''
          extra_params = env['omniauth.params'] ? "&#{env['omniauth.params'].to_query}" : ''
          new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}#{origin_query_param}#{strategy_name_query_param}#{extra_params}"
          Rack::Response.new(['302 Moved'], 302, 'Location' => new_path).finish
        end
      end

      # Omniauth currently removes omniauth.params during mocked requests
      # see also: https://github.com/intridea/omniauth/pull/812
      OmniAuth::Strategy.class_eval do
        def mock_callback_call
          setup_phase
          @env['omniauth.origin'] = session.delete('omniauth.origin')
          @env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
          @env['omniauth.params'] = session.delete('omniauth.params') || {}
          mocked_auth = OmniAuth.mock_auth_for(name.to_s)
          if mocked_auth.is_a?(Symbol)
            fail!(mocked_auth)
          else
            @env['omniauth.auth'] = mocked_auth
            OmniAuth.config.before_callback_phase.call(@env) if OmniAuth.config.before_callback_phase
            call_app!
          end
        end
      end

    end
  end
end