Class: Authorization

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/authorization.rb

Class Method Summary collapse

Class Method Details

.handle_authorization(auth) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/authorization.rb', line 7

def self.handle_authorization(auth)
  provider = auth['provider']
  uid      = auth['uid']

  authorization = find_by_provider_and_uid provider, uid
  if authorization.present?
    authorization.user.update_from_auth! auth
  else
    user = User.find_or_create_from_hash! auth
    authorization = Authorization.create! user: user, provider: provider, uid: uid
  end
  authorization
end