twitter_authentication icon indicating copy to clipboard operation
twitter_authentication copied to clipboard

Sign in with Twitter OAuth: A Rails Generator plugin

                        Twitter Authentication

This is a "Sign in with Twitter"-oauth authorization generator for rails, based closely on the restful_authentication plugin by Rick Olson which can be found at http://github.com/technoweenie/restful-authentication/tree/master.

"Sign in with Twitter" is the pattern of authentication that allows users to connect their Twitter account with third-party services in as little as one click.

Step 1 - Installation:

./script/plugin install git://github.com/corbanbrook/twitter_authentication.git

Step 2 - Generate Authentication System:

./script/generate twitter_authenticated user sessions

The first parameter specifies the model that bootstraps the twitter account (typically a user or account model).

The second parameter specifies the sessions controller name. This is the controller that handles the actual login/logout function on the site.

Step 3 - Migrate User Account Model

View the created migration and see if it meets your need. This model bootstaps itself onto the users twitter account and caches all user details. Any additional fields you require to store should be added to the migration at this time.

./rake db:migrate RAILS_ENV=development|production

Step 4 - Register Application with Twitter:

Visit http://twitter.com/oauth_clients/ and register a new application.

Point the Callback url to: http://your.application.url/sessions/callback

Upon completion you will receive a consumer key and secret you will need to add to config/twitter_oauth.yml

Step 5 - Add Authentication to your Controllers

To add authentication to protect your controllers use a before_filter

ie.

before_filter :login_required
  • Now your application should be ready to go? *

Requirements:

  • Twitter gem by John NuneMaker http://twitter.rubyforge.org/ an API wrapper for Twitter and Twitter Search API's

    gem install twitter

API

  • login_required

    Use on controllers to autheticate access to individual pages.

    ie.

    class UsersController < ApplicationController before_filter :login_required, :except => 'index' .. end

  • authorized?, logged_in?

    Show the logged in state of the user.

@corban weare.buildingsky.net


   Copyright (c) 2009 Corban Brook, released under the MIT license