Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created June 23, 2020 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancom/2e2f37f12d7fd07e72e49ff6f00d309a to your computer and use it in GitHub Desktop.
Save stephancom/2e2f37f12d7fd07e72e49ff6f00d309a to your computer and use it in GitHub Desktop.
pretty version of oath creation
# ___ _ _ __ __
# .' `. (_) / |_[ | | ]
# / .-. \ _ .--..--. _ .--. __ ,--. __ _ `| |-'| |--. .---. .--.| |
# | | | |[ `.-. .-. | [ `.-. | [ | `'_\ :[ | | | | | | .-. |/ /__\\/ /'`\' |
# \ `-' / | | | | | | | | | | | | // | |,| \_/ |,| |, | | | || \__.,| \__/ |
# `.___.' [___||__||__][___||__][___]\'-;__/'.__.'_/\__/[___]|__]'.__.' '.__.;__]
#
# Facebook, Google, Apple, the world?
module Omniauthed
extend ActiveSupport::Concern
included do
has_many :authorizations, dependent: :destroy
end
class_methods do
def from_omniauth(oauth)
auth = Authorization.where(oauth.slice(:provider, :uid)).first_or_create do |new_auth|
new_auth.user = User.where(email: oauth.info.email).first_or_create do |new_user|
new_user.password = Devise.friendly_token
new_user.full_name = oauth.info.name
new_user.avatar = auth.info.image
end
end
auth.user
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment