Class: Devise::MultiAuth::CaptureSuccessfulExternalAuthentication

Inherits:
Object
  • Object
show all
Defined in:
app/services/devise/multi_auth/capture_successful_external_authentication.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, auth) ⇒ CaptureSuccessfulExternalAuthentication

Returns a new instance of CaptureSuccessfulExternalAuthentication.



9
10
11
12
# File 'app/services/devise/multi_auth/capture_successful_external_authentication.rb', line 9

def initialize(user, auth)
  @user = user
  @auth = auth
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



8
9
10
# File 'app/services/devise/multi_auth/capture_successful_external_authentication.rb', line 8

def auth
  @auth
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'app/services/devise/multi_auth/capture_successful_external_authentication.rb', line 8

def user
  @user
end

Class Method Details

.call(user, auth = {}) ⇒ Object



3
4
5
6
# File 'app/services/devise/multi_auth/capture_successful_external_authentication.rb', line 3

def self.call(user, auth = {})
  return true unless auth.present?
  new(user, auth).call
end

Instance Method Details

#callObject



14
15
16
17
18
19
# File 'app/services/devise/multi_auth/capture_successful_external_authentication.rb', line 14

def call
  object = Authentication.where(user: user).where(auth.slice(:provider, :uid)).first_or_initialize
  object.access_token = auth.fetch(:credentials)[:token]
  object.refresh_token = auth.fetch(:credentials)[:refresh_token]
  object.save!
end