Module: OmniAuth::Identity::Model
- Included in:
- OmniAuth::Identity::Models::ActiveRecord
- Defined in:
- lib/omniauth/identity/model.rb
Overview
This module provides an includable interface for implementing the necessary API for OmniAuth Identity to properly locate identities and provide all necessary information. All methods marked as abstract must be implemented in the including class for things to work properly.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- SCHEMA_ATTRIBUTES =
%w(name email nickname first_name last_name location description image phone)
Class Method Summary collapse
Instance Method Summary collapse
-
#auth_key ⇒ String
Used to retrieve the user-supplied authentication key (e.g. a username or email).
-
#auth_key=(value) ⇒ Object
Used to set the user-supplied authentication key (e.g. a username or email. Determined using the ‘.auth_key` class method..
-
#authenticate(password) ⇒ self or false
abstract
Returns self if the provided password is correct, false otherwise.
-
#info ⇒ Hash
A hash of as much of the standard OmniAuth schema as is stored in this particular model.
-
#uid ⇒ String
An identifying string that must be globally unique to the application.
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/omniauth/identity/model.rb', line 9 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#auth_key ⇒ String
Used to retrieve the user-supplied authentication key (e.g. a username or email). Determined using the class method of the same name, defaults to ‘:email`.
92 93 94 95 96 97 98 |
# File 'lib/omniauth/identity/model.rb', line 92 def auth_key if respond_to?(self.class.auth_key) send(self.class.auth_key) else raise NotImplementedError end end |
#auth_key=(value) ⇒ Object
Used to set the user-supplied authentication key (e.g. a username or email. Determined using the ‘.auth_key` class method.
106 107 108 109 110 111 112 |
# File 'lib/omniauth/identity/model.rb', line 106 def auth_key=(value) if respond_to?(self.class.auth_key + '=') send(self.class.auth_key + '=', value) else raise NotImplementedError end end |
#authenticate(password) ⇒ self or false
Returns self if the provided password is correct, false otherwise.
51 52 53 |
# File 'lib/omniauth/identity/model.rb', line 51 def authenticate(password) raise NotImplementedError end |
#info ⇒ Hash
A hash of as much of the standard OmniAuth schema as is stored in this particular model. By default, this will call instance methods for each of the attributes it needs in turn, ignoring any for which ‘#respond_to?` is `false`.
If ‘first_name`, `nickname`, and/or `last_name` is provided but `name` is not, it will be automatically calculated.
65 66 67 68 69 70 71 |
# File 'lib/omniauth/identity/model.rb', line 65 def info info = SCHEMA_ATTRIBUTES.inject({}) do |hash,attribute| hash[attribute] = send(attribute) if respond_to?(attribute) hash end info end |
#uid ⇒ String
An identifying string that must be globally unique to the application. Defaults to stringifying the ‘id` method.
77 78 79 80 81 82 83 84 |
# File 'lib/omniauth/identity/model.rb', line 77 def uid if respond_to?('id') return nil if self.id.nil? self.id.to_s else raise NotImplementedError end end |