Skip to content

Instantly share code, notes, and snippets.

@nbudin
Created March 31, 2010 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nbudin/350849 to your computer and use it in GitHub Desktop.
Save nbudin/350849 to your computer and use it in GitHub Desktop.
Warden::Strategies.add(:openid) do
def valid?
!params["openid_identifier"].blank?
end
def authenticate!
if resp = env[Rack::OpenID::RESPONSE]
RAILS_DEFAULT_LOGGER.info "Attempting OpenID auth: #{env["rack.openid.response"].inspect}"
case resp.status
when :success
u = Person.find_for_authentication(:openid_url => resp.identity_url)
success!(u)
when :cancel
fail!("OpenID auth cancelled")
when :failure
fail!("OpenID auth failed")
end
else
header_data = Rack::OpenID.build_header(:identifier => params["openid_identifier"])
RAILS_DEFAULT_LOGGER.info header_data
custom!([401, {
Rack::OpenID::AUTHENTICATE_HEADER => header_data
}, "Sign in with OpenID"])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment