Skip to content

Instantly share code, notes, and snippets.

@Swelly
Created September 26, 2013 01:26
Show Gist options
  • Save Swelly/6708612 to your computer and use it in GitHub Desktop.
Save Swelly/6708612 to your computer and use it in GitHub Desktop.
Omniauth callback with Twitter
group :development, :test do
gem 'rspec'
gem 'factory_girl_rails'
gem 'pry-rails' # Causes rails console to open pry
# https://github.com/rweng/pry-rails
gem 'pry-debugger' # Adds step, next, finish, and continue commands and breakpoints
# https://github.com/nixme/pry-debugger
gem 'pry-stack_explorer' # Navigate the call-stack
# https://github.com/pry/pry-stack_explorer
gem 'annotate' # Annotate all your models, tests, fixtures, and factories
# https://github.com/ctran/annotate_models
gem 'quiet_assets' # Turns off the Rails asset pipeline log
# https://github.com/evrone/quiet_assets
# gem 'better_errors' # Replaces the standard Rails error page with a much better and more useful error page
# https://github.com/charliesome/better_errors
gem 'binding_of_caller' # Advanced features for better_errors advanced features (REPL, local/instance variable inspection, pretty stack frame names)
# https://github.com/banister/binding_of_caller
gem 'meta_request' # Supporting gem for Rails Panel (Google Chrome extension for Rails development).
# https://github.com/dejan/rails_panel/tree/master/meta_request
gem 'rails-erd' # Diagrams your models. NOTE! $ brew install graphviz
# https://github.com/voormedia/rails-erd
gem 'rspec-rails', '~> 2.0' # Rspec-rails is a testing framework for Rails 3.x and 4.x.
gem 'dotenv-rails' # $touch .env
end
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_twitter_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Twitter") if is_navigational_format?
else
session["devise.twitter_data"] = request.env["omniauth.auth"]
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