Class: Gallery::OmniauthCallbacksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/gallery/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/gallery/omniauth_callbacks_controller.rb', line 5

def callback
  @omniauth_hash = request.env["omniauth.auth"]
  @omniauth_hash.provider = 'google' if @omniauth_hash.provider == "google_oauth2"

  identity = Identity.find_by_uid_and_provider(@omniauth_hash.uid, @omniauth_hash.provider)
  identity.update_attributes({:token => @omniauth_hash.credentials.token}) if identity
  identity = Identity.create parse_omniauth_hash_to_identity(@omniauth_hash) unless identity

  redirect_to admin_path
end

#parse_omniauth_hash_to_identity(omniauth_hash) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/gallery/omniauth_callbacks_controller.rb', line 16

def parse_omniauth_hash_to_identity(omniauth_hash)
  case omniauth_hash.provider
  when 'facebook'
    return { :uid => @omniauth_hash.uid, :provider => @omniauth_hash.provider, :token => @omniauth_hash.credentials.token, :name => @omniauth_hash.info.name, :link => @omniauth_hash.extra.raw_info.link }
  when 'eyeem'
    return { :uid => @omniauth_hash.uid, :provider => @omniauth_hash.provider, :token => @omniauth_hash.credentials.token, :name => @omniauth_hash.info.name, :link => @omniauth_hash.extra.raw_info.user.webUrl }
  when 'google'
    return { :uid => @omniauth_hash.uid, :provider => @omniauth_hash.provider, :token => @omniauth_hash.credentials.token, :name => @omniauth_hash.info.name, :link => @omniauth_hash.extra.raw_info.link }
  end
end