Created
March 25, 2010 16:45
-
-
Save ku1ik/343796 to your computer and use it in GitHub Desktop.
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
use Rack::Session::Cookie | |
use Rack::OpenID | |
use RailsWarden::Manager do |manager| | |
manager.default_strategies :openid | |
manager.failure_app = ExceptionsController | |
end | |
class OpenIDStrategy < Warden::Strategies::Base | |
def authenticate! | |
if resp = request.env['rack.openid.response'] | |
if resp.status == :failure || resp.status == :missing | |
fail! "OpenID authentication failed" | |
elsif resp.status == :cancel | |
fail! "OpenID authentication canceled" | |
elsif resp.status == :success | |
if user = User.first(:identity_url => resp.identity_url) | |
success! user | |
else | |
fail! "No user with given OpenID" | |
end | |
end | |
elsif openid_url = request.params[:openid_url] | |
custom!([401, { "WWW-Authenticate" => Rack::OpenID.build_header(:identifier => openid_url) }, []]) | |
end | |
end | |
end | |
Warden::Strategies.add(:openid, OpenIDStrategy) | |
class UsersController | |
def login | |
request.env["warden"].authenticate! | |
redirect_to "/dashboard" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment