Giter VIP home page Giter VIP logo

warden_oauth's Introduction

warden_oauth

warden_oauth enhances the Warden authentication framework, offering a simple interface for creating oauth strategies.

Getting Started

To get started you just have to require the warden_oauth libraries, and setup the oauth services you would like to have on the Warden::Manager middleware declaration:

Warden::Manager do |config|
  config.failure_app = FailureApp
  config.oauth(:twitter) do |twitter|
    twitter.consumer_secret = <YOUR CONSUMER SECRET>
    twitter.consumer_key  = <YOUR CONSUMER KEY>
    twitter.options :site => 'http://twitter.com'
  end
  config.default_strategies(:twitter_oauth, :password, :other)
end

Giving an Access Token fetcher

Users get identified on a system via an access_token and an access_secret, when a valid access_token is recevied, warden_oauth calls a fetcher declared on Warden::OAuth.access_token_user_finder(:<strategy_key>).

Warden::OAuth.access_token_user_finder(:twitter) do |access_token|
  User.find_by_access_token_and_access_secret(access_token.token, access_token.secret)
end

If a user is returned, then this is the user that is going to be authenticated in the session, otherwise the FailureApp will be called, you may check the env['warden.options'][:oauth][:access_token] to check the original access_token and <bold>create a new user</bold> from there if desired.

Strategy Class info

When you declare an oauth strategy on the Warden::Config initialization, (e.g. config.oauth(:service_name)) a Warden::OAuth::Strategy::ServiceName will be declared, at the same time this class will be registered as :service_name_oauth on the Warden::Strategies.

So when we have a declaration like the one we have in the Getting Started section, we will have an Strategy class called Warden::OAuth::Strategy::Twitter, and this will be registered as :twitter_oauth on the Warden::Strategies.

Running the Strategy

In order to get the strategy running in the app, you have to specify a parameter called warden_oauth_provider with the name of the oauth service you want to use. So for example, if you would like to boot the twitter oauth example given on the “Getting Started” section you just have to specify the parameter on a protected url.

In Rails:

link_to 'Twitter Authentication', url_for(login_path(:warden_oauth_provider => 'twitter'))

There can be 3 different outcomes from this strategy:

  1. The OAuth credentials are invalid and the FailureApp is called.

  2. The OAuth credentials are valid, but there is no user associated to them. In this case the FailureApp is called, but the env[:oauth] will be available.

  3. The OAuth credentials are valid, and the user is authenticated successfuly.

Note:

In Rails, don’t set the :warden_oauth_provider parameter as part of the login route, if you do this, rails will catch the parameter, but not the warden rack middleware, ergo, it won’t work as expected.

Examples

If you want to know how to make a twitter authentication client, check examples/twitter/application.rb

Note on Patches/Pull Requests

For any error send an email to: romanandreg [at] gmail [dot] com

Copyright © 2009 Roman Gonzalez. See LICENSE for details.

warden_oauth's People

Contributors

roman avatar

Stargazers

Michael Reyes avatar Angus H. avatar Rob avatar 墨神 avatar  avatar  avatar Jason Lewis avatar Szikszai Gusztáv avatar Heinrich Lee Yu avatar Hristo Kochev avatar  avatar Eric Paschoalick Chaves avatar Seth Vincent avatar Drew Delianides avatar Lin He avatar Felix Roeser avatar Emilio Cavazos avatar Hedgehog avatar Yacin Bahi, PhD. avatar Son Jungwook avatar Kawashima avatar Qi He avatar Colin Frame avatar Ryan McKillen avatar Benjamin Quorning avatar Graeme Nelson avatar koyachi avatar Justin Smestad avatar Georg Leciejewski avatar  avatar Masafumi Fujiwara avatar Akihiro Matsumura avatar Ilya Grigorik avatar  avatar Grant Goodale avatar Keita Urashima avatar Kaz avatar  avatar fabrizio avatar Lalit Shandilya avatar Aaron Eisenberger avatar Eoin Hennessy avatar Alex Semyonov avatar Ivar Vasara avatar Hans Petter Wilhelmsen avatar Clemens Kofler avatar  avatar Orlin M Bozhinov avatar Calvin Yu avatar Kakutani Shintaro avatar Carlos Brando avatar Luca G. Soave avatar Cleiton Francisco avatar Aaron Quint avatar Rich Manalang avatar Pius Uzamere avatar Brian Smith avatar

Watchers

James Scott, Jr avatar James Cloos avatar  avatar  avatar

warden_oauth's Issues

multiple oauth providers won't work at the same time

(As noted by Steven Parkes)

I'm using warden_oauth against both twitter and linkedin (in the context for devise, if that matters).

The problem I'm coming up against is that when I get the redirect back from the oauth provider, it again goes through all the strategies. The authenticate! for each strategy sees that it has the right URL parameter and goes on to do the find_user_by_access_token. But if the auth is through the second provider, this is wrong when checking the first provider, and it errors out because it's getting the wrong token.

Does that makes sense? The summary is that multiple oauth strategies have to be able to differentiate themselves.

Not sure the best way to do this. I could have different callback URLs, but that's getting overridden in #request_token right now.

I can hack it, but I'm wondering what you thought the best approach would be.

OAuth custom callback_url

I see that you are using host_with_port as the default callback url when requesting a token. I think we should have a way of specifying this. Why not use the current url instead of just the current host and port?

This way we can use some_callback_url(:warden_oauth_provider => 'something'). And the 'some_callback' path will be used

I need to populate user twitter data in my local db

It seems "Warden::OAuth.access_token_user_finder(:twitter) do |access_token|" can be used to retrieve the access token and secret for the twitter user. However, what if we want to store other twitter information in our db, such as full_name, screen_name, url, etc?

Do we have to make another call to the Twitter api? Or does this gem support a method for this already?

How should this be done?

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.