class ExternalAuthentication
Attributes
auth_hash[R]
Public Class Methods
new(auth_hash)
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 2 def initialize(auth_hash) @auth_hash = auth_hash end
Public Instance Methods
perform()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 6 def perform if scope.exists? scope.first else transaction { scope.create(user: user) } end end
Private Instance Methods
create_user()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 22 def create_user Oath::Services::SignUp.new(user_params).perform end
credential_params()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 49 def credential_params { provider: auth_hash["provider"], uid: auth_hash["uid"] } end
email()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 37 def email auth_hash["info"]["email"] end
random_password()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 41 def random_password SecureRandom.hex end
scope()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 45 def scope ExternalCredential.where(credential_params) end
transaction(&block)
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 26 def transaction(&block) ExternalCredential.transaction(&block) end
user()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 18 def user User.find_by(email: email) || create_user end
user_params()
click to toggle source
# File lib/generators/oath/templates/app/services/external_authentication.rb, line 30 def user_params { email: email, password: random_password } end