Class: ActiveAdmin::Oidc::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/activeadmin/oidc/engine.rb

Constant Summary collapse

PROVIDER_NAME =
:oidc
ControllersPatch =
Module.new do
  def controllers
    result = super
    if Engine.oidc_enabled?
      result = result.merge(
        omniauth_callbacks: 'active_admin/oidc/devise/omniauth_callbacks'
      )
    end
    result
  end
end

Class Method Summary collapse

Class Method Details

.admin_user_classObject



18
19
20
21
# File 'lib/activeadmin/oidc/engine.rb', line 18

def self.admin_user_class
  admin_class = ActiveAdmin::Oidc.config.admin_user_class
  admin_class.is_a?(String) ? admin_class.safe_constantize : admin_class
end

.oidc_enabled?Boolean

True when the host’s AdminUser model includes :omniauthable. Used to gate controller registration and view overrides so the gem is a no-op when OIDC is not enabled on the model.

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/activeadmin/oidc/engine.rb', line 13

def self.oidc_enabled?
  klass = admin_user_class
  klass.respond_to?(:devise_modules) && klass.devise_modules.include?(:omniauthable)
end

.session_routes_target(app) ⇒ Object

Returns the route set our session routes should be appended to. Follows ‘Devise.available_router_name` (set by the host via `Devise.router_name = :foo`) so that engine-mounted Devise setups see the helpers on the right engine’s url_helpers.



27
28
29
30
31
32
33
34
35
36
# File 'lib/activeadmin/oidc/engine.rb', line 27

def self.session_routes_target(app)
  router_name = ::Devise.available_router_name
  return app.routes if router_name.blank? || router_name.to_sym == :main_app

  engine_class = ::Rails::Engine.subclasses.find do |klass|
    klass.engine_name.to_sym == router_name.to_sym
  end

  engine_class ? engine_class.routes : app.routes
end