Class: Identity

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/happy_seed/omniauth/templates/app/models/identity.rb

Class Method Summary collapse

Class Method Details

.find_for_oauth(auth) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/generators/happy_seed/omniauth/templates/app/models/identity.rb', line 6

def self.find_for_oauth(auth)
  identity = find_by(provider: auth.provider, uid: auth.uid)
  identity = create(uid: auth.uid, provider: auth.provider) if identity.nil?
  identity.accesstoken = auth.credentials.token
  identity.name = auth.info.name
  identity.email = auth.info.email
  identity.nickname = auth.info.nickname
  identity.image = auth.info.image
  identity.phone = auth.info.phone
  identity.urls = (auth.info.urls || "").to_json
  identity.save
  identity
end