Module: OmniAuth::Identity::Model
- Included in:
- OmniAuth::Identity::Models::ActiveRecord
- Defined in:
- lib/omniauth/identity/model.rb
Overview
This module provides an include-able 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.
Singleton API
- locate(key)
- create(*args) - Deprecated in v3.0.5; Will be removed in v4.0
Instance API
- save
- persisted?
- authenticate(password)
Defined Under Namespace
Modules: ClassCreateApi, ClassMethods, InstancePersistedApi, InstanceSaveApi
Constant Summary collapse
- SCHEMA_ATTRIBUTES =
Standard OmniAuth schema attributes that may be stored in the model.
%w[name email nickname first_name last_name location description image phone].freeze
- FILTERED_INSPECT_ATTRIBUTES =
%i[password password_confirmation password_digest].freeze
Instance Attribute Summary collapse
-
#SCHEMA_ATTRIBUTES ⇒ Array<String>
readonly
Standard OmniAuth schema attributes that may be stored in the model.
Class Method Summary collapse
-
.included(base) ⇒ void
Called when this module is included in a model class.
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_keyclass method.. -
#authenticate(_password) ⇒ self, 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.
Instance Attribute Details
#SCHEMA_ATTRIBUTES ⇒ Array<String> (readonly)
Standard OmniAuth schema attributes that may be stored in the model.
49 |
# File 'lib/omniauth/identity/model.rb', line 49 SCHEMA_ATTRIBUTES = %w[name email nickname first_name last_name location description image phone].freeze |
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Called when this module is included in a model class.
Extends the base class with ClassMethods and includes necessary APIs if they are not already defined.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/omniauth/identity/model.rb', line 60 def included(base) base.include(OmniAuth::Identity::AUTH_SANITIZER::FilteredAttributes) base.prepend(OmniAuth::Identity::AUTH_SANITIZER::FilteredAttributes) base.filtered_attributes(*FILTERED_INSPECT_ATTRIBUTES) base.extend(ClassMethods) base.extend(ClassCreateApi) unless base.respond_to?(:create) i_methods = base.instance_methods base.include(InstanceSaveApi) unless i_methods.include?(:save) base.include(InstancePersistedApi) unless i_methods.include?(:persisted?) 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.
193 194 195 196 197 198 199 |
# File 'lib/omniauth/identity/model.rb', line 193 def auth_key if respond_to?(self.class.auth_key.to_sym) 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.
207 208 209 210 211 212 213 214 |
# File 'lib/omniauth/identity/model.rb', line 207 def auth_key=(value) auth_key_setter = :"#{self.class.auth_key}=" if respond_to?(auth_key_setter) send(auth_key_setter, value) else raise NotImplementedError end end |
#authenticate(_password) ⇒ self, false
Subclasses must implement this method.
Returns self if the provided password is correct, false otherwise.
169 170 171 |
# File 'lib/omniauth/identity/model.rb', line 169 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.
225 226 227 228 229 230 231 232 233 |
# File 'lib/omniauth/identity/model.rb', line 225 def info info = {} SCHEMA_ATTRIBUTES.each_with_object(info) do |attribute, hash| hash[attribute] = send(attribute) if respond_to?(attribute) end info["name"] ||= [info["first_name"], info["last_name"]].join(" ").strip if info["first_name"] || info["last_name"] info["name"] ||= info["nickname"] info end |
#uid ⇒ String
An identifying string that must be globally unique to the
application. Defaults to stringifying the id method.
177 178 179 180 181 182 183 184 185 |
# File 'lib/omniauth/identity/model.rb', line 177 def uid if respond_to?(:id) return if id.nil? id.to_s else raise NotImplementedError end end |