Extension of the Authlogic library to add RPX support.
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.
lib
test
.gitignore
CHANGELOG.rdoc
MIT-LICENSE
Manifest.txt
README.rdoc
Rakefile
init.rb

README.rdoc

Authlogic RPX

Authlogic RPX is an extension of the Authlogic library to add RPX support. Authlogic v2.0 introduced an enhanced API that makes “plugging in” alternate authentication methods as easy as installing a gem.

Helpful links for Authlogic

* Documentation: authlogic.rubyforge.org * Authlogic: github.com/binarylogic/authlogic

Install and use

1. Make some simple changes to your database:

class AddUsersRpxIdentifier < ActiveRecord::Migration
  def self.up
    add_column :users, :rpx_identifier, :string
    add_index :users, :rpx_identifier

    change_column :users, :login, :string, :default => nil, :null => true
    change_column :users, :crypted_password, :string, :default => nil, :null => true
    change_column :users, :password_salt, :string, :default => nil, :null => true

  end

  def self.down
    remove_column :users, :rpx_identifier

    [:login, :crypted_password, :password_salt].each do |field|
      User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
      change_column :users, field, :string, :default => "", :null => false
    end
  end
end

2. Install the rpx_now plugin

$ script/plugin install git://github.com/grosser/rpx_now.git

2a. Configure the rpx_now plugin

Create an account at rpxnow.com and get your RPX API Key.

Add one of these to your views:

<%= RPXNow.embed_code('mywebsite',rpx_login_url) %>

..or..

<%= RPXNow.popup_code('Login with Facebook, Google or other account','mywebsite', rpx_login_url,:language=>'en') %>

Don't forgot to replace 'mywebsite' with the relevant realm for your site.

Make sure you have set up a route for rpx_login_url (RPX only returns a GET)

map.rpx_login 'login/rpx', :controller => 'user_sessions', :action => 'create'

Add the key to your relevant development environment:

RPXNow.api_key = 'YOUR RPX API KEY'

3. Install the Authlogic-Rpx gem (currently broken, use the plugin)

$ sudo gem install authlogic-rpx

Now add the gem dependency in your config:

config.gem "authlogic-rpx", :lib => "authlogic_rpx"

Or for older version of rails, install it as a plugin:

$ script/plugin install git://github.com/hunter/authlogic_rpx.git

4. Handling user data

The use case for originally building this was using the returned user data to inform the account creation form rather than setting the user attributes directly.

Authlogic RPX is currently not optimised for the Authlogic way of doing things so for the moment something like this will work:

In your user session controller

def create

@user_session = UserSession.new(params[:user_session])

if @user_session.save
  flash[:notice] = "Login successful!"
  redirect_back_or_default user_url(@user_session.user)
else
  if @user_session.rpx_data
    @user = User.new(@user_session.rpx_data)
    session.delete(:rpx_identifier)
    session[:rpx_identifier] = @rpx_identifier = @user_session.rpx_data[:rpx_identifier]
    render :template => "users/new"
  else
    render :action => :new
  end
end

end

In your user controller

def create

@user = User.new(params[:user])
@user.rpx_identifier = @rpx_identifier = session[:rpx_identifier] if session[:rpx_identifier]

# etc

end

TODO

Get Tests working Clean up registration data handling

Copyright © 2009 Hunter Nield of [Syndeo Labs](www.syndeolabs.com), released under the MIT license