Giter Club home page Giter Club logo

oauth-ruby's Introduction

Ruby OAuth

Status

<img src=“https://travis-ci.org/oauth-xx/oauth-ruby.svg?branch=master” alt=“Build Status” />

What

This is a RubyGem for implementing both OAuth clients and servers in Ruby applications.

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

Installing

sudo gem install oauth

The source code is now hosted on the OAuth GitHub Project github.com/oauth-xx/oauth-ruby

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 GEM (rubygems.org/gems/oauth-plugin github.com/pelle/oauth-plugin) which now uses this gem as a dependency.

Demonstration of usage

We need to specify the oauth_callback url explicitly, otherwise it defaults to “oob” (Out of Band)

@callback_url = "http://127.0.0.1:3000/oauth/callback"

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(:oauth_callback => @callback_url)

session[:token] = request_token.token
session[:token_secret] = request_token.secret
redirect_to @request_token.authorize_url(:oauth_callback => @callback_url)

When user returns create an access_token

hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
request_token  = OAuth::RequestToken.from_hash(@consumer, hash)
@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.

require 'oauth/request_proxy/typhoeus_request'
oauth_params = {:consumer => oauth_consumer, :token => access_token}
hydra = Typhoeus::Hydra.new
req = Typhoeus::Request.new(uri, options) # :method needs to be specified in options
oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
req.options[:headers].merge!({"Authorization" => oauth_helper.header}) # Signs the request
hydra.queue(req)
hydra.run
@response = req.response

More Information

How to submit patches

The source code is now hosted on the OAuth GitHub Project github.com/oauth-xx/oauth-ruby

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 and post a message to the google group.

License

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

Contact

OAuth Ruby has been created and maintained by a large number of talented individuals. The current maintainer is Aaron Quint (quirkey).

Comments are welcome. Send an email to via the OAuth Ruby mailing list groups.google.com/group/oauth-ruby

oauth-ruby's People

Contributors

afeld avatar andrehjr avatar bkocik avatar cfeller avatar clifff avatar ecavazos avatar ehartmann avatar galois17 avatar hayeah avatar jamesharker avatar jdsiegel avatar jimmyz avatar jonathonma avatar jremmen avatar jurisgalang avatar kellan avatar kevinhughes27 avatar lackac avatar mojodna avatar mpapis avatar oldgreen avatar pelle avatar quirkey avatar raeno avatar shaliko avatar shammond42 avatar sutto avatar th1agoalmeida avatar til avatar xaviershay avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.