OneClick

Let your users register with one click using open standards for authenticating. Currently supporting only Twitter. Tested in Rails 2.3.5. Should work in all 2.3 version. Probably not Rails 3.

Currently supporting only MongoMapper! Will support ActiveRecord and more platforms (Facebook, OpenID) eventually.

Requirements

Needs twitter_oauth.

sudo gem install twitter_oauth

Installation

sudo gem install one_click

environment.rb

config.gem "one_click"

Configuration

Add an initializer in config/initializers for example one_click_config.rb;

OneClick.config = {

:twitter => { :key => ‘your key’, :secret => ‘your secret’ }

}

User Model

User model needs to extend OneClickUser and associate twitter (one), like so:

class User < OneClickUser

one :twitter

end

The Twitter object is automatically maintained by the gem.

Usage

Using the gem is easy. There are three defined routes:

map. '/login/callback',	:controller => :sessions, :action => 'callback'
map. '/login/:service',	:controller => :sessions, :action => 'login'
map. '/logout',		:controller => :sessions, :action => 'logout'

Access /login/twitter to login with Twitter. Once logged in, a new User is created with a twitter profile associated if it didn’t already exist. The created User is blank.

To access the currently logged in user simply call ‘current_user’.

There are three helper methods; ‘requires_login’, ‘requires_logout’ and ‘logged_in?’. So to set up a page which requires login simply use a before filter;

class AdminController < ApplicationController

before_filter :requires_login

def index # Something nifty end

end