omniauth 0.3.0.rc3 → 1.0.0.pr1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ !.autotest
2
+ !.document
3
+ !.gemtest
4
+ !.gitignore
5
+ !.rspec
6
+ !.yardopts
7
+ *.gem
8
+ *.rbc
9
+ *.sw[a-z]
10
+ *.tmproj
11
+ *.tmproject
12
+ *.un~
13
+ *~
14
+ .*
15
+ .DS_Store
16
+ .Spotlight-V100
17
+ .Trashes
18
+ .\#*
19
+ ._*
20
+ .bundle
21
+ .config
22
+ .directory
23
+ .elc
24
+ .loadpath
25
+ .project
26
+ .redcar
27
+ .rvmrc
28
+ .yardoc
29
+ /.emacs.desktop
30
+ /.emacs.desktop.lock
31
+ /live
32
+ Desktop.ini
33
+ Gemfile.lock
34
+ Icon?
35
+ InstalledFiles
36
+ Session.vim
37
+ Thumbs.db
38
+ \#*
39
+ \#*\#
40
+ _yardoc
41
+ auto-save-list
42
+ coverage
43
+ dist/*
44
+ doc
45
+ doc/
46
+ lib/bundler/man
47
+ oa-live
48
+ pkg
49
+ pkg/*
50
+ rdoc
51
+ spec/reports
52
+ test/tmp
53
+ test/version_tmp
54
+ tmp
55
+ tmtags
56
+ tramp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - jruby
5
+ - rbx
6
+ - rbx-2.0
7
+ - ree
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --markup markdown
2
+ --markup-provider maruku
3
+ -
4
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'guard-bundler'
9
+ gem 'growl'
10
+ gem 'rb-fsevent'
11
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec/" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch(/^.+\.gemspec/)
10
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Michael Bleigh, Erik Michaels-Ober, and Intridea, Inc.
1
+ Copyright (c) 2010-2011 Michael Bleigh and Intridea, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,155 +1,133 @@
1
1
  # OmniAuth: Standardized Multi-Provider Authentication
2
- OmniAuth is a new Rack-based authentication system for multi-provider external
3
- authentcation. OmniAuth is built from the ground up on the philosophy that
4
- **authentication is not the same as identity**, and is based on two
5
- observations:
6
-
7
- 1. The traditional 'sign up using a login and password' model is becoming the
8
- exception, not the rule. Modern web applications offer external
9
- authentication via OpenID, Facebook, and/or OAuth.
10
- 2. The interconnectable web is no longer a dream, it is a necessity. It is not
11
- unreasonable to expect that one application may need to be able to connect
12
- to one, three, or twelve other services. Modern authentication systems
13
- should allow a user's identity to be associated with many authentications.
14
-
15
- ## <a name="installation">Installation</a>
16
- To install OmniAuth, simply install the gem:
17
-
18
- gem install omniauth
19
-
20
- ## <a name="ci">Continuous Integration</a>
21
- [![Build Status](https://travis-ci.org/intridea/omniauth.png)](http://travis-ci.org/intridea/omniauth)
22
-
23
- ## <a name="providers">Providers</a>
24
- OmniAuth currently supports the following external providers:
25
-
26
- * via OAuth (OAuth 1.0, OAuth 2, and xAuth)
27
- * 37signals ID (credit: [mbleigh](https://github.com/mbleigh))
28
- * AngelList (credit: [joshuaxls](https://github.com/joshuaxls))
29
- * Bit.ly (credit: [philnash](https://github.com/philnash))
30
- * Blogger (credit: [dsueiro-backing](https://github.com/dsueiro-backing))
31
- * Cobot (credit: [kamal](https://github.com/kamal))
32
- * DailyMile (credit: [cdmwebs](https://github.com/cdmwebs))
33
- * Doit.im (credit: [chouti](https://github.com/chouti))
34
- * Dopplr (credit: [flextrip](https://github.com/flextrip))
35
- * Douban (credit: [quake](https://github.com/quake))
36
- * Evernote (credit: [szimek](https://github.com/szimek))
37
- * Facebook (credit: [mbleigh](https://github.com/mbleigh))
38
- * Foursquare (credit: [mbleigh](https://github.com/mbleigh))
39
- * GitHub (credit: [mbleigh](https://github.com/mbleigh))
40
- * Glitch (credit: [harrylove](https://github.com/harrylove))
41
- * GoodReads (credit: [cristoffer](https://github.com/christoffer))
42
- * Google Health (credit: [jaigouk](https://github.com/jaigouk))
43
- * Gowalla (credit: [kvnsmth](https://github.com/kvnsmth))
44
- * Hyves (credit: [mrdg](https://github.com/mrdg))
45
- * Identi.ca (credit: [dcu](https://github.com/dcu))
46
- * Flattr (credit: [dcu](https://github.com/dcu))
47
- * Instagram (credit: [kiyoshi](https://github.com/kiyoshi))
48
- * Instapaper (credit: [micpringle](https://github.com/micpringle))
49
- * LastFM (credit: [tictoc](https://github.com/tictoc))
50
- * LinkedIn (credit: [mbleigh](https://github.com/mbleigh))
51
- * Mailchimp (via [srbiv](http://github.com/srbiv))
52
- * Mailru (credit: [lexer](https://github.com/lexer))
53
- * Meetup (credit [coderoshi](https://github.com/coderoshi))
54
- * Miso (credit: [rickenharp](https://github.com/rickenharp))
55
- * Mixi (credit: [kiyoshi](https://github.com/kiyoshi))
56
- * Netflix (credit: [caged](https://github.com/caged))
57
- * Orkut (credit: [andersonleite](https://github.com/andersonleite))
58
- * Plurk (credit: [albb0920](http://github.com/albb0920))
59
- * Qzone (credit: [quake](https://github.com/quake))
60
- * Rdio (via [brandonweiss](https://github.com/brandonweiss))
61
- * Renren (credit: [quake](https://github.com/quake))
62
- * Salesforce (via [CloudSpokes](http://www.cloudspokes.com))
63
- * SmugMug (credit: [pchilton](https://github.com/pchilton))
64
- * SoundCloud (credit: [leemartin](https://github.com/leemartin))
65
- * T163 (credit: [quake](https://github.com/quake))
66
- * Taobao (credit: [l4u](https://github.com/l4u))
67
- * TeamBox (credit [jrom](https://github.com/jrom))
68
- * Tqq (credit: [quake](https://github.com/quake))
69
- * TradeMe (credit: [pchilton](https://github.com/pchilton))
70
- * TripIt (credit: [flextrip](https://github.com/flextrip))
71
- * Tsina (credit: [quake](https://github.com/quake))
72
- * Tsohu (credit: [quake](https://github.com/quake))
73
- * Tumblr (credit: [jamiew](https://github.com/jamiew))
74
- * Twitter (credit: [mbleigh](https://github.com/mbleigh))
75
- * Viadeo (credit: [guillaug](https://github.com/guillaug))
76
- * Vimeo (credit: [jamiew](https://github.com/jamiew))
77
- * Vkontakte (credit: [german](https://github.com/german))
78
- * WePay (credit: [ryanwood](https://github.com/ryanwood))
79
- * Yahoo (credit: [mpd](https://github.com/mpd))
80
- * Yammer (credit: [kltcalamay](https://github.com/kltcalamay))
81
- * YouTube (credit: [jamiew](https://github.com/jamiew))
82
- * CAS (Central Authentication Service) (credit: [jamesarosen](https://github.com/jamesarosen))
83
- * Flickr (credit: [pchilton](https://github.com/pchilton))
84
- * Google Apps (via OpenID) (credit: [mbleigh](https://github.com/mbleigh))
85
- * Google OpenID+OAuth (via Hybrid Protocol) (credit: [boyvanamstel](https://github.com/boyvanamstel))
86
- * LDAP (credit: [pyu10055](https://github.com/pyu10055))
87
- * OpenID (credit: [mbleigh](https://github.com/mbleigh))
88
- * Yupoo (credit: [chouti](https://github.com/chouti))
89
-
90
- ## <a name="usage">Usage</a>
91
- OmniAuth is a collection of Rack middleware. To use a single strategy, you simply need to add the middleware:
92
-
93
- require 'oa-oauth'
94
- use OmniAuth::Strategies::Twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
95
-
96
- 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:
97
-
98
- get '/auth/twitter/callback' do
99
- auth_hash = request.env['omniauth.auth']
2
+
3
+ **NOTICE:** This documentation and code is for OmniAuth 1.0 in which
4
+ each provider will become its own separate gem. If you're looking for
5
+ the current released version, please visit [OmniAuth 0.3 Stable
6
+ Branch](https://github.com/intridea/omniauth/tree/0-3-stable).
7
+
8
+ ## An Introduction
9
+
10
+ OmniAuth is a libary that standardizes multi-provider authentication for
11
+ web applications. It was created to be powerful, flexible, and do as
12
+ little as possible. Any developer can create **strategies** for OmniAuth
13
+ that can authenticate users via disparate systems. OmniAuth strategies
14
+ have been created for everything from Facebook to LDAP.
15
+
16
+ In order to use OmniAuth in your applications, you will need to leverage
17
+ one or more strategies. These strategies are generally released
18
+ individually as RubyGems, and you can see a [community maintained list](https://github.com/intridea/omniauth/wiki/List-of-Strategies)
19
+ on the wiki for this project.
20
+
21
+ ## Adding OmniAuth to Your Application
22
+
23
+ Each OmniAuth strategy is a Rack Middleware. That means that you can use
24
+ it the same way that you use any other Rack middleware. For example, to
25
+ use the built-in Developer strategy in a Sinatra application I might do
26
+ this:
27
+
28
+ require 'sinatra'
29
+ require 'omniauth'
30
+
31
+ class MyApplication < Sinatra::Base
32
+ use Rack::Session
33
+ use OmniAuth::Strategies::Developer
34
+ end
35
+
36
+ Because OmniAuth is built for *multi-provider* authentication, I may
37
+ want to leave room to run multiple strategies. For this, the built-in
38
+ `OmniAuth::Builder` class gives you an easy way to specify multiple
39
+ strategies. Note that there is **no difference** between the following
40
+ code and using each strategy individually as middleware. This is an
41
+ example that you might put into a Rails initializer at
42
+ `config/initializers/omniauth.rb`:
43
+
44
+ Rails.application.config.middleware.use OmniAuth::Builder do
45
+ provider :developer unless Rails.env.production?
46
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
47
+ end
48
+
49
+ You should look to the documentation for each provider you use for
50
+ specific initialization requirements.
51
+
52
+ ## Integrating OmniAuth Into Your Application
53
+
54
+ OmniAuth is an extremely low-touch library. It is designed to be a
55
+ black box that you can send your application's users into when you need
56
+ authentication and then get information back. OmniAuth was intentionally
57
+ built not to automatically associate with a User model or make
58
+ assumptions about how many authentication methods you might want to use
59
+ or what you might want to do with the data once a user has
60
+ authenticated. This makes OmniAuth incredibly flexible. To use OmniAuth,
61
+ you need only to redirect users to `/auth/:provider`, where `:provider`
62
+ is the name of the strategy (for example, `developer` or `twitter`).
63
+ From there, OmniAuth will take over and take the user through the
64
+ necessary steps to authenticate them with the chosen strategy.
65
+
66
+ Once the user has authenticated, what do you do next? OmniAuth simply
67
+ sets a special hash called the Authentication Hash on the Rack
68
+ environment of a request to `/auth/:provider/callback`. This hash
69
+ contains as much information about the user as OmniAuth was able to
70
+ glean from the utilized strategy. You should set up an endpoint in your
71
+ application that matches to the callback URL and then performs whatever
72
+ steps are necessary for your application. For example, in a Rails app I
73
+ would add a line in my `routes.rb` file like this:
74
+
75
+ match '/auth/:provider/callback', to: 'sessions#create'
76
+
77
+ And I might then have a `SessionsController` with code that looks
78
+ something like this:
79
+
80
+ class SessionsController < ApplicationController
81
+ def create
82
+ @user = ̈User.find_or_create_from_auth_hash(auth_hash)
83
+ self.current_user = @user
84
+ redirect_to '/'
85
+ end
86
+
87
+ protected
88
+
89
+ def auth_hash
90
+ request.env['omniauth.auth']
91
+ end
100
92
  end
101
93
 
102
- The hash in question will look something like this:
103
-
104
- {
105
- 'uid' => '12356',
106
- 'provider' => 'twitter',
107
- 'user_info' => {
108
- 'name' => 'User Name',
109
- 'nickname' => 'username',
110
- # ...
111
- }
112
- }
113
-
114
- 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.
115
-
116
- ## <a name="resources">Resources</a>
117
- The best place to find more information is the [OmniAuth Wiki](https://github.com/intridea/omniauth/wiki). Some specific information you might be interested in:
118
-
119
- * [CI Build Status](http://travis-ci.org/intridea/omniauth)
120
- * [Roadmap](https://github.com/intridea/omniauth/wiki/Roadmap)
121
- * [Changelog](https://github.com/intridea/omniauth/wiki/Changelog)
122
- * [Report Issues](https://github.com/intridea/omniauth/issues)
123
- * [Mailing List](http://groups.google.com/group/omniauth)
124
-
125
- ## <a name="core">Core Team</a>
126
- * **Michael Bleigh** ([mbleigh](https://github.com/mbleigh))
127
- * **Erik Michaels-Ober** ([sferik](https://github.com/sferik))
128
-
129
- ## <a name="rubies">Supported Rubies</a>
130
- This library aims to support and is [tested
131
- against](http://travis-ci.org/intridea/omniauth) the following Ruby
132
- implementations:
133
-
134
- * Ruby 1.8.7
135
- * Ruby 1.9.2
136
- * [JRuby](http://www.jruby.org/)
137
- * [Rubinius](http://rubini.us/)
138
- * [Ruby Enterprise Edition](http://www.rubyenterpriseedition.com/)
139
-
140
- If something doesn't work on one of these interpreters, it should be considered
141
- a bug.
142
-
143
- This library may inadvertently work (or seem to work) on other Ruby
144
- implementations, however support will only be provided for the versions listed
145
- above.
146
-
147
- If you would like this library to support another Ruby version, you may
148
- volunteer to be a maintainer. Being a maintainer entails making sure all tests
149
- run and pass on that implementation. When something breaks on your
150
- implementation, you will be personally responsible for providing patches in a
151
- timely fashion. If critical issues for a particular implementation exist at the
152
- time of a major release, support for that Ruby version may be dropped.
153
-
154
- ## <a name="license">License</a>
155
- OmniAuth is released under the MIT License.
94
+ The `omniauth.auth` key in the environment hash gives me my
95
+ Authentication Hash which will contain information about the just
96
+ authenticated user including a unique id, the strategy they just used
97
+ for authentication, and personal details such as name and email address
98
+ as available. For an in-depth description of what the authentication
99
+ hash might contain, see the [Auth Hash Schema wiki page](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema).
100
+
101
+ Note that OmniAuth does not perform any actions beyond setting some
102
+ environment information on the callback request. It is entirely up to
103
+ you how you want to implement the particulars of your application's
104
+ authentication flow.
105
+
106
+ ## Resources
107
+
108
+ The [OmniAuth Wiki](https://github.com/intridea/omniauth/wiki) has
109
+ actively maintained in-depth documentation for OmniAuth. It should be
110
+ your first stop if you are wondering about a more in-depth look at
111
+ OmniAuth, how it works, and how to use it.
112
+
113
+ ## License
114
+
115
+ Copyright (c) 2011 Intridea, Inc.
116
+
117
+ Permission is hereby granted, free of charge, to any person obtaining a
118
+ copy of this software and associated documentation files (the "Software"),
119
+ to deal in the Software without restriction, including without limitation
120
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
121
+ and/or sell copies of the Software, and to permit persons to whom the
122
+ Software is furnished to do so, subject to the following conditions:
123
+
124
+ The above copyright notice and this permission notice shall be included
125
+ in all copies or substantial portions of the Software.
126
+
127
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
128
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
129
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
130
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
131
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
132
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
133
+ DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
6
+ task :test => :spec
@@ -0,0 +1,47 @@
1
+ require 'hashie/mash'
2
+
3
+ module OmniAuth
4
+ # The AuthHash is a normalized schema returned by all OmniAuth
5
+ # strategies. It maps as much user information as the provider
6
+ # is able to provide into the InfoHash (stored as the `'info'`
7
+ # key).
8
+ class AuthHash < Hashie::Mash
9
+ # Tells you if this is considered to be a valid
10
+ # OmniAuth AuthHash. The requirements for that
11
+ # are that it has a provider name, a uid, and a
12
+ # valid info hash. See InfoHash#valid? for
13
+ # more details there.
14
+ def valid?
15
+ uid? && provider? && info? && info.valid?
16
+ end
17
+
18
+ def regular_writer(key, value)
19
+ if key.to_s == 'info' && !value.is_a?(InfoHash)
20
+ value = InfoHash.new(value)
21
+ end
22
+ super
23
+ end
24
+
25
+ class InfoHash < Hashie::Mash
26
+ def name
27
+ return self[:name] if self[:name]
28
+ return "#{first_name} #{last_name}".strip if first_name? || last_name?
29
+ return nickname if nickname?
30
+ return email if email?
31
+ nil
32
+ end
33
+
34
+ def name?; !!name end
35
+
36
+ def valid?
37
+ name?
38
+ end
39
+
40
+ def to_hash
41
+ hash = super
42
+ hash['name'] ||= name
43
+ hash
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ require 'omniauth'
2
+
3
+ module OmniAuth
4
+ class Builder < ::Rack::Builder
5
+ def initialize(app, &block)
6
+ @app = app
7
+ super(&block)
8
+ end
9
+
10
+ def on_failure(&block)
11
+ OmniAuth.config.on_failure = block
12
+ end
13
+
14
+ def configure(&block)
15
+ OmniAuth.configure(&block)
16
+ end
17
+
18
+ def provider(klass, *args, &block)
19
+ if klass.is_a?(Class)
20
+ middleware = klass
21
+ else
22
+ middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
23
+ end
24
+
25
+ use middleware, *args, &block
26
+ end
27
+
28
+ def call(env)
29
+ @ins << @app unless @ins.include?(@app)
30
+ to_app.call(env)
31
+ end
32
+ end
33
+ end