Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Thin OpenID Wrapper for Ruby on Rails using ruby-openid gem.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time



Thin OpenID Consumer Wrapper for Ruby on Rails using ruby-openid gem.


It helps to keep your session controller nice and clean and provides some handy methods such as begin_openid, complete_openid and openid_params.


The goal is to have openid consumer wrapper, what follows more closely the spirit of OpenID spec and the same time provides some handy methods.

No more you need squeezed openid through one method as in the original plugin, enjoy same clarity as you will find in OpenID spec, so it means when you start request then you just use method begin_openid (aliased to create_openid) and when you complete your request, then use method complete_openid.

note: this wrapper is made openid only in mind, so that's why it might not be the quickest fit for you if you also need old way of username-password authentication, however they play nice together if you want so.


First you need Rails 2.1.0 or newer.

Start with:

gem sources -a
sudo gem install priit-openid_wrapper

Add to config/environment.rb:

config.gem 'priit-openid_wrapper', :lib => 'openid_wrapper', :source => ''

Add to config/routes.rb:

map.resources :users

# OpenID spec does not honor RESTful design,
# so we need add complete action as well.
map.resources :sessions, :collection => {:complete => :get}

# some handy shortcuts, you can use as link_to 'Signup', signup_path
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'

Add to app/controller/sessions_controller.rb

def create
  begin_openid # you can change defaults like :return_url => complete_sessions_url etc
               # take a look lib/openid_wrapper/openid_wrapper.rb def begin_openid

def complete
  case complete_openid.status
    when :success
      user = User.find_by_openid_identifier(params[:openid][:openid_identifier])
      if user.nil?
        user = User.create(params[:openid])
      session[:current_user_id] =
      flash[:success] = "Logged in succesfully!"
      return redirect_to root_path
    when :failure
      flash[:error] = 'Something went wrong!'
    when :cancel
      flash[:error] = 'Openid login cancelled!' 
    when :setup_needed
      flash[:notice] = 'Openid setup needed!'
  return redirect_to root_path

Add to app/views/users/new.html.haml:

- form_tag sessions_path do
  = text_field_tag :openid_identifier
  = submit_tag 'Login'

Additional Tips and Notes

  • Make OpenID identifier field more nuby friendly and

add OpenID official selector from

  • OpenID Wrapper will generate log entry: ** openid_wrapper: initialized properly.

How to contribute?

You are welcome to clone it at your favourite git repository:

Check out TODO file to find out some pending tasks or do whatever you like to improve. Just send merge request, when you like to push your improvements.

General Info about OpenID

OpenID Authentication 2.0 - final specifications

History and Credits

* OpenID Authentication plugin started by David Heinemeier Hansson.[1]
* Alex Gorbatchev made complete clean up without changing original API.[2]
* Priit Tamboom made complete API change as well and gemified it.[3]



Copyright © 2008 Priit Tamboom, released under the MIT license

Something went wrong with that request. Please try again.