omniauth 1.9.2 → 2.1.0
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.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +2 -0
- data/.github/workflows/main.yml +89 -0
- data/.gitignore +2 -0
- data/Gemfile +11 -10
- data/README.md +96 -50
- data/SECURITY.md +17 -0
- data/lib/omniauth/authenticity_token_protection.rb +32 -0
- data/lib/omniauth/builder.rb +3 -4
- data/lib/omniauth/failure_endpoint.rb +10 -1
- data/lib/omniauth/form.rb +1 -1
- data/lib/omniauth/strategy.rb +79 -27
- data/lib/omniauth/version.rb +1 -1
- data/lib/omniauth.rb +18 -6
- data/omniauth.gemspec +3 -2
- metadata +24 -13
- data/.travis.yml +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df50309ac3b4098a460e7a52f233798a3246cffdfeb2c6f6f60d373b8af8af2c
|
|
4
|
+
data.tar.gz: bf5c53ceadb04c431b88aa17dfe6a11b46475b38bc9d4fa74865e1eb21d27772
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dfd0bb2add456a51a393e672cba45d310f6ab7d2b5aa37c058a7242b8b0dc9b644877596c0a47c9e1c462d1e593516d1474379f103cae0988cced76c37260d4a
|
|
7
|
+
data.tar.gz: 6a0c4302b25339ca10e304ef1fb968e5dd36cb5e6d686499c1b9d5185f9165fef864f54603f385076bf81160980ca532285a00ebdf23de82f3a1bacf95655856
|
data/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Ruby
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ master ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ master ]
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
runs-on: ubuntu-18.04
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: false
|
|
21
|
+
matrix:
|
|
22
|
+
os: [ubuntu, macos]
|
|
23
|
+
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, head, debug, truffleruby, truffleruby-head]
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v2
|
|
26
|
+
- name: Set up Ruby
|
|
27
|
+
uses: ruby/setup-ruby@v1
|
|
28
|
+
with:
|
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
|
30
|
+
bundler-cache: true
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: bundle install
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: bundle exec rake
|
|
35
|
+
test-jruby:
|
|
36
|
+
runs-on: ubuntu-18.04
|
|
37
|
+
strategy:
|
|
38
|
+
fail-fast: false
|
|
39
|
+
matrix:
|
|
40
|
+
os: [ubuntu, macos]
|
|
41
|
+
jruby: [jruby] # TODO: Add back jruby-head once we figure out why there's a bundler mismatch
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v2
|
|
44
|
+
- name: Set up Ruby
|
|
45
|
+
uses: ruby/setup-ruby@v1
|
|
46
|
+
with:
|
|
47
|
+
ruby-version: ${{ matrix.jruby }}
|
|
48
|
+
bundler-cache: true
|
|
49
|
+
- name: Install dependencies
|
|
50
|
+
env:
|
|
51
|
+
JRUBY_OPTS: --debug
|
|
52
|
+
run: bundle install
|
|
53
|
+
- name: Run tests
|
|
54
|
+
env:
|
|
55
|
+
JRUBY_OPTS: --debug
|
|
56
|
+
run: bundle exec rake
|
|
57
|
+
frozen-string-compat:
|
|
58
|
+
runs-on: ubuntu-18.04
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v2
|
|
61
|
+
- name: Set up Ruby
|
|
62
|
+
uses: ruby/setup-ruby@v1
|
|
63
|
+
with:
|
|
64
|
+
ruby-version: 2.6
|
|
65
|
+
bundler-cache: true
|
|
66
|
+
- name: Install dependencies
|
|
67
|
+
run: bundle install
|
|
68
|
+
- name: Run tests
|
|
69
|
+
env:
|
|
70
|
+
RUBYOPT: "--enable-frozen-string-literal"
|
|
71
|
+
run: bundle exec rake
|
|
72
|
+
coveralls:
|
|
73
|
+
runs-on: ubuntu-18.04
|
|
74
|
+
steps:
|
|
75
|
+
- uses: actions/checkout@v2
|
|
76
|
+
- name: Set up Ruby
|
|
77
|
+
uses: ruby/setup-ruby@v1
|
|
78
|
+
with:
|
|
79
|
+
ruby-version: 2.6
|
|
80
|
+
bundler-cache: true
|
|
81
|
+
- name: Install dependencies
|
|
82
|
+
run: bundle install
|
|
83
|
+
- name: Run tests
|
|
84
|
+
run: bundle exec rake
|
|
85
|
+
- name: Coveralls GitHub Action
|
|
86
|
+
uses: coverallsapp/github-action@v1.1.2
|
|
87
|
+
with:
|
|
88
|
+
github-token: ${{ secrets.github_token }}
|
|
89
|
+
path-to-lcov: './coverage/lcov/omniauth.lcov'
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
gem 'jruby-openssl', '~> 0.
|
|
3
|
+
gem 'jruby-openssl', '~> 0.10.5', platforms: :jruby
|
|
4
4
|
gem 'rake', '>= 12.0'
|
|
5
5
|
gem 'yard', '>= 0.9.11'
|
|
6
6
|
|
|
@@ -12,16 +12,17 @@ group :development do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
group :test do
|
|
15
|
-
gem '
|
|
16
|
-
gem 'hashie', '>= 3.4.6', '~> 4.0.0', :
|
|
17
|
-
gem 'json', '~> 2.0
|
|
18
|
-
gem 'mime-types', '~> 3.1', :
|
|
19
|
-
gem 'rack', '>= 2.0.6', :platforms => %i[jruby_18 jruby_19 ruby_19 ruby_20 ruby_21]
|
|
15
|
+
gem 'coveralls_reborn', '~> 0.19.0', require: false
|
|
16
|
+
gem 'hashie', '>= 3.4.6', '~> 4.0.0', platforms: [:jruby_18]
|
|
17
|
+
gem 'json', '~> 2.3.0', platforms: %i[jruby_18 jruby_19 ruby_19]
|
|
18
|
+
gem 'mime-types', '~> 3.1', platforms: [:jruby_18]
|
|
20
19
|
gem 'rack-test'
|
|
21
|
-
gem 'rest-client', '~> 2.0.0', :
|
|
22
|
-
gem 'rspec', '~> 3.5
|
|
23
|
-
gem '
|
|
24
|
-
gem '
|
|
20
|
+
gem 'rest-client', '~> 2.0.0', platforms: [:jruby_18]
|
|
21
|
+
gem 'rspec', '~> 3.5'
|
|
22
|
+
gem 'rack-freeze'
|
|
23
|
+
gem 'rubocop', '>= 0.58.2', '< 0.69.0', platforms: %i[ruby_20 ruby_21 ruby_22 ruby_23 ruby_24]
|
|
24
|
+
gem 'simplecov-lcov'
|
|
25
|
+
gem 'tins', '~> 1.13', platforms: %i[jruby_18 jruby_19 ruby_19]
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
gemspec
|
data/README.md
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
[][gem]
|
|
4
4
|
[][travis]
|
|
5
|
-
[][codeclimate]
|
|
6
6
|
[][coveralls]
|
|
7
|
-
[](https://hakiri.io/github/omniauth/omniauth/master)
|
|
8
7
|
|
|
9
8
|
[gem]: https://rubygems.org/gems/omniauth
|
|
10
9
|
[travis]: http://travis-ci.org/omniauth/omniauth
|
|
11
10
|
[codeclimate]: https://codeclimate.com/github/omniauth/omniauth
|
|
12
11
|
[coveralls]: https://coveralls.io/r/omniauth/omniauth
|
|
13
12
|
|
|
13
|
+
This is the documentation for our latest release [v2.1.0](https://github.com/omniauth/omniauth/releases/tag/v2.1.0).
|
|
14
|
+
|
|
14
15
|
## An Introduction
|
|
15
16
|
OmniAuth is a library that standardizes multi-provider authentication for
|
|
16
17
|
web applications. It was created to be powerful, flexible, and do as
|
|
@@ -32,8 +33,8 @@ development and easily swap in other strategies later.
|
|
|
32
33
|
## Getting Started
|
|
33
34
|
Each OmniAuth strategy is a Rack Middleware. That means that you can use
|
|
34
35
|
it the same way that you use any other Rack middleware. For example, to
|
|
35
|
-
use the built-in Developer strategy in a Sinatra application
|
|
36
|
-
this:
|
|
36
|
+
use the built-in Developer strategy in a Sinatra application you might
|
|
37
|
+
do this:
|
|
37
38
|
|
|
38
39
|
```ruby
|
|
39
40
|
require 'sinatra'
|
|
@@ -45,7 +46,7 @@ class MyApplication < Sinatra::Base
|
|
|
45
46
|
end
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
Because OmniAuth is built for *multi-provider* authentication,
|
|
49
|
+
Because OmniAuth is built for *multi-provider* authentication, you may
|
|
49
50
|
want to leave room to run multiple strategies. For this, the built-in
|
|
50
51
|
`OmniAuth::Builder` class gives you an easy way to specify multiple
|
|
51
52
|
strategies. Note that there is **no difference** between the following
|
|
@@ -82,33 +83,9 @@ environment of a request to `/auth/:provider/callback`. This hash
|
|
|
82
83
|
contains as much information about the user as OmniAuth was able to
|
|
83
84
|
glean from the utilized strategy. You should set up an endpoint in your
|
|
84
85
|
application that matches to the callback URL and then performs whatever
|
|
85
|
-
steps are necessary for your application.
|
|
86
|
-
would add a line in my `routes.rb` file like this:
|
|
87
|
-
|
|
88
|
-
```ruby
|
|
89
|
-
get '/auth/:provider/callback', to: 'sessions#create'
|
|
90
|
-
```
|
|
86
|
+
steps are necessary for your application.
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
something like this:
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
class SessionsController < ApplicationController
|
|
97
|
-
def create
|
|
98
|
-
@user = User.find_or_create_from_auth_hash(auth_hash)
|
|
99
|
-
self.current_user = @user
|
|
100
|
-
redirect_to '/'
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
protected
|
|
104
|
-
|
|
105
|
-
def auth_hash
|
|
106
|
-
request.env['omniauth.auth']
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
The `omniauth.auth` key in the environment hash gives me my
|
|
88
|
+
The `omniauth.auth` key in the environment hash provides an
|
|
112
89
|
Authentication Hash which will contain information about the just
|
|
113
90
|
authenticated user including a unique id, the strategy they just used
|
|
114
91
|
for authentication, and personal details such as name and email address
|
|
@@ -120,35 +97,67 @@ environment information on the callback request. It is entirely up to
|
|
|
120
97
|
you how you want to implement the particulars of your application's
|
|
121
98
|
authentication flow.
|
|
122
99
|
|
|
123
|
-
**Please note:** there is currently a CSRF vulnerability which affects OmniAuth (designated [CVE-2015-9284](https://nvd.nist.gov/vuln/detail/CVE-2015-9284)) that requires mitigation at the application level. More details on how to do this can be found on the [Wiki](https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284).
|
|
124
100
|
|
|
125
|
-
##
|
|
126
|
-
|
|
101
|
+
## Rails (without Devise)
|
|
102
|
+
To get started, add the following gems
|
|
103
|
+
|
|
104
|
+
**Gemfile**:
|
|
105
|
+
```ruby
|
|
106
|
+
gem 'omniauth'
|
|
107
|
+
gem "omniauth-rails_csrf_protection"
|
|
108
|
+
```
|
|
127
109
|
|
|
128
|
-
|
|
110
|
+
Then insert OmniAuth as a middleware
|
|
129
111
|
|
|
130
|
-
|
|
112
|
+
**config/initializers/omniauth.rb**:
|
|
131
113
|
```ruby
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
114
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
115
|
+
provider :developer if Rails.env.development?
|
|
116
|
+
end
|
|
135
117
|
```
|
|
136
118
|
|
|
137
|
-
|
|
119
|
+
Additional providers can be added here in the future. Next we wire it
|
|
120
|
+
all up using routes, a controller and a login view.
|
|
121
|
+
|
|
122
|
+
**config/routes.rb**:
|
|
123
|
+
|
|
138
124
|
```ruby
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: 'return_to'
|
|
125
|
+
get 'auth/:provider/callback', to: 'sessions#create'
|
|
126
|
+
get '/login', to: 'sessions#new'
|
|
142
127
|
```
|
|
143
128
|
|
|
144
|
-
|
|
129
|
+
**app/controllers/sessions_controller.rb**:
|
|
145
130
|
```ruby
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
131
|
+
class SessionsController < ApplicationController
|
|
132
|
+
def new
|
|
133
|
+
render :new
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def create
|
|
137
|
+
user_info = request.env['omniauth.auth']
|
|
138
|
+
raise user_info # Your own session management should be placed here.
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**app/views/sessions/new.html.erb**:
|
|
144
|
+
```erb
|
|
145
|
+
<%= form_tag('/auth/developer', method: 'post', data: {turbo: false}) do %>
|
|
146
|
+
<button type='submit'>Login with Developer</button>
|
|
147
|
+
<% end %>
|
|
149
148
|
```
|
|
150
149
|
|
|
151
|
-
|
|
150
|
+
Now if you visit `/login` and click the Login button, you should see the
|
|
151
|
+
OmniAuth developer login screen. After submitting it, you are returned to your
|
|
152
|
+
application at `Sessions#create`. The raise should now display all the Omniauth
|
|
153
|
+
details you have available to integrate it into your own user management.
|
|
154
|
+
|
|
155
|
+
If you want out of the box usermanagement, you should consider using Omniauth
|
|
156
|
+
through Devise. Please visit the [Devise Github page](https://github.com/heartcombo/devise#omniauth)
|
|
157
|
+
for more information.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
## Rails API
|
|
152
161
|
The following middleware are (by default) included for session management in
|
|
153
162
|
Rails applications. When using OmniAuth with a Rails API, you'll need to add
|
|
154
163
|
one of these required middleware back in:
|
|
@@ -163,7 +172,7 @@ a `session_store.rb` initializer, add `use ActionDispatch::Session::CookieStore`
|
|
|
163
172
|
and have sessions functioning as normal.
|
|
164
173
|
|
|
165
174
|
To be clear: sessions may work, but your session options will be ignored
|
|
166
|
-
(i.e the session key will default to `_session_id`). Instead of the
|
|
175
|
+
(i.e. the session key will default to `_session_id`). Instead of the
|
|
167
176
|
initializer, you'll have to set the relevant options somewhere
|
|
168
177
|
before your middleware is built (like `application.rb`) and pass them to your
|
|
169
178
|
preferred middleware, like this:
|
|
@@ -187,14 +196,51 @@ to `STDOUT` but you can configure this using `OmniAuth.config.logger`:
|
|
|
187
196
|
OmniAuth.config.logger = Rails.logger
|
|
188
197
|
```
|
|
189
198
|
|
|
199
|
+
## Origin Param
|
|
200
|
+
The `origin` url parameter is typically used to inform where a user came from
|
|
201
|
+
and where, should you choose to use it, they'd want to return to.
|
|
202
|
+
Omniauth supports the following settings which can be configured on a provider level:
|
|
203
|
+
|
|
204
|
+
**Default**:
|
|
205
|
+
```ruby
|
|
206
|
+
provider :twitter, ENV['KEY'], ENV['SECRET']
|
|
207
|
+
POST /auth/twitter/?origin=[URL]
|
|
208
|
+
# If the `origin` parameter is blank, `omniauth.origin` is set to HTTP_REFERER
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Using a differently named origin parameter**:
|
|
212
|
+
```ruby
|
|
213
|
+
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: 'return_to'
|
|
214
|
+
POST /auth/twitter/?return_to=[URL]
|
|
215
|
+
# If the `return_to` parameter is blank, `omniauth.origin` is set to HTTP_REFERER
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Disabled**:
|
|
219
|
+
```ruby
|
|
220
|
+
provider :twitter, ENV['KEY'], ENV['SECRET'], origin_param: false
|
|
221
|
+
POST /auth/twitter
|
|
222
|
+
# This means the origin should be handled by your own application.
|
|
223
|
+
# Note that `omniauth.origin` will always be blank.
|
|
224
|
+
```
|
|
225
|
+
|
|
190
226
|
## Resources
|
|
191
227
|
The [OmniAuth Wiki](https://github.com/omniauth/omniauth/wiki) has
|
|
192
228
|
actively maintained in-depth documentation for OmniAuth. It should be
|
|
193
229
|
your first stop if you are wondering about a more in-depth look at
|
|
194
230
|
OmniAuth, how it works, and how to use it.
|
|
195
231
|
|
|
232
|
+
## OmniAuth for Enterprise
|
|
233
|
+
|
|
234
|
+
Available as part of the Tidelift Subscription.
|
|
235
|
+
|
|
236
|
+
The maintainers of OmniAuth and thousands of other packages are working with
|
|
237
|
+
Tidelift to deliver commercial support and maintenance for the open source
|
|
238
|
+
packages you use to build your applications. Save time, reduce risk, and
|
|
239
|
+
improve code health, while paying the maintainers of the exact packages you use.
|
|
240
|
+
[Learn more.](https://tidelift.com/subscription/pkg/rubygems-omniauth?utm_source=undefined&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
241
|
+
|
|
196
242
|
## Supported Ruby Versions
|
|
197
|
-
OmniAuth is tested under 2.
|
|
243
|
+
OmniAuth is tested under 2.5, 2.6, 2.7, truffleruby, and JRuby.
|
|
198
244
|
|
|
199
245
|
## Versioning
|
|
200
246
|
This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
Use this section to tell people about which versions of your project are
|
|
6
|
+
currently being supported with security updates.
|
|
7
|
+
|
|
8
|
+
| Version | Supported |
|
|
9
|
+
| ------- | ------------------ |
|
|
10
|
+
| 2.0.x | :white_check_mark: |
|
|
11
|
+
| <= 1.9.1 | :x: |
|
|
12
|
+
|
|
13
|
+
## Security contact information
|
|
14
|
+
|
|
15
|
+
To report a security vulnerability, please use the
|
|
16
|
+
[Tidelift security contact](https://tidelift.com/security).
|
|
17
|
+
Tidelift will coordinate the fix and disclosure.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'rack-protection'
|
|
2
|
+
|
|
3
|
+
module OmniAuth
|
|
4
|
+
class AuthenticityError < StandardError; end
|
|
5
|
+
class AuthenticityTokenProtection < Rack::Protection::AuthenticityToken
|
|
6
|
+
def initialize(options = {})
|
|
7
|
+
@options = default_options.merge(options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.call(env)
|
|
11
|
+
new.call!(env)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call!(env)
|
|
15
|
+
return if accepts?(env)
|
|
16
|
+
|
|
17
|
+
instrument env
|
|
18
|
+
react env
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias_method :call, :call!
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def deny(_env)
|
|
26
|
+
OmniAuth.logger.send(:warn, "Attack prevented by #{self.class}")
|
|
27
|
+
raise AuthenticityError.new(options[:message])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
alias default_reaction deny
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/omniauth/builder.rb
CHANGED
|
@@ -26,19 +26,18 @@ module OmniAuth
|
|
|
26
26
|
@options = options
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def provider(klass, *args, &block)
|
|
29
|
+
def provider(klass, *args, **opts, &block)
|
|
30
30
|
if klass.is_a?(Class)
|
|
31
31
|
middleware = klass
|
|
32
32
|
else
|
|
33
33
|
begin
|
|
34
|
-
middleware = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s)
|
|
34
|
+
middleware = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s, false)
|
|
35
35
|
rescue NameError
|
|
36
36
|
raise(LoadError.new("Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass})."))
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
use middleware, *args, &block
|
|
40
|
+
use middleware, *args, **options.merge(opts), &block
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
def call(env)
|
|
@@ -27,10 +27,19 @@ module OmniAuth
|
|
|
27
27
|
|
|
28
28
|
def redirect_to_failure
|
|
29
29
|
message_key = env['omniauth.error.type']
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
new_path = "#{env['SCRIPT_NAME']}#{strategy_path_prefix}/failure?message=#{Rack::Utils.escape(message_key)}#{origin_query_param}#{strategy_name_query_param}"
|
|
31
32
|
Rack::Response.new(['302 Moved'], 302, 'Location' => new_path).finish
|
|
32
33
|
end
|
|
33
34
|
|
|
35
|
+
def strategy_path_prefix
|
|
36
|
+
if env['omniauth.error.strategy']
|
|
37
|
+
env['omniauth.error.strategy'].path_prefix
|
|
38
|
+
else
|
|
39
|
+
OmniAuth.config.path_prefix
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
34
43
|
def strategy_name_query_param
|
|
35
44
|
return '' unless env['omniauth.error.strategy']
|
|
36
45
|
|
data/lib/omniauth/form.rb
CHANGED
|
@@ -9,7 +9,7 @@ module OmniAuth
|
|
|
9
9
|
options[:header_info] ||= ''
|
|
10
10
|
self.options = options
|
|
11
11
|
|
|
12
|
-
@html = ''
|
|
12
|
+
@html = +'' # unary + string allows it to be mutable if strings are frozen
|
|
13
13
|
@with_custom_button = false
|
|
14
14
|
@footer = nil
|
|
15
15
|
header(options[:title], options[:header_info])
|
data/lib/omniauth/strategy.rb
CHANGED
|
@@ -181,17 +181,47 @@ module OmniAuth
|
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
@env = env
|
|
184
|
+
|
|
185
|
+
warn_if_using_get_on_request_path
|
|
186
|
+
|
|
184
187
|
@env['omniauth.strategy'] = self if on_auth_path?
|
|
185
188
|
|
|
186
189
|
return mock_call!(env) if OmniAuth.config.test_mode
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
|
|
191
|
+
begin
|
|
192
|
+
return options_call if on_auth_path? && options_request?
|
|
193
|
+
return request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
|
|
194
|
+
return callback_call if on_callback_path?
|
|
195
|
+
return other_phase if respond_to?(:other_phase)
|
|
196
|
+
rescue StandardError => e
|
|
197
|
+
raise e if env.delete('omniauth.error.app')
|
|
198
|
+
|
|
199
|
+
return fail!(e.message, e)
|
|
200
|
+
end
|
|
191
201
|
|
|
192
202
|
@app.call(env)
|
|
193
203
|
end
|
|
194
204
|
|
|
205
|
+
def warn_if_using_get_on_request_path
|
|
206
|
+
return unless on_request_path?
|
|
207
|
+
return unless OmniAuth.config.allowed_request_methods.include?(:get)
|
|
208
|
+
return if OmniAuth.config.silence_get_warning
|
|
209
|
+
|
|
210
|
+
log :warn, <<-WARN
|
|
211
|
+
You are using GET as an allowed request method for OmniAuth. This may leave
|
|
212
|
+
you open to CSRF attacks. As of v2.0.0, OmniAuth by default allows only POST
|
|
213
|
+
to its own routes. You should review the following resources to guide your
|
|
214
|
+
mitigation:
|
|
215
|
+
https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284
|
|
216
|
+
https://github.com/omniauth/omniauth/issues/960
|
|
217
|
+
https://nvd.nist.gov/vuln/detail/CVE-2015-9284
|
|
218
|
+
https://github.com/omniauth/omniauth/pull/809
|
|
219
|
+
|
|
220
|
+
You can ignore this warning by setting:
|
|
221
|
+
OmniAuth.config.silence_get_warning = true
|
|
222
|
+
WARN
|
|
223
|
+
end
|
|
224
|
+
|
|
195
225
|
# Responds to an OPTIONS request.
|
|
196
226
|
def options_call
|
|
197
227
|
OmniAuth.config.before_options_phase.call(env) if OmniAuth.config.before_options_phase
|
|
@@ -202,17 +232,19 @@ module OmniAuth
|
|
|
202
232
|
# Performs the steps necessary to run the request phase of a strategy.
|
|
203
233
|
def request_call # rubocop:disable CyclomaticComplexity, MethodLength, PerceivedComplexity
|
|
204
234
|
setup_phase
|
|
205
|
-
log :
|
|
235
|
+
log :debug, 'Request phase initiated.'
|
|
206
236
|
|
|
207
237
|
# store query params from the request url, extracted in the callback_phase
|
|
208
238
|
session['omniauth.params'] = request.GET
|
|
239
|
+
|
|
240
|
+
OmniAuth.config.request_validation_phase.call(env) if OmniAuth.config.request_validation_phase
|
|
209
241
|
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
|
210
242
|
|
|
211
243
|
if options.form.respond_to?(:call)
|
|
212
|
-
log :
|
|
244
|
+
log :debug, 'Rendering form from supplied Rack endpoint.'
|
|
213
245
|
options.form.call(env)
|
|
214
246
|
elsif options.form
|
|
215
|
-
log :
|
|
247
|
+
log :debug, 'Rendering form from underlying application.'
|
|
216
248
|
call_app!
|
|
217
249
|
elsif !options.origin_param
|
|
218
250
|
request_phase
|
|
@@ -225,12 +257,14 @@ module OmniAuth
|
|
|
225
257
|
|
|
226
258
|
request_phase
|
|
227
259
|
end
|
|
260
|
+
rescue OmniAuth::AuthenticityError => e
|
|
261
|
+
fail!(:authenticity_error, e)
|
|
228
262
|
end
|
|
229
263
|
|
|
230
264
|
# Performs the steps necessary to run the callback phase of a strategy.
|
|
231
265
|
def callback_call
|
|
232
266
|
setup_phase
|
|
233
|
-
log :
|
|
267
|
+
log :debug, 'Callback phase initiated.'
|
|
234
268
|
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
|
235
269
|
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
|
236
270
|
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
|
@@ -268,8 +302,14 @@ module OmniAuth
|
|
|
268
302
|
# in the event that OmniAuth has been configured to be
|
|
269
303
|
# in test mode.
|
|
270
304
|
def mock_call!(*)
|
|
271
|
-
|
|
272
|
-
|
|
305
|
+
begin
|
|
306
|
+
return mock_request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
|
|
307
|
+
return mock_callback_call if on_callback_path?
|
|
308
|
+
rescue StandardError => e
|
|
309
|
+
raise e if env.delete('omniauth.error.app')
|
|
310
|
+
|
|
311
|
+
return fail!(e.message, e)
|
|
312
|
+
end
|
|
273
313
|
|
|
274
314
|
call_app!
|
|
275
315
|
end
|
|
@@ -278,7 +318,10 @@ module OmniAuth
|
|
|
278
318
|
setup_phase
|
|
279
319
|
|
|
280
320
|
session['omniauth.params'] = request.GET
|
|
321
|
+
|
|
322
|
+
OmniAuth.config.request_validation_phase.call(env) if OmniAuth.config.request_validation_phase
|
|
281
323
|
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
|
324
|
+
|
|
282
325
|
if options.origin_param
|
|
283
326
|
if request.params[options.origin_param]
|
|
284
327
|
session['omniauth.origin'] = request.params[options.origin_param]
|
|
@@ -312,10 +355,10 @@ module OmniAuth
|
|
|
312
355
|
# underlying application. This will default to `/auth/:provider/setup`.
|
|
313
356
|
def setup_phase
|
|
314
357
|
if options[:setup].respond_to?(:call)
|
|
315
|
-
log :
|
|
358
|
+
log :debug, 'Setup endpoint detected, running now.'
|
|
316
359
|
options[:setup].call(env)
|
|
317
360
|
elsif options[:setup]
|
|
318
|
-
log :
|
|
361
|
+
log :debug, 'Calling through to underlying application for setup.'
|
|
319
362
|
setup_env = env.merge('PATH_INFO' => setup_path, 'REQUEST_METHOD' => 'GET')
|
|
320
363
|
call_app!(setup_env)
|
|
321
364
|
end
|
|
@@ -345,11 +388,13 @@ module OmniAuth
|
|
|
345
388
|
end
|
|
346
389
|
|
|
347
390
|
def auth_hash
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
391
|
+
credentials_data = credentials
|
|
392
|
+
extra_data = extra
|
|
393
|
+
AuthHash.new(:provider => name, :uid => uid).tap do |auth|
|
|
394
|
+
auth.info = info unless skip_info?
|
|
395
|
+
auth.credentials = credentials_data if credentials_data
|
|
396
|
+
auth.extra = extra_data if extra_data
|
|
397
|
+
end
|
|
353
398
|
end
|
|
354
399
|
|
|
355
400
|
# Determines whether or not user info should be retrieved. This
|
|
@@ -389,7 +434,12 @@ module OmniAuth
|
|
|
389
434
|
end
|
|
390
435
|
|
|
391
436
|
def request_path
|
|
392
|
-
@request_path ||=
|
|
437
|
+
@request_path ||=
|
|
438
|
+
if options[:request_path].is_a?(String)
|
|
439
|
+
options[:request_path]
|
|
440
|
+
else
|
|
441
|
+
"#{script_name}#{path_prefix}/#{name}"
|
|
442
|
+
end
|
|
393
443
|
end
|
|
394
444
|
|
|
395
445
|
def callback_path
|
|
@@ -397,7 +447,7 @@ module OmniAuth
|
|
|
397
447
|
path = options[:callback_path] if options[:callback_path].is_a?(String)
|
|
398
448
|
path ||= current_path if options[:callback_path].respond_to?(:call) && options[:callback_path].call(env)
|
|
399
449
|
path ||= custom_path(:request_path)
|
|
400
|
-
path ||= "#{path_prefix}/#{name}/callback"
|
|
450
|
+
path ||= "#{script_name}#{path_prefix}/#{name}/callback"
|
|
401
451
|
path
|
|
402
452
|
end
|
|
403
453
|
end
|
|
@@ -409,7 +459,7 @@ module OmniAuth
|
|
|
409
459
|
CURRENT_PATH_REGEX = %r{/$}.freeze
|
|
410
460
|
EMPTY_STRING = ''.freeze
|
|
411
461
|
def current_path
|
|
412
|
-
@current_path ||= request.
|
|
462
|
+
@current_path ||= request.path.downcase.sub(CURRENT_PATH_REGEX, EMPTY_STRING)
|
|
413
463
|
end
|
|
414
464
|
|
|
415
465
|
def query_string
|
|
@@ -418,6 +468,9 @@ module OmniAuth
|
|
|
418
468
|
|
|
419
469
|
def call_app!(env = @env)
|
|
420
470
|
@app.call(env)
|
|
471
|
+
rescue StandardError => e
|
|
472
|
+
env['omniauth.error.app'] = true
|
|
473
|
+
raise e
|
|
421
474
|
end
|
|
422
475
|
|
|
423
476
|
def full_host
|
|
@@ -441,7 +494,7 @@ module OmniAuth
|
|
|
441
494
|
end
|
|
442
495
|
|
|
443
496
|
def callback_url
|
|
444
|
-
full_host +
|
|
497
|
+
full_host + callback_path + query_string
|
|
445
498
|
end
|
|
446
499
|
|
|
447
500
|
def script_name
|
|
@@ -491,16 +544,15 @@ module OmniAuth
|
|
|
491
544
|
OmniAuth.config.on_failure.call(env)
|
|
492
545
|
end
|
|
493
546
|
|
|
494
|
-
def dup
|
|
495
|
-
super.tap do
|
|
496
|
-
@options = @options.dup
|
|
497
|
-
end
|
|
498
|
-
end
|
|
499
|
-
|
|
500
547
|
class Options < OmniAuth::KeyStore; end
|
|
501
548
|
|
|
502
549
|
protected
|
|
503
550
|
|
|
551
|
+
def initialize_copy(*args)
|
|
552
|
+
super
|
|
553
|
+
@options = @options.dup
|
|
554
|
+
end
|
|
555
|
+
|
|
504
556
|
def merge_stack(stack)
|
|
505
557
|
stack.inject({}) do |a, e|
|
|
506
558
|
a.merge!(e)
|
data/lib/omniauth/version.rb
CHANGED
data/lib/omniauth.rb
CHANGED
|
@@ -15,6 +15,7 @@ module OmniAuth
|
|
|
15
15
|
autoload :Form, 'omniauth/form'
|
|
16
16
|
autoload :AuthHash, 'omniauth/auth_hash'
|
|
17
17
|
autoload :FailureEndpoint, 'omniauth/failure_endpoint'
|
|
18
|
+
autoload :AuthenticityTokenProtection, 'omniauth/authenticity_token_protection'
|
|
18
19
|
|
|
19
20
|
def self.strategies
|
|
20
21
|
@strategies ||= []
|
|
@@ -29,20 +30,22 @@ module OmniAuth
|
|
|
29
30
|
logger
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
def self.defaults
|
|
33
|
+
def self.defaults # rubocop:disable MethodLength
|
|
33
34
|
@defaults ||= {
|
|
34
35
|
:camelizations => {},
|
|
35
36
|
:path_prefix => '/auth',
|
|
36
37
|
:on_failure => OmniAuth::FailureEndpoint,
|
|
37
38
|
:failure_raise_out_environments => ['development'],
|
|
39
|
+
:request_validation_phase => OmniAuth::AuthenticityTokenProtection,
|
|
38
40
|
:before_request_phase => nil,
|
|
39
41
|
:before_callback_phase => nil,
|
|
40
42
|
:before_options_phase => nil,
|
|
41
43
|
:form_css => Form::DEFAULT_CSS,
|
|
42
44
|
:test_mode => false,
|
|
43
45
|
:logger => default_logger,
|
|
44
|
-
:allowed_request_methods => %i[
|
|
45
|
-
:mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})}
|
|
46
|
+
:allowed_request_methods => %i[post],
|
|
47
|
+
:mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})},
|
|
48
|
+
:silence_get_warning => false
|
|
46
49
|
}
|
|
47
50
|
end
|
|
48
51
|
|
|
@@ -74,6 +77,14 @@ module OmniAuth
|
|
|
74
77
|
end
|
|
75
78
|
end
|
|
76
79
|
|
|
80
|
+
def request_validation_phase(&block)
|
|
81
|
+
if block_given?
|
|
82
|
+
@request_validation_phase = block
|
|
83
|
+
else
|
|
84
|
+
@request_validation_phase
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
77
88
|
def before_request_phase(&block)
|
|
78
89
|
if block_given?
|
|
79
90
|
@before_request_phase = block
|
|
@@ -111,8 +122,9 @@ module OmniAuth
|
|
|
111
122
|
camelizations[name.to_s] = camelized.to_s
|
|
112
123
|
end
|
|
113
124
|
|
|
114
|
-
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase
|
|
115
|
-
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css,
|
|
125
|
+
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase, :request_validation_phase
|
|
126
|
+
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css,
|
|
127
|
+
:test_mode, :mock_auth, :full_host, :camelizations, :logger, :silence_get_warning
|
|
116
128
|
end
|
|
117
129
|
|
|
118
130
|
def self.config
|
|
@@ -159,7 +171,7 @@ module OmniAuth
|
|
|
159
171
|
if first_letter_in_uppercase
|
|
160
172
|
word.to_s.gsub(%r{/(.?)}) { '::' + Regexp.last_match[1].upcase }.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
|
|
161
173
|
else
|
|
162
|
-
word.
|
|
174
|
+
camelize(word).tap { |w| w[0] = w[0].downcase }
|
|
163
175
|
end
|
|
164
176
|
end
|
|
165
177
|
end
|
data/omniauth.gemspec
CHANGED
|
@@ -6,8 +6,9 @@ require 'omniauth/version'
|
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
8
|
spec.add_dependency 'hashie', ['>= 3.4.6']
|
|
9
|
-
spec.add_dependency 'rack',
|
|
10
|
-
spec.add_development_dependency 'bundler', '~>
|
|
9
|
+
spec.add_dependency 'rack', '>= 2.2.3'
|
|
10
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
11
|
+
spec.add_dependency 'rack-protection'
|
|
11
12
|
spec.add_development_dependency 'rake', '~> 12.0'
|
|
12
13
|
spec.authors = ['Michael Bleigh', 'Erik Michaels-Ober', 'Tom Milewski']
|
|
13
14
|
spec.description = 'A generalized Rack framework for multiple-provider authentication.'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniauth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Bleigh
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2022-
|
|
13
|
+
date: 2022-04-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: hashie
|
|
@@ -32,34 +32,42 @@ dependencies:
|
|
|
32
32
|
requirements:
|
|
33
33
|
- - ">="
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version:
|
|
36
|
-
- - "<"
|
|
37
|
-
- !ruby/object:Gem::Version
|
|
38
|
-
version: '3'
|
|
35
|
+
version: 2.2.3
|
|
39
36
|
type: :runtime
|
|
40
37
|
prerelease: false
|
|
41
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
39
|
requirements:
|
|
43
40
|
- - ">="
|
|
44
41
|
- !ruby/object:Gem::Version
|
|
45
|
-
version:
|
|
46
|
-
- - "<"
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: '3'
|
|
42
|
+
version: 2.2.3
|
|
49
43
|
- !ruby/object:Gem::Dependency
|
|
50
44
|
name: bundler
|
|
51
45
|
requirement: !ruby/object:Gem::Requirement
|
|
52
46
|
requirements:
|
|
53
47
|
- - "~>"
|
|
54
48
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '
|
|
49
|
+
version: '2.0'
|
|
56
50
|
type: :development
|
|
57
51
|
prerelease: false
|
|
58
52
|
version_requirements: !ruby/object:Gem::Requirement
|
|
59
53
|
requirements:
|
|
60
54
|
- - "~>"
|
|
61
55
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '
|
|
56
|
+
version: '2.0'
|
|
57
|
+
- !ruby/object:Gem::Dependency
|
|
58
|
+
name: rack-protection
|
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
type: :runtime
|
|
65
|
+
prerelease: false
|
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
63
71
|
- !ruby/object:Gem::Dependency
|
|
64
72
|
name: rake
|
|
65
73
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -83,18 +91,21 @@ executables: []
|
|
|
83
91
|
extensions: []
|
|
84
92
|
extra_rdoc_files: []
|
|
85
93
|
files:
|
|
94
|
+
- ".github/FUNDING.yml"
|
|
86
95
|
- ".github/ISSUE_TEMPLATE.md"
|
|
96
|
+
- ".github/workflows/main.yml"
|
|
87
97
|
- ".gitignore"
|
|
88
98
|
- ".rspec"
|
|
89
99
|
- ".rubocop.yml"
|
|
90
|
-
- ".travis.yml"
|
|
91
100
|
- ".yardopts"
|
|
92
101
|
- Gemfile
|
|
93
102
|
- LICENSE.md
|
|
94
103
|
- README.md
|
|
95
104
|
- Rakefile
|
|
105
|
+
- SECURITY.md
|
|
96
106
|
- lib/omniauth.rb
|
|
97
107
|
- lib/omniauth/auth_hash.rb
|
|
108
|
+
- lib/omniauth/authenticity_token_protection.rb
|
|
98
109
|
- lib/omniauth/builder.rb
|
|
99
110
|
- lib/omniauth/failure_endpoint.rb
|
|
100
111
|
- lib/omniauth/form.css
|
data/.travis.yml
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
bundler_args: --without development
|
|
2
|
-
before_install:
|
|
3
|
-
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
|
4
|
-
- gem install bundler -v '1.17.3'
|
|
5
|
-
install:
|
|
6
|
-
- bundle _1.17.3_ install --jobs=3 --retry=3
|
|
7
|
-
cache: bundler
|
|
8
|
-
env:
|
|
9
|
-
global:
|
|
10
|
-
- JRUBY_OPTS="$JRUBY_OPTS --debug"
|
|
11
|
-
language: ruby
|
|
12
|
-
rvm:
|
|
13
|
-
- jruby-9000
|
|
14
|
-
- 2.2.9
|
|
15
|
-
- 2.3.5
|
|
16
|
-
- 2.4.4
|
|
17
|
-
- 2.5.3
|
|
18
|
-
- jruby-head
|
|
19
|
-
- ruby-head
|
|
20
|
-
matrix:
|
|
21
|
-
allow_failures:
|
|
22
|
-
- rvm: jruby-head
|
|
23
|
-
- rvm: ruby-head
|
|
24
|
-
fast_finish: true
|
|
25
|
-
sudo: false
|