A warden strategy for authenticate with OpenID
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples/sinatra
lib
spec
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
warden-openid.gemspec

README.rdoc

Warden OpenID Strategy

Install

$ gem install warden-openid

Usage

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

Caveats

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')

Contributors

  • 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

Copyright © 2010 Keita Urashima. See LICENSE for details.