public
Description: A Project Management and Collaboration tool inspired by Basecamp
Home | Edit | New

Automatic Registration via OpenID

If you have some sort of corporate infrastructure and can’t face adding your millions of users to RailsCollab, then look no further. The pain-free solution is here!

Basically, you need to make use of RailsCollab’s OpenID support to automatically register users into the system. The following code is an example implementation of “openid_login” (in the access controller) which achieves this.


def openid_login
unless AppConfig.allow_openid
error_status(true, :invalid_request)
redirect_to :action => ‘login’
return
end

  1. Fields to grab from the OpenID Provider
    req_fields = [‘nickname’, ‘email’]
    opt_fields = [‘fullname’]
authenticate_with_open_id(params[:openid_url], {:required => req_fields, :optional => opt_fields}) do |result, identity_url, registration| if result.successful? log_user = User.openid_login(identity_url)
  1. User registered with the system?
    if log_user.nil?
  2. No, then find the “OpenID” company
    oid_company = Company.find(:first, :conditions => {’name’ => ’OpenID’})
  1. Construct the user, assigning them
    user = User.new(:display_name => registration[‘fullname’], :email => registration[‘email’])
    user.username = registration[‘nickname’]
    user.password = Base64.encode64(Digest::SHA1.digest(“#{rand(1<<64)}/#{Time.now.to_f}/#{user.username}”))[0..7]
    user.company = oid_company
    user.is_admin = false
    user.idetntity_url = identity_url
    user.auto_assign = false
unless user.save error_status(true, :failed_login_openid_url, {:openid_url => identity_url}) else
  1. Assign OpenID’s projects to user
    oid_company.projects.each { |project| user.projects << project }
    log_user = user
    end
    end
unless log_user.nil? error_status(false, :success_login_openid_url, {:openid_url => identity_url}) redirect_back_or_default :controller => ‘dashboard’ session[‘user_id’] = log_user.id return end redirect_to :action => ‘login’ elsif result.unsuccessful? if result == :canceled error_status(true, :verification_cancelled) elsif !identity_url.nil? error_status(true, :failed_verification_openid_url, {:openid_url => identity_url}) else error_status(true, :verification_failed) end redirect_to :action => ‘login’ else error_status(true, :unknown_response_status, {:status => result.message}) redirect_to :action => ‘login’ end end end

As noted in the code, the OpenID provider needs to at least supply ‘nickname’ and ‘email’ fields in the response. These are used to create the associated user for the OpenID.

Last edited by jamesu, Sat Nov 15 03:07:59 -0800 2008
Home | Edit | New
Versions: