class Sorcery::Model::Config

Attributes

after_config[RW]

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

before_authenticate[RW]

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

crypted_password_attribute_name[RW]

change default crypted_password attribute.

custom_encryption_provider[R]

use an external encryption class.

downcase_username_before_authenticating[RW]

downcase the username before trying to authenticate, default is false

email_attribute_name[RW]

change default email attribute.

email_delivery_method[RW]

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

encryption_algorithm[R]

encryption algorithm name. See 'encryption_algorithm=' below for available options.

encryption_key[RW]

encryption key used to encrypt reversible encryptions such as AES256.

encryption_provider[R]

change default encryption_provider.

password_attribute_name[RW]

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

pepper[RW]

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

salt_attribute_name[RW]

change default salt attribute.

salt_join_token[RW]

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.

stretches[RW]

how many times to apply encryption to the password.

subclasses_inherit_config[RW]

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

submodules[RW]

configured in config/application.rb

token_randomness[RW]

Set token randomness

username_attribute_names[R]

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

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

custom_encryption_provider=(provider) click to toggle source
# File lib/sorcery/model/config.rb, line 88
def custom_encryption_provider=(provider)
  @custom_encryption_provider = @encryption_provider = provider
end
encryption_algorithm=(algo) click to toggle source
# File lib/sorcery/model/config.rb, line 92
def encryption_algorithm=(algo)
  @encryption_algorithm = algo
  @encryption_provider = case @encryption_algorithm.to_sym
                         when :none   then nil
                         when :md5    then CryptoProviders::MD5
                         when :sha1   then CryptoProviders::SHA1
                         when :sha256 then CryptoProviders::SHA256
                         when :sha512 then CryptoProviders::SHA512
                         when :aes256 then CryptoProviders::AES256
                         when :bcrypt then CryptoProviders::BCrypt
                         when :custom then @custom_encryption_provider
                         else raise ArgumentError, "Encryption algorithm supplied, #{algo}, is invalid"
                         end
end
reset!() click to toggle source

Resets all configuration options to their default values.

# File lib/sorcery/model/config.rb, line 78
def reset!
  @defaults.each do |k, v|
    instance_variable_set(k, v)
  end
end
username_attribute_names=(fields) click to toggle source
# File lib/sorcery/model/config.rb, line 84
def username_attribute_names=(fields)
  @username_attribute_names = fields.is_a?(Array) ? fields : [fields]
end

Private Instance Methods

default_email_delivery_method() click to toggle source
# File lib/sorcery/model/config.rb, line 109
def default_email_delivery_method
  # Rails 4.2 deprecates #deliver
  rails_version_bigger_than_or_equal?('4.2.0') ? :deliver_now : :deliver
end
rails_version_bigger_than_or_equal?(version) click to toggle source
# File lib/sorcery/model/config.rb, line 114
def rails_version_bigger_than_or_equal?(version)
  Gem::Version.new(version) <= Gem::Version.new(Rails.version)
end