Module: AuthRails
- Defined in:
- lib/auth_rails.rb,
lib/auth_rails/config.rb,
lib/auth_rails/version.rb,
lib/auth_rails/class_methods.rb,
lib/auth_rails/configuration/jwt.rb,
lib/auth_rails/services/jwt_service.rb,
lib/auth_rails/strategies/base_strategy.rb,
app/controllers/auth_rails/api_controller.rb,
lib/generators/auth_rails/migration_generator.rb,
app/controllers/auth_rails/api/auth_controller.rb,
lib/auth_rails/strategies/allowed_token_strategy.rb,
app/controllers/concerns/auth_rails/authentication.rb,
app/models/concerns/auth_rails/concerns/allowed_token_strategy.rb
Defined Under Namespace
Modules: Api, Authentication, Concerns, Configuration, Services, Strategies
Classes: ApiController, Config, Engine, Error, MigrationGenerator
Constant Summary
collapse
- VERSION =
'1.1.2'
Class Method Summary
collapse
Class Method Details
.authenticate(resource:, password:) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/auth_rails/class_methods.rb', line 29
def authenticate(resource:, password:)
if Config.authenticate.present?
raise_if_not_proc(Config.authenticate, 'Config.authenticate')
Config.authenticate.call(resource, password)
else
raise 'Don\'t know how to authenticate resource with password' unless resource.respond_to?(:authenticate)
resource.authenticate(password)
end
end
|
.configuration ⇒ Object
9
10
11
|
# File 'lib/auth_rails/class_methods.rb', line 9
def configuration
Config
end
|
5
6
7
|
# File 'lib/auth_rails/class_methods.rb', line 5
def configure
yield Config
end
|
.dig_params(params:) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/auth_rails/class_methods.rb', line 41
def dig_params(params:)
if Config.dig_params.present?
raise_if_not_proc(Config.dig_params, 'Config.dig_params')
Config.dig_params.call(params)
else
params[AuthRails.identifier_name]
end
end
|
.error_class ⇒ Object
21
22
23
|
# File 'lib/auth_rails/class_methods.rb', line 21
def error_class
@error_class ||= Config.error_class || Error
end
|
.identifier_name ⇒ Object
17
18
19
|
# File 'lib/auth_rails/class_methods.rb', line 17
def identifier_name
@identifier_name ||= Config.identifier_name&.to_sym || :email
end
|
.jwt_strategy ⇒ Object
25
26
27
|
# File 'lib/auth_rails/class_methods.rb', line 25
def jwt_strategy
@jwt_strategy ||= Configuration::Jwt.strategy || Strategies::BaseStrategy
end
|
.resource_class ⇒ Object
13
14
15
|
# File 'lib/auth_rails/class_methods.rb', line 13
def resource_class
@resource_class ||= Config.resource_class
end
|
.retrieve_resource(params:) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/auth_rails/class_methods.rb', line 51
def retrieve_resource(params:)
identifier = dig_params(params: params)
if Config.retrieve_resource.present?
raise_if_not_proc(Config.retrieve_resource, 'Config.retrieve_resource')
return Config.retrieve_resource.call(identifier)
end
AuthRails.resource_class.find_by(AuthRails.identifier_name => identifier)
end
|