omniauth 0.3.0.rc3 → 1.0.0.beta1

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,139 @@
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
+ One strategy, called `Developer`, is included with OmniAuth and provides
22
+ a completely unsecure, non-production-usable strategy that directly
23
+ prompts a user for authentication information and then passes it
24
+ straight through. You can use it as a placeholder when you start
25
+ development and easily swap in other strategies later.
26
+
27
+ ## Getting Started
28
+
29
+ Each OmniAuth strategy is a Rack Middleware. That means that you can use
30
+ it the same way that you use any other Rack middleware. For example, to
31
+ use the built-in Developer strategy in a Sinatra application I might do
32
+ this:
33
+
34
+ require 'sinatra'
35
+ require 'omniauth'
36
+
37
+ class MyApplication < Sinatra::Base
38
+ use Rack::Session
39
+ use OmniAuth::Strategies::Developer
40
+ end
41
+
42
+ Because OmniAuth is built for *multi-provider* authentication, I may
43
+ want to leave room to run multiple strategies. For this, the built-in
44
+ `OmniAuth::Builder` class gives you an easy way to specify multiple
45
+ strategies. Note that there is **no difference** between the following
46
+ code and using each strategy individually as middleware. This is an
47
+ example that you might put into a Rails initializer at
48
+ `config/initializers/omniauth.rb`:
49
+
50
+ Rails.application.config.middleware.use OmniAuth::Builder do
51
+ provider :developer unless Rails.env.production?
52
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
53
+ end
54
+
55
+ You should look to the documentation for each provider you use for
56
+ specific initialization requirements.
57
+
58
+ ## Integrating OmniAuth Into Your Application
59
+
60
+ OmniAuth is an extremely low-touch library. It is designed to be a
61
+ black box that you can send your application's users into when you need
62
+ authentication and then get information back. OmniAuth was intentionally
63
+ built not to automatically associate with a User model or make
64
+ assumptions about how many authentication methods you might want to use
65
+ or what you might want to do with the data once a user has
66
+ authenticated. This makes OmniAuth incredibly flexible. To use OmniAuth,
67
+ you need only to redirect users to `/auth/:provider`, where `:provider`
68
+ is the name of the strategy (for example, `developer` or `twitter`).
69
+ From there, OmniAuth will take over and take the user through the
70
+ necessary steps to authenticate them with the chosen strategy.
71
+
72
+ Once the user has authenticated, what do you do next? OmniAuth simply
73
+ sets a special hash called the Authentication Hash on the Rack
74
+ environment of a request to `/auth/:provider/callback`. This hash
75
+ contains as much information about the user as OmniAuth was able to
76
+ glean from the utilized strategy. You should set up an endpoint in your
77
+ application that matches to the callback URL and then performs whatever
78
+ steps are necessary for your application. For example, in a Rails app I
79
+ would add a line in my `routes.rb` file like this:
80
+
81
+ match '/auth/:provider/callback', to: 'sessions#create'
82
+
83
+ And I might then have a `SessionsController` with code that looks
84
+ something like this:
85
+
86
+ class SessionsController < ApplicationController
87
+ def create
88
+ @user = User.find_or_create_from_auth_hash(auth_hash)
89
+ self.current_user = @user
90
+ redirect_to '/'
91
+ end
92
+
93
+ protected
94
+
95
+ def auth_hash
96
+ request.env['omniauth.auth']
97
+ end
100
98
  end
101
99
 
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.
100
+ The `omniauth.auth` key in the environment hash gives me my
101
+ Authentication Hash which will contain information about the just
102
+ authenticated user including a unique id, the strategy they just used
103
+ for authentication, and personal details such as name and email address
104
+ as available. For an in-depth description of what the authentication
105
+ hash might contain, see the [Auth Hash Schema wiki page](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema).
106
+
107
+ Note that OmniAuth does not perform any actions beyond setting some
108
+ environment information on the callback request. It is entirely up to
109
+ you how you want to implement the particulars of your application's
110
+ authentication flow.
111
+
112
+ ## Resources
113
+
114
+ The [OmniAuth Wiki](https://github.com/intridea/omniauth/wiki) has
115
+ actively maintained in-depth documentation for OmniAuth. It should be
116
+ your first stop if you are wondering about a more in-depth look at
117
+ OmniAuth, how it works, and how to use it.
118
+
119
+ ## License
120
+
121
+ Copyright (c) 2011 Intridea, Inc.
122
+
123
+ Permission is hereby granted, free of charge, to any person obtaining a
124
+ copy of this software and associated documentation files (the "Software"),
125
+ to deal in the Software without restriction, including without limitation
126
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
127
+ and/or sell copies of the Software, and to permit persons to whom the
128
+ Software is furnished to do so, subject to the following conditions:
129
+
130
+ The above copyright notice and this permission notice shall be included
131
+ in all copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
134
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
135
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
136
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
137
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
138
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
139
+ 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,51 @@
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
+ def self.subkey_class; Hashie::Mash end
10
+
11
+ # Tells you if this is considered to be a valid
12
+ # OmniAuth AuthHash. The requirements for that
13
+ # are that it has a provider name, a uid, and a
14
+ # valid info hash. See InfoHash#valid? for
15
+ # more details there.
16
+ def valid?
17
+ uid? && provider? && info? && info.valid?
18
+ end
19
+
20
+ def regular_writer(key, value)
21
+ if key.to_s == 'info' && !value.is_a?(InfoHash)
22
+ value = InfoHash.new(value)
23
+ end
24
+ super
25
+ end
26
+
27
+ class InfoHash < Hashie::Mash
28
+ def self.subkey_class; Hashie::Mash end
29
+
30
+ def name
31
+ return self[:name] if self[:name]
32
+ return "#{first_name} #{last_name}".strip if first_name? || last_name?
33
+ return nickname if nickname?
34
+ return email if email?
35
+ nil
36
+ end
37
+
38
+ def name?; !!name end
39
+
40
+ def valid?
41
+ name?
42
+ end
43
+
44
+ def to_hash
45
+ hash = super
46
+ hash['name'] ||= name
47
+ hash
48
+ end
49
+ end
50
+ end
51
+ 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