lib/ditty/services/authentication.rb in ditty-0.8.0 vs lib/ditty/services/authentication.rb in ditty-0.9.0
- old
+ new
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-require 'ditty/controllers/application'
+require 'ditty/controllers/application_controller'
require 'ditty/services/settings'
require 'ditty/services/logger'
require 'backports/2.4.0/hash/compact'
require 'omniauth'
-OmniAuth.config.logger = Ditty::Services::Logger.instance
-OmniAuth.config.path_prefix = "#{Ditty::Application.map_path}/auth"
+OmniAuth.config.logger = ::Ditty::Services::Logger
+OmniAuth.config.path_prefix = "#{::Ditty::ApplicationController.map_path}/auth"
OmniAuth.config.on_failure = proc { |env|
next [400, {}, []] if env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
}
@@ -26,37 +26,38 @@
config.compact.keys
end
def setup
providers.each do |provider|
+ req = config.dig(provider, :require) || "omniauth/#{provider}"
begin
- require "omniauth/#{provider}"
+ require req
rescue LoadError
require "omniauth-#{provider}"
end
end
end
def config
- default.merge Ditty::Services::Settings.values(:authentication) || {}
+ default.merge ::Ditty::Services::Settings.values(:authentication) || {}
end
def provides?(provider)
providers.include? provider.to_sym
end
def default
require 'ditty/models/identity'
- require 'ditty/controllers/auth'
+ require 'ditty/controllers/auth_controller'
{
identity: {
arguments: [
{
fields: [:username],
- model: Ditty::Identity,
- on_login: Ditty::Auth,
- on_registration: Ditty::Auth,
+ model: ::Ditty::Identity,
+ on_login: ::Ditty::AuthController,
+ on_registration: ::Ditty::AuthController,
locate_conditions: ->(req) { { username: req['username'] } }
}
]
}
}
@@ -64,6 +65,6 @@
end
end
end
end
-Ditty::Services::Authentication.setup
+::Ditty::Services::Authentication.setup