Module: Ditty::Services::Authentication

Defined in:
lib/ditty/services/authentication.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



21
22
23
# File 'lib/ditty/services/authentication.rb', line 21

def [](key)
  config[key]
end

.configObject



39
40
41
# File 'lib/ditty/services/authentication.rb', line 39

def config
  default.merge Ditty::Services::Settings.values(:authentication) || {}
end

.defaultObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ditty/services/authentication.rb', line 47

def default
  require 'ditty/models/identity'
  require 'ditty/controllers/auth'
  {
    identity: {
      arguments: [
        {
          fields: [:username],
          model: Ditty::Identity,
          on_login: Ditty::Auth,
          on_registration: Ditty::Auth,
          locate_conditions: ->(req) { { username: req['username'] } }
        }
      ]
    }
  }
end

.providersObject



25
26
27
# File 'lib/ditty/services/authentication.rb', line 25

def providers
  config.compact.keys
end

.provides?(provider) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ditty/services/authentication.rb', line 43

def provides?(provider)
  providers.include? provider.to_sym
end

.setupObject



29
30
31
32
33
34
35
36
37
# File 'lib/ditty/services/authentication.rb', line 29

def setup
  providers.each do |provider|
    begin
      require "omniauth/#{provider}"
    rescue LoadError
      require "omniauth-#{provider}"
    end
  end
end