Class: Sorcery::Model::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sorcery/model/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sorcery/model/config.rb', line 52

def initialize
  @defaults = {
    :@submodules                           => [],
    :@username_attribute_names             => [:email],
    :@password_attribute_name              => :password,
    :@downcase_username_before_authenticating => false,
    :@email_attribute_name                 => :email,
    :@crypted_password_attribute_name      => :crypted_password,
    :@encryption_algorithm                 => :bcrypt,
    :@encryption_provider                  => CryptoProviders::BCrypt,
    :@custom_encryption_provider           => nil,
    :@encryption_key                       => nil,
    :@pepper                               => '',
    :@salt_join_token                      => '',
    :@salt_attribute_name                  => :salt,
    :@stretches                            => nil,
    :@subclasses_inherit_config            => false,
    :@before_authenticate                  => [],
    :@after_config                         => [],
    :@email_delivery_method                => default_email_delivery_method,
    :@token_randomness                     => 15
  }
  reset!
end

Instance Attribute Details

#after_configObject

an array of method names to call after configuration by user. used internally.



39
40
41
# File 'lib/sorcery/model/config.rb', line 39

def after_config
  @after_config
end

#before_authenticateObject

an array of method names to call before authentication completes. used internally.



32
33
34
# File 'lib/sorcery/model/config.rb', line 32

def before_authenticate
  @before_authenticate
end

#crypted_password_attribute_nameObject

change default crypted_password attribute.



14
15
16
# File 'lib/sorcery/model/config.rb', line 14

def crypted_password_attribute_name
  @crypted_password_attribute_name
end

#custom_encryption_providerObject

use an external encryption class.



48
49
50
# File 'lib/sorcery/model/config.rb', line 48

def custom_encryption_provider
  @custom_encryption_provider
end

#downcase_username_before_authenticatingObject

downcase the username before trying to authenticate, default is false



12
13
14
# File 'lib/sorcery/model/config.rb', line 12

def downcase_username_before_authenticating
  @downcase_username_before_authenticating
end

#email_attribute_nameObject

change default email attribute.



10
11
12
# File 'lib/sorcery/model/config.rb', line 10

def email_attribute_name
  @email_attribute_name
end

#email_delivery_methodObject

method to send email related options: ‘:deliver_later`, `:deliver_now`, `:deliver` Default: :deliver (Rails version < 4.2) or :deliver_now (Rails version 4.2+) method to send email related



37
38
39
# File 'lib/sorcery/model/config.rb', line 37

def email_delivery_method
  @email_delivery_method
end

#encryption_algorithmObject

encryption algorithm name. See ‘encryption_algorithm=’ below for available options.



50
51
52
# File 'lib/sorcery/model/config.rb', line 50

def encryption_algorithm
  @encryption_algorithm
end

#encryption_keyObject

encryption key used to encrypt reversible encryptions such as AES256.



26
27
28
# File 'lib/sorcery/model/config.rb', line 26

def encryption_key
  @encryption_key
end

#encryption_providerObject (readonly)

change default encryption_provider.



46
47
48
# File 'lib/sorcery/model/config.rb', line 46

def encryption_provider
  @encryption_provider
end

#password_attribute_nameObject

change virtual password attribute, the one which is used until an encrypted one is generated.



8
9
10
# File 'lib/sorcery/model/config.rb', line 8

def password_attribute_name
  @password_attribute_name
end

#pepperObject

application-specific secret token that is joined with the password and its salt. Currently available with BCrypt (default crypt provider) only.



17
18
19
# File 'lib/sorcery/model/config.rb', line 17

def pepper
  @pepper
end

#salt_attribute_nameObject

change default salt attribute.



22
23
24
# File 'lib/sorcery/model/config.rb', line 22

def salt_attribute_name
  @salt_attribute_name
end

#salt_join_tokenObject

what pattern to use to join the password with the salt APPLICABLE TO MD5, SHA1, SHA256, SHA512. Other crypt providers (incl. BCrypt) ignore this parameter.



20
21
22
# File 'lib/sorcery/model/config.rb', line 20

def salt_join_token
  @salt_join_token
end

#stretchesObject

how many times to apply encryption to the password.



24
25
26
# File 'lib/sorcery/model/config.rb', line 24

def stretches
  @stretches
end

#subclasses_inherit_configObject

make this configuration inheritable for subclasses. Useful for ActiveRecord’s STI.



28
29
30
# File 'lib/sorcery/model/config.rb', line 28

def subclasses_inherit_config
  @subclasses_inherit_config
end

#submodulesObject

configured in config/application.rb



30
31
32
# File 'lib/sorcery/model/config.rb', line 30

def submodules
  @submodules
end

#token_randomnessObject

Set token randomness



41
42
43
# File 'lib/sorcery/model/config.rb', line 41

def token_randomness
  @token_randomness
end

#username_attribute_namesObject

change default username attribute, for example, to use :email as the login. See ‘username_attribute_names=’ below.



44
45
46
# File 'lib/sorcery/model/config.rb', line 44

def username_attribute_names
  @username_attribute_names
end

Instance Method Details

#reset!Object

Resets all configuration options to their default values.



78
79
80
81
82
# File 'lib/sorcery/model/config.rb', line 78

def reset!
  @defaults.each do |k, v|
    instance_variable_set(k, v)
  end
end