Last active
December 17, 2015 08:29
-
-
Save JonRowe/5580647 to your computer and use it in GitHub Desktop.
Omniauth setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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