Class: Authentication
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Authentication
- Includes:
- Models::Auditable
- Defined in:
- app/models/authentication.rb
Overview
== Schema Information
Table name: authentications
Database name: primary
id :integer not null, primary key
google_auth_access_token :text
google_auth_refresh_token :text
google_calendar_status :string
google_calendar_status_checked_at :datetime
provider :string(255)
uid :string(255)
created_at :datetime not null
updated_at :datetime not null
account_id :integer
Indexes
index_authentications_on_account_id (account_id)
index_authentications_on_uid (uid)
provider_account_id (provider,account_id)
provider_uid (provider,uid)
Constant Summary collapse
- PROVIDERS =
Providers.
{ "facebook" => { icon: "facebook", name: "facebook" }, "google_oauth2" => { icon: "google", name: "google" }, "linkedin" => { icon: "linkedin", name: "linkedin" }, "apple" => { icon: "apple", name: "apple" }, "zoom" => { icon: "video", name: "zoom" } }.freeze
- SUPPORTED_PROVIDERS =
Sign In with Apple is temporarily deferred pending an Apple Developer
Program membership renewal. The strategy code in
config/initializers/130_devise.rbandapp/models/account.rb(avatar
extraction, monkey-patches) stays in place — re-enable by adding
'apple' back to this list and uncommenting theconfig.omniauth :apple, …
block. Seedoc/development/SOCIAL_LOGIN_SETUP.md. %w[facebook google_oauth2 linkedin zoom].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #provider ⇒ Object readonly
- #uid ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Class Method Summary collapse
- .extract_email_from_omniauth_hash(omniauth) ⇒ Object
- .extract_name_from_omniauth_hash(omniauth) ⇒ Object
-
.extract_picture_url_from_omniauth_hash(omniauth) ⇒ Object
Extract the profile picture URL across providers.
-
.google_auth ⇒ ActiveRecord::Relation<Authentication>
A relation of Authentications that are google auth.
-
.zoom_auth ⇒ ActiveRecord::Relation<Authentication>
A relation of Authentications that are zoom auth.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#provider ⇒ Object (readonly)
33 |
# File 'app/models/authentication.rb', line 33 validates :provider, presence: true |
#uid ⇒ Object (readonly)
34 |
# File 'app/models/authentication.rb', line 34 validates :uid, presence: true |
Class Method Details
.extract_email_from_omniauth_hash(omniauth) ⇒ Object
54 55 56 |
# File 'app/models/authentication.rb', line 54 def self.extract_email_from_omniauth_hash(omniauth) omniauth.try(:[], 'user_info').try(:[], 'email') || omniauth.try(:[], 'info').try(:[], 'email') end |
.extract_name_from_omniauth_hash(omniauth) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/models/authentication.rb', line 69 def self.extract_name_from_omniauth_hash(omniauth) omniauth.try(:[], 'user_info').try(:[], 'name') || omniauth.try(:[], 'info').try(:[], 'name') || (if omniauth.try(:[], 'info').try(:[], 'first_name').present? || omniauth.try(:[], 'info').try(:[], 'last_name').present? [omniauth.try(:[], 'info').try(:[], 'first_name'), omniauth.try(:[], 'info').try(:[], 'last_name')].compact.join(' ') end) end |
.extract_picture_url_from_omniauth_hash(omniauth) ⇒ Object
Extract the profile picture URL across providers. Facebook /
Google use info.image; LinkedIn OIDC uses info.picture_url;
Apple does not return one. Returns nil when absent so callers can
skip the fetch.
62 63 64 65 66 67 |
# File 'app/models/authentication.rb', line 62 def self.extract_picture_url_from_omniauth_hash(omniauth) info = omniauth.try(:[], 'info') || omniauth.try(:[], 'user_info') return nil unless info info['image'].presence || info['picture_url'].presence || info['picture'].presence end |
.google_auth ⇒ ActiveRecord::Relation<Authentication>
A relation of Authentications that are google auth. Active Record Scope
30 |
# File 'app/models/authentication.rb', line 30 scope :google_auth, -> { where(provider: 'google_oauth2') } |
.zoom_auth ⇒ ActiveRecord::Relation<Authentication>
A relation of Authentications that are zoom auth. Active Record Scope
31 |
# File 'app/models/authentication.rb', line 31 scope :zoom_auth, -> { where(provider: 'zoom') } |