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.
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: ClassMethods
Constant Summary collapse
- SCHEMA_ATTRIBUTES =
%w[name email nickname first_name last_name location description image phone].freeze
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.
-
#persisted? ⇒ true or false
abstract
Checks if the Identity object is persisted in the ORM.
-
#save ⇒ Model
abstract
Persists a new Identity object to the ORM.
-
#uid ⇒ String
An identifying string that must be globally unique to the application.
Class Method Details
.included(base) ⇒ Object
26 27 28 |
# File 'lib/omniauth/identity/model.rb', line 26 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`.
133 134 135 136 137 138 139 |
# File 'lib/omniauth/identity/model.rb', line 133 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.
147 148 149 150 151 152 153 154 |
# File 'lib/omniauth/identity/model.rb', line 147 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 |
#authenticate(password) ⇒ self or false
Returns self if the provided password is correct, false otherwise.
109 110 111 |
# File 'lib/omniauth/identity/model.rb', line 109 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.
165 166 167 168 169 |
# File 'lib/omniauth/identity/model.rb', line 165 def info SCHEMA_ATTRIBUTES.each_with_object({}) do |attribute, hash| hash[attribute] = send(attribute) if respond_to?(attribute) end end |
#persisted? ⇒ true or false
Checks if the Identity object is persisted in the ORM. Defaults to calling super. Override as needed per ORM.
97 98 99 100 101 |
# File 'lib/omniauth/identity/model.rb', line 97 def persisted? raise NotImplementedError unless defined?(super) super end |
#save ⇒ Model
Persists a new Identity object to the ORM. Default raises an error. Override as needed per ORM.
85 86 87 88 89 |
# File 'lib/omniauth/identity/model.rb', line 85 def save raise NotImplementedError unless defined?(super) super end |
#uid ⇒ String
An identifying string that must be globally unique to the application. Defaults to stringifying the ‘id` method.
117 118 119 120 121 122 123 124 125 |
# File 'lib/omniauth/identity/model.rb', line 117 def uid if respond_to?(:id) return nil if id.nil? id.to_s else raise NotImplementedError end end |