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 +0 -0
- data/.gitignore +56 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +4 -0
- data/Gemfile +11 -0
- data/Guardfile +10 -0
- data/{LICENSE.md → LICENSE} +1 -1
- data/README.md +130 -152
- data/Rakefile +6 -0
- data/lib/omniauth/auth_hash.rb +47 -0
- data/lib/omniauth/builder.rb +33 -0
- data/lib/omniauth/form.rb +191 -0
- data/lib/omniauth/strategy.rb +429 -0
- data/lib/omniauth/test/phony_session.rb +8 -0
- data/lib/omniauth/test/strategy_macros.rb +34 -0
- data/lib/omniauth/test/strategy_test_case.rb +49 -0
- data/lib/omniauth/test.rb +12 -0
- data/lib/omniauth/version.rb +1 -17
- data/lib/omniauth.rb +135 -6
- data/omniauth.gemspec +28 -0
- data/spec/omniauth/auth_hash_spec.rb +103 -0
- data/spec/omniauth/builder_spec.rb +20 -0
- data/spec/omniauth/strategy_spec.rb +601 -0
- data/spec/omniauth_spec.rb +82 -0
- data/spec/spec_helper.rb +12 -0
- metadata +138 -143
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
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/{LICENSE.md → LICENSE}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2010-2011 Michael Bleigh
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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,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
|