Class: ROM::Auth::System

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/auth/system.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ System

Returns a new instance of System.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/rom/auth/system.rb', line 7

def initialize(config)
  raise ArgumentError unless config.is_a?(Configuration)
  @configuration = config

  load_plugins!
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/rom/auth/system.rb', line 5

def configuration
  @configuration
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



5
6
7
# File 'lib/rom/auth/system.rb', line 5

def plugins
  @plugins
end

Instance Method Details

#authenticate(credentials) ⇒ Object

def authenticators

Authenticators::Authenticator.descendants.inject({}) do |acc, desc|
  acc.merge(desc.shorthand_symbol => desc)
end

end

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rom/auth/system.rb', line 26

def authenticate(credentials)
  raise ArgumentError unless credentials

  success = false
  now = Time.now
  user = identify_user(credentials)

  on_authentication_attempt(credentials)

  if user
    authenticated = run_authentication_check(credentials)

    if authenticated
      on_authentication_success(credentials)

      if authentication_authorized?(user, credentials)
        on_authorized_authentication(credentials)
        success = true
      else
        on_unauthorized_authentication(credentials)
      end
    else
      on_authentication_failure(credentials)
    end
  else
    on_identification_failure(credentials)
  end

  on_authentication_completed(
    identifier: credentials.identifier,
    user_id: (user[:id] if user),
    started_at: now,
    ended_at: Time.now,
    type: credentials.type,
    authenticated: authenticated,
    success: success
  )

  user if success
end

#inspectObject



71
72
73
# File 'lib/rom/auth/system.rb', line 71

def inspect
  "#<ROM::Auth::AuthenticationSystem plugins: #{plugins.keys}>"
end

#loggerObject



67
68
69
# File 'lib/rom/auth/system.rb', line 67

def logger
  configuration.logger
end

#migrate!(setup) ⇒ Object



14
15
16
17
18
# File 'lib/rom/auth/system.rb', line 14

def migrate!(setup)
  plugins.each do |_type, plugin|
    plugin.migrate(setup)
  end
end