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.
To install OmniAuth, simply install the gem:
gem install omniauth
OmniAuth currently supports the following external providers:
-
via OAuth (OAuth 1.0, OAuth 2, and xAuth)
-
37signals ID
-
Bit.ly (credit: philnash)
-
Dopplr (credit: flextrip)
-
Facebook
-
Foursquare
-
GitHub
-
GoodReads (credit: cristoffer)
-
Gowalla (credit: kvnsmth)
-
Hyves (credit: mrdg)
-
Identi.ca (credit: dcu)
-
LinkedIn
-
Meetup (credit coderoshi)
-
Netflix (credit: caged)
-
SmugMug (credit: pchilton)
-
SoundCloud (credit: leemartin)
-
TradeMe (credit: pchilton)
-
TripIt (credit: flextrip)
-
Twitter
-
Vimeo (credit: jamiew)
-
YouTube (credit: jamiew)
-
Tsina (credit: he9qi)
-
T163 (credit: he9qi)
-
Tsohu (credit: he9qi)
-
Tqq (credit: he9qi)
-
Netflix (credit: caged)
-
Miso (credit: rickenharp)
-
DailyMile (credit: cdmwebs)
-
Instagram (credit: kiyoshi)
-
Mixi (credit: kiyoshi)
-
Evernote (credit: szimek)
-
Doit.im (credit: chouti)
-
Instapaper (credit: micpringle)
-
Identi.ca (credit: dcu)
-
Gowalla (credit: kvnsmth)
-
Dopplr (credit: flextrip)
-
TripIt (credit: flextrip)
-
Meetup (credit coderoshi)
-
SoundCloud (credit: leemartin)
-
SmugMug (credit: pchilton)
-
-
OpenID
-
Google Apps (via OpenID)
-
CAS (Central Authentication Service) (credit: jamesarosen)
-
LDAP (credit: pyu10055)
-
Renren (Renren Connect of renren.com) (credit: taweili, rainux)
-
via OA-More
- Flickr (credit: pchilton)
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 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.
The best place to find more information is the OmniAuth Wiki. Some specific information you might be interested in:
OmniAuth is licensed under the MIT License.