module OmniAuth::Identity::Model
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.
Singleton API
-
locate(key)
-
create(*args) - Deprecated in v3.0.5; Will be removed in v4.0
Instance API
-
save
-
persisted?
-
authenticate(password)
Constants
- SCHEMA_ATTRIBUTES
Public Class Methods
# File lib/omniauth/identity/model.rb, line 26 def self.included(base) base.extend ClassMethods base.extend ClassCreateApi unless base.respond_to?(:create) im = base.instance_methods base.include InstanceSaveApi unless im.include?(:save) base.include InstancePersistedApi unless im.include?(:persisted?) end
Public Instance Methods
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`.
@return [String] An identifying string that will be entered by
users upon sign in.
# File lib/omniauth/identity/model.rb, line 138 def auth_key if respond_to?(self.class.auth_key.to_sym) send(self.class.auth_key) else raise NotImplementedError end end
Used to set the user-supplied authentication key (e.g. a username or email. Determined using the `.auth_key` class method.
@param [String] value The value to which the auth key should be
set.
# File lib/omniauth/identity/model.rb, line 152 def auth_key=(value) auth_key_setter = "#{self.class.auth_key}=".to_sym if respond_to?(auth_key_setter) send(auth_key_setter, value) else raise NotImplementedError end end
Returns self if the provided password is correct, false otherwise.
@abstract @param [String] password The password to check. @return [self or false] Self if authenticated, false if not.
# File lib/omniauth/identity/model.rb, line 114 def authenticate(_password) raise NotImplementedError end
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.
@return [Hash] A string-keyed hash of user information.
# File lib/omniauth/identity/model.rb, line 170 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
An identifying string that must be globally unique to the application. Defaults to stringifying the `id` method.
@return [String] An identifier string unique to this identity.
# File lib/omniauth/identity/model.rb, line 122 def uid if respond_to?(:id) return nil if id.nil? id.to_s else raise NotImplementedError end end