Module: OmniAuth::Identity::Model::ClassMethods

Defined in:
lib/omniauth/identity/model.rb

Overview

Class-level methods for OmniAuth Identity models.

Instance Method Summary collapse

Instance Method Details

#auth_key(method = false) ⇒ String

Used to set or retrieve the method that will be used to get and set the user-supplied authentication key.

Parameters:

  • method (String, Symbol, false) (defaults to: false)

    The method name to set, or false to retrieve.

Returns:

  • (String)

    The method name.



86
87
88
89
90
91
92
93
# File 'lib/omniauth/identity/model.rb', line 86

def auth_key(method = false)
  AUTH_KEY_MUTEX.synchronize do
    @auth_key = method.to_s unless method == false
    @auth_key = nil if !defined?(@auth_key) || @auth_key == ""

    @auth_key || "email"
  end
end

#authenticate(conditions, password) ⇒ Model, false

Authenticate a user with the given key and password.

Parameters:

  • conditions (String)

    The unique login key provided for a given identity.

  • password (String)

    The presumed password for the identity.

Returns:

  • (Model, false)

    An instance of the identity model class or false if authentication fails.



69
70
71
72
73
74
# File 'lib/omniauth/identity/model.rb', line 69

def authenticate(conditions, password)
  instance = locate(conditions)
  return false unless instance

  instance.authenticate(password)
end

#inherited(subclass) ⇒ Object



76
77
78
79
# File 'lib/omniauth/identity/model.rb', line 76

def inherited(subclass)
  super if defined?(super)
  subclass.filtered_attributes(*filtered_attribute_names) if subclass.respond_to?(:filtered_attributes)
end

#locate(_key) ⇒ Model

This method is abstract.

Subclasses must implement this method.

Locate an identity given its unique login key.

Parameters:

  • _key (String)

    The unique login key.

Returns:

  • (Model)

    An instance of the identity model class.

Raises:

  • (NotImplementedError)


100
101
102
# File 'lib/omniauth/identity/model.rb', line 100

def locate(_key)
  raise NotImplementedError
end