Ruby OAuth GEM

What

This is a fork of the excellent OAuth RubyGem (github.com/mojodna/oauth) which adds support for the Typhoeus HTTP client library.

See the OAuth specs oauth.net/core/1.0/

Installing

sudo gem install typhoauth --source http://gemcutter.org

The source code is now hosted on the OAuth GitHub Project github.com/bkocik/typhoauth

The basics

This is a ruby library which is intended to be used in creating Ruby Consumer and Service Provider applications. It is NOT a Rails plugin, but could easily be used for the foundation for such a Rails plugin.

As a matter of fact it has been pulled out from an OAuth Rails Plugin code.google.com/p/oauth-plugin/ which now requires this GEM.

Demonstration of usage

Create a new consumer instance by passing it a configuration hash:

@consumer = OAuth::Consumer.new("key","secret", :site => "https://agree2")

Start the process by requesting a token

@request_token = @consumer.get_request_token
session[:request_token] = @request_token
redirect_to @request_token.authorize_url

When user returns create an access_token

@access_token = @request_token.get_access_token
@photos = @access_token.get('/photos.xml')

Now that you have an access token, you can use Typhoeus to interact with the OAuth provider if you choose.

oauth_params = {:consumer => oauth_consumer, :token => access_token}
hydra = Typhoeus::Hydra.new
req = Typhoeus::Request.new(uri, options) 
oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
req.headers.merge!({"Authorization" => oauth_helper.header}) # Signs the request
hydra.queue(req)
hydra.run
@response = req.response

Finally be sure to check out the OAuth RDoc Manual oauth.rubyforge.org/rdoc/ .

Documentation Wiki

There is some documentation on the Google Code project for the “OAuth Rails Plugin”:code.google.com/p/oauth-plugin/ :

Forum

groups.google.com/group/oauth-ruby

How to submit patches

Read the “8 steps for fixing other people’s code” drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/.

The source code is now hosted on the OAuth GitHub Project github.com/bkocik/typhoauth

To submit a patch, please fork the oauth project and create a patch with tests. Once you’re happy with it send a pull request.

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Send an email to [email protected]