Module: Ditty::Services::Authentication

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

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



18
19
20
# File 'lib/ditty/services/authentication.rb', line 18

def [](key)
  config[key]
end

.configObject



36
37
38
# File 'lib/ditty/services/authentication.rb', line 36

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

.defaultObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ditty/services/authentication.rb', line 44

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

.providersObject



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

def providers
  config.compact.keys
end

.provides?(provider) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.setupObject



26
27
28
29
30
31
32
33
34
# File 'lib/ditty/services/authentication.rb', line 26

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