Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Created March 25, 2010 16:45
Show Gist options
  • Save ku1ik/343796 to your computer and use it in GitHub Desktop.
Save ku1ik/343796 to your computer and use it in GitHub Desktop.
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