Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Created July 10, 2012 05:53
Show Gist options
  • Save amitpatelx/3081430 to your computer and use it in GitHub Desktop.
Save amitpatelx/3081430 to your computer and use it in GitHub Desktop.
OmniAuth callback controller with twitter handler
#app/controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
# You need to implement the method below in your model
auth = env["omniauth.auth"]
@user = user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.new
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.twitter_uid"] = auth["uid"]
redirect_to new_user_registration_url
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment