7.8 KiB
OmniAuth: Standardized Multi-Provider Authentication
OmniAuth is a new Rack-based authentication system for multi-provider external authentcation. OmniAuth is built from the ground up on the philosophy that authentication is not the same as identity, and is based on two observations:
- The traditional 'sign up using a login and password' model is becoming the exception, not the rule. Modern web applications offer external authentication via OpenID, Facebook, and/or OAuth.
- The interconnectable web is no longer a dream, it is a necessity. It is not unreasonable to expect that one application may need to be able to connect to one, three, or twelve other services. Modern authentication systems should allow a user's identity to be associated with many authentications.
Installation
To install OmniAuth, simply install the gem:
gem install omniauth
Continuous Integration
Providers
OmniAuth currently supports the following external providers:
- via OAuth (OAuth 1.0, OAuth 2, and xAuth)
- 37signals ID (credit: mbleigh)
- Bit.ly (credit: philnash)
- Blogger (credit: dsueiro-backing)
- Cobot (credit: kamal)
- DailyMile (credit: cdmwebs)
- Doit.im (credit: chouti)
- Dopplr (credit: flextrip)
- Douban (credit: quake)
- Evernote (credit: szimek)
- Facebook (credit: mbleigh)
- Foursquare (credit: mbleigh)
- GitHub (credit: mbleigh)
- Glitch (credit: harrylove)
- GoodReads (credit: cristoffer)
- Google Health (credit: jaigouk)
- Gowalla (credit: kvnsmth)
- Hyves (credit: mrdg)
- Identi.ca (credit: dcu)
- Flattr (credit: dcu)
- Instagram (credit: kiyoshi)
- Instapaper (credit: micpringle)
- LastFM (credit: tictoc)
- LinkedIn (credit: mbleigh)
- Mailru (credit: lexer)
- Meetup (credit coderoshi)
- Miso (credit: rickenharp)
- Mixi (credit: kiyoshi)
- Netflix (credit: caged)
- Orkut (credit: andersonleite)
- Plurk (credit: albb0920)
- Qzone (credit: quake)
- Rdio (via brandonweiss)
- Renren (credit: quake)
- Salesforce (via CloudSpokes)
- SmugMug (credit: pchilton)
- SoundCloud (credit: leemartin)
- T163 (credit: quake)
- Taobao (credit: l4u)
- TeamBox (credit jrom)
- Tqq (credit: quake)
- TradeMe (credit: pchilton)
- TripIt (credit: flextrip)
- Tsina (credit: quake)
- Tsohu (credit: quake)
- Tumblr (credit: jamiew)
- Twitter (credit: mbleigh)
- Vimeo (credit: jamiew)
- Vkontakte (credit: german)
- WePay (credit: ryanwood)
- Yahoo (credit: mpd)
- Yammer (credit: kltcalamay)
- YouTube (credit: jamiew)
- CAS (Central Authentication Service) (credit: jamesarosen)
- Flickr (credit: pchilton)
- Google Apps (via OpenID) (credit: mbleigh)
- Google OpenID+OAuth (via Hybrid Protocol) (credit: boyvanamstel)
- LDAP (credit: pyu10055)
- OpenID (credit: mbleigh)
- Yupoo (credit: chouti)
Compatibility
OmniAuth is tested against the following Ruby versions:
- 1.8.7
- 1.9.1
- 1.9.2
- JRuby (note, the Evernote strategy is not available for JRuby)
- Rubinius
- REE
Usage
OmniAuth is a collection of Rack middleware. To use a single strategy, you simply need to add the middleware:
require 'oa-oauth'
use OmniAuth::Strategies::Twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
Now to initiate authentication you merely need to redirect the user to /auth/twitter
via a link or other means. Once the user has authenticated to Twitter, they will be redirected to /auth/twitter/callback
. You should build an endpoint that handles this URL, at which point you will have access to the authentication information through the omniauth.auth
parameter of the Rack environment. For example, in Sinatra you would do something like this:
get '/auth/twitter/callback' do
auth_hash = request.env['omniauth.auth']
end
The hash in question will look something like this:
{
'uid' => '12356',
'provider' => 'twitter',
'user_info' => {
'name' => 'User Name',
'nickname' => 'username',
# ...
}
}
The user_info
hash will automatically be populated with as much information about the user as OmniAuth was able to pull from the given API or authentication provider.
Resources
The best place to find more information is the OmniAuth Wiki. Some specific information you might be interested in:
OmniAuth Core
Supported Rubies
This library aims to support and is tested against the following Ruby implementations:
- Ruby 1.8.7
- Ruby 1.9.2
- JRuby
- Rubinius
- Ruby Enterprise Edition
If something doesn't work on one of these interpreters, it should be considered a bug.
This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.
If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be personally responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped.
License
OmniAuth is licensed under the MIT License.