Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Last active December 17, 2015 08:29
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 JonRowe/5580647 to your computer and use it in GitHub Desktop.
Save JonRowe/5580647 to your computer and use it in GitHub Desktop.
Omniauth setup
Warden::Strategies.add(:login) do
def authenticate!
throw :warden
end
end
WardenOmniAuth.on_callback do |hash|
HandleAuthentication.new(hash).user
end
Rails.application.config.middleware.instance_eval do
use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
provider :facebook, ENV['FACEBOOK_ID'], ENV['FACEBOOK_SECRET']
end
use Warden::Manager do |manager|
manager.default_strategies :login, :omni_twitter, :omni_facebook
manager.failure_app = proc do |env|
env['rack.session']['warden.pre_failure'] = env['ORIGINAL_FULLPATH']
[301,{ 'Location' => '/login', 'Content-Type' => 'text/redirect' },['Redirecting you to /login']]
end
manager.serialize_into_session do |user|
user.id
end
manager.serialize_from_session do |id|
MongoAdaptor.new('users',User).fetch(id)
end
end
use WardenOmniAuth do |config|
config.redirect_after_callback do |env|
env['rack.session'].delete('warden.pre_failure') || "/"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment