Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Forked from kamal/gist:269412
Created February 22, 2010 13:32

Revisions

  1. @kamal kamal created this gist Jan 5, 2010.
    27 changes: 27 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    require "rack/openid"
    require "warden"

    use Rack::OpenID
    use Warden::Manager do |manager|
    Warden::Strategies.add(:openid) do
    def authenticate!
    if resp = env["rack.openid.response"]
    case resp.status
    when :success
    u = User.find_by_identity_url(resp.identity_url)
    success!(u)
    when :cancel
    fail!("OpenID auth cancelled")
    when :failure
    fail!("OpenID auth failed")
    end
    else
    custom!([401, {"WWW-Authenticate" => 'OpenID identifier="https://www.google.com/accounts/o8/id"'}, "OpenID plz"])
    end
    end
    end
    manager.default_strategies :openid
    manager.failure_app = lambda do
    Rack::Response.new("Failed").finish
    end
    end