remi / rack-oauth

Rack Middleware for OAuth Authorization

This URL has Read+Write access

remi (author)
Mon Oct 26 09:02:38 -0700 2009
commit  d9fdb00fdc5d94ec042f752ea913558172cd51d0
tree    0a779e2e06c2418845a91931468cd656f35af24f
parent  f43a76db150735be65e3565ad16a43f999f639e8
name age message
file .gitignore Loading commit data...
file README.rdoc
file Rakefile
file VERSION
directory lib/
file rack-oauth.gemspec
README.rdoc

Rack::OAuth

Rack::OAuth is a Rack middleware for easily integrating OAuth into your Ruby web applications.

Installation

  $ gem sources -a http://gems.github.com
  $ sudo gem install remi-rack-oauth

Rack::OAuth requires the rack and oauth gems (and json, although this can be overriden)

  $ sudo gem install rack oauth json

Usage

To quickly see how to use this, you might want to check out the screencast at remi.org

You can also view the RDoc at code.remi.org/rack-oauth

  use Rack::OAuth, :key => 'abc', :secret => '123', :site => 'http://twitter.com'

This will use all of the defaults:

  • visiting /oauth_login will setup an OAuth request and redirect the user to login to the OAuth provider
  • /oauth_complete is where we redirect to after OAuth authorization is complete
  • session[:oauth_user] will return a hash with the OAuth account information (if a user was authorized)

There are a number of defaults that can be overridden. Defaults can be viewed at code.remi.org/rack-oauth/classes/Rack/OAuth.html

  use Rack::OAuth, :key          => 'abc',
                   :secret       => '123',
                   :site         => 'http://twitter.com',
                   :login        => '/path_that_will_goto_oauth_providers_login',
                   :redirect     => '/path_to_redirect_to_after_oauth_authorization',
                   :session_key  => 'name_of_session_variable_to_store_oauth_user_info_in',
                   :rack_session => 'name_of_rack_session_variable',
                   :json_parser  => lambda {|json_string| return SomeParser.parse(json_string) }

Notes

Rack::OAuth was created to work with Twitter OAuth and has, thus far, only been tested using Twitter’s OAuth. If this doesn’t work for you for a different OAuth provider, please let me know! Or, if you patch Rack::OAuth to support another provider, please send me a pull request with the patch.

Also, I haven’t added any specs yet. My bad.