Warden OpenID Strategy
$ gem install warden-openid
1. Configure Warden uses OpenID strategy
require 'warden-openid' use Rack::Session::Cookie use Rack::OpenID use Warden::Manager do |manager| manager.default_strategies :openid manager.failure_app = FailureApp end
2. Setup user finder
Warden::OpenID.configure do |config| config.user_finder do |response| User.find_by_identity_url(response.identity_url) end end
response is an instance of OpenID::Consumer::Response.
3. Create route and view
Example by Sinatra and Haml:
post '/signin' do authenticate! end %form(action='/signin' method='post') %input(type='text' name='openid_identifier') %input(type='submit' value='Sign in')
This strategy starts with openid_identifier parameter.
You may need to customize /unauthenticated route. Please refer to examples directory for details.
Fetch additional fields from server
Warden::OpenID.configure do |config| config.required_fields = 'email' config.optional_fields = %w(nickname fullname) config.user_finder do |response| fields = OpenID::SReg::Response.from_success_response(response) p fields['email'] p fields['nickname'] end end
If you use this with Rails, please don't use OpenID::Store::Memory. A problem occurs by class reloading in the development mode.
For example, OpenID::Store::Filesystem is used instead:
require 'openid/store/filesystem' Rails.configuration.middleware.use Rack::OpenID, OpenID::Store::Filesystem.new(Rails.root + 'tmp/openid')
Philip H. MacIver
Note on Patches/Pull Requests
Fork the project.
Make your feature addition or bug fix.
Add tests for it. This is important so I don't break it in a future version unintentionally.
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 Keita Urashima. See LICENSE for details.