Skip to content

Instantly share code, notes, and snippets.

@guiltry
Created April 5, 2015 06:37
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 guiltry/568bebef711c8c92119e to your computer and use it in GitHub Desktop.
Save guiltry/568bebef711c8c92119e to your computer and use it in GitHub Desktop.
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def self.provides_callback_for(provider)
class_eval %Q{
def #{provider}
# NOTE:
# Extract Oauth logic to a new ruby class.
@user = FactoryMethod::User.create("#{provider}", env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
}
end
[:facebook, :google_oauth2].each do |provider|
provides_callback_for provider
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment