doorkeeper 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/.travis.yml +38 -10
- data/CHANGELOG.md +43 -1
- data/CONTRIBUTING.md +35 -0
- data/Gemfile +4 -26
- data/README.md +21 -55
- data/Rakefile +3 -1
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/applications_controller.rb +4 -5
- data/app/controllers/doorkeeper/authorizations_controller.rb +4 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -2
- data/app/helpers/doorkeeper/{form_errors_helper.rb → dashboard_helper.rb} +5 -1
- data/app/validators/redirect_uri_validator.rb +6 -0
- data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/index.html.erb +1 -1
- data/config/locales/en.yml +6 -3
- data/doorkeeper.gemspec +3 -3
- data/gemfiles/Gemfile.common.rb +11 -0
- data/gemfiles/Gemfile.mongo_mapper.rb +5 -0
- data/gemfiles/Gemfile.mongoid2.rb +5 -0
- data/gemfiles/Gemfile.mongoid3.rb +4 -0
- data/gemfiles/Gemfile.mongoid4.rb +5 -0
- data/lib/doorkeeper/config.rb +34 -24
- data/lib/doorkeeper/engine.rb +1 -2
- data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
- data/lib/doorkeeper/models/access_grant_mixin.rb +36 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +122 -0
- data/lib/doorkeeper/models/application_mixin.rb +60 -0
- data/lib/doorkeeper/models/{expirable.rb → concerns/expirable.rb} +6 -5
- data/lib/doorkeeper/models/{ownership.rb → concerns/ownership.rb} +7 -7
- data/lib/doorkeeper/models/{revocable.rb → concerns/revocable.rb} +1 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +6 -6
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
- data/lib/doorkeeper/oauth/pre_authorization.rb +5 -1
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -6
- data/lib/doorkeeper/oauth/scopes.rb +6 -1
- data/lib/doorkeeper/oauth/token.rb +3 -2
- data/lib/doorkeeper/orm/active_record/access_grant.rb +7 -0
- data/lib/doorkeeper/orm/active_record/access_token.rb +21 -0
- data/lib/doorkeeper/{models → orm}/active_record/application.rb +1 -3
- data/lib/doorkeeper/orm/active_record.rb +17 -0
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_grant.rb +4 -5
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_token.rb +12 -17
- data/lib/doorkeeper/{models → orm}/mongo_mapper/application.rb +3 -4
- data/lib/doorkeeper/orm/mongo_mapper.rb +11 -0
- data/lib/doorkeeper/{models → orm}/mongoid2/access_grant.rb +5 -3
- data/lib/doorkeeper/{models → orm}/mongoid2/access_token.rb +10 -12
- data/lib/doorkeeper/{models → orm}/mongoid2/application.rb +3 -0
- data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid2.rb +11 -0
- data/lib/doorkeeper/orm/mongoid3/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid3/access_token.rb +37 -0
- data/lib/doorkeeper/{models/mongoid3_4 → orm/mongoid3}/application.rb +3 -0
- data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid3.rb +11 -0
- data/lib/doorkeeper/orm/mongoid4/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid4/access_token.rb +37 -0
- data/lib/doorkeeper/orm/mongoid4/application.rb +25 -0
- data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/orm/mongoid4.rb +11 -0
- data/lib/doorkeeper/rails/helpers.rb +63 -0
- data/lib/doorkeeper/rails/routes.rb +1 -12
- data/lib/doorkeeper/request/code.rb +0 -1
- data/lib/doorkeeper/request/token.rb +0 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +15 -6
- data/lib/generators/doorkeeper/application_owner_generator.rb +4 -1
- data/lib/generators/doorkeeper/application_scopes_generator.rb +34 -0
- data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +5 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +8 -1
- data/lib/generators/doorkeeper/templates/migration.rb +1 -0
- data/lib/generators/doorkeeper/views_generator.rb +4 -5
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/protected_resources_controller_spec.rb +25 -175
- data/spec/controllers/tokens_controller_spec.rb +15 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/metal_controller.rb +2 -2
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +5 -5
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/config/boot.rb +4 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +5 -0
- data/spec/dummy/db/schema.rb +41 -40
- data/spec/factories.rb +24 -0
- data/spec/lib/config_spec.rb +30 -10
- data/spec/lib/models/expirable_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +8 -3
- data/spec/lib/models/scopes_spec.rb +3 -3
- data/spec/lib/oauth/client_spec.rb +1 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
- data/spec/lib/oauth/pre_authorization_spec.rb +43 -9
- data/spec/lib/oauth/token_request_spec.rb +28 -1
- data/spec/lib/oauth/token_spec.rb +1 -1
- data/spec/models/doorkeeper/application_spec.rb +16 -1
- data/spec/requests/applications/applications_request_spec.rb +6 -4
- data/spec/requests/flows/implicit_grant_spec.rb +32 -0
- data/spec/requests/flows/refresh_token_spec.rb +12 -3
- data/spec/spec_helper_integration.rb +8 -2
- data/spec/support/shared/controllers_shared_context.rb +2 -2
- data/spec/validators/redirect_uri_validator_spec.rb +30 -3
- metadata +52 -39
- data/lib/doorkeeper/doorkeeper_for.rb +0 -69
- data/lib/doorkeeper/helpers/filter.rb +0 -64
- data/lib/doorkeeper/models/access_grant.rb +0 -30
- data/lib/doorkeeper/models/access_token.rb +0 -106
- data/lib/doorkeeper/models/active_record/access_grant.rb +0 -9
- data/lib/doorkeeper/models/active_record/access_token.rb +0 -25
- data/lib/doorkeeper/models/application.rb +0 -40
- data/lib/doorkeeper/models/mongoid/scopes.rb +0 -15
- data/lib/doorkeeper/models/mongoid/version.rb +0 -15
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +0 -27
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +0 -46
- data/lib/doorkeeper/models/scopes.rb +0 -21
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
- data/script/rails +0 -5
- data/script/run_all +0 -14
- data/spec/factories/access_grant.rb +0 -9
- data/spec/factories/access_token.rb +0 -11
- data/spec/factories/application.rb +0 -6
- /data/lib/{generators/doorkeeper → doorkeeper/generators/doorkeeper/mongo_mapper}/templates/indexes.rb +0 -0
- /data/lib/doorkeeper/models/{accessible.rb → concerns/accessible.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb6985f71c5db8c5a96f9205a290aa6d36956177
|
4
|
+
data.tar.gz: 4d96f1493d890735bdeaf379c6345a949ecd0857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0efb46569e591675b5a208a7cae0d72eb746a17ea99573359e7788374afdcc9b052ef38577abba6681aecb89ddc95e7d6dc0b09bb7201beeb2ac0c4f671d899f
|
7
|
+
data.tar.gz: c3786d7fb5f6c2867fddd0d67948bfdc0292451f82aec9fcb1075b08d37c1a439028984c11e2100f1a2cff7ddd8e223e0da8dfb11ae511085bec9fa9b5c1486a
|
data/.hound.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,18 +1,46 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
|
2
5
|
rvm:
|
3
6
|
- 1.9.3
|
4
7
|
- 2.0
|
5
8
|
- 2.1
|
9
|
+
|
6
10
|
env:
|
7
|
-
- rails=3.1
|
8
|
-
- rails=3.2.
|
9
|
-
- rails=4.0.
|
10
|
-
- rails=4.1.
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
11
|
+
# - rails=3.1 # Don't need it in the CI matrix
|
12
|
+
- rails=3.2.0
|
13
|
+
- rails=4.0.0
|
14
|
+
- rails=4.1.0
|
15
|
+
- rails=4.2.0.rc2
|
16
|
+
|
17
|
+
gemfile:
|
18
|
+
- Gemfile
|
19
|
+
- gemfiles/Gemfile.mongoid2.rb
|
20
|
+
- gemfiles/Gemfile.mongoid3.rb
|
21
|
+
- gemfiles/Gemfile.mongoid4.rb
|
22
|
+
- gemfiles/Gemfile.mongo_mapper.rb
|
23
|
+
|
17
24
|
services:
|
18
25
|
- mongodb
|
26
|
+
|
27
|
+
matrix:
|
28
|
+
exclude:
|
29
|
+
- gemfile: gemfiles/Gemfile.mongoid2.rb
|
30
|
+
env: rails=4.0.0
|
31
|
+
- gemfile: gemfiles/Gemfile.mongoid2.rb
|
32
|
+
env: rails=4.1.0
|
33
|
+
- gemfile: gemfiles/Gemfile.mongoid2.rb
|
34
|
+
env: rails=4.2.0.rc2
|
35
|
+
|
36
|
+
- gemfile: gemfiles/Gemfile.mongoid3.rb
|
37
|
+
env: rails=4.0.0
|
38
|
+
- gemfile: gemfiles/Gemfile.mongoid3.rb
|
39
|
+
env: rails=4.1.0
|
40
|
+
- gemfile: gemfiles/Gemfile.mongoid3.rb
|
41
|
+
env: rails=4.2.0.rc2
|
42
|
+
|
43
|
+
- gemfile: gemfiles/Gemfile.mongoid4.rb
|
44
|
+
env: rails=3.1.0
|
45
|
+
- gemfile: gemfiles/Gemfile.mongoid4.rb
|
46
|
+
env: rails=3.2.0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,48 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
### Backward incompatible changes
|
6
|
+
|
7
|
+
- [#448] Removes `doorkeeper_for` helper. Now we use
|
8
|
+
`before_action :doorkeeper_authorize!`.
|
9
|
+
- [#469] Allow client applications to restrict the set of allowable scopes.
|
10
|
+
Fixes #317. `oauth_applications` relation needs a new `scopes` string column,
|
11
|
+
non nullable, which defaults to an empty string. To add the column run:
|
12
|
+
|
13
|
+
```
|
14
|
+
rails generate doorkeeper:application_scopes
|
15
|
+
```
|
16
|
+
|
17
|
+
If you’d rather do it by hand, your ActiveRecord migration should contain:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
add_column :oauth_applications, :scopes, :string, null: false, default: ‘’
|
21
|
+
```
|
22
|
+
|
23
|
+
### Removed deprecations
|
24
|
+
|
25
|
+
- Removes `test_redirect_uri` option. It is now called `native_redirect_uri`.
|
26
|
+
- [#446] Removes `mount Doorkeeper::Engine`. Now we use `use_doorkeeper`.
|
27
|
+
|
28
|
+
### Other changes/enhancements
|
29
|
+
|
30
|
+
- [#484] Performance improvement - avoid performing order_by when not required.
|
31
|
+
- [#450] When password is invalid in Password Credentials Grant, Doorkeeper
|
32
|
+
returned 'invalid_resource_owner' instead of 'invalid_grant', as the spec
|
33
|
+
declares. Fixes #444.
|
34
|
+
- [#452] Allows `revoked_at` to be set in the future, for future expiry.
|
35
|
+
Rationale: https://github.com/doorkeeper-gem/doorkeeper/pull/452#issuecomment-51431459
|
36
|
+
- [#480] For Implicit grant flow, access tokens can now be reused. Fixes #421.
|
37
|
+
- [#491] Reworks of @jasl's #454 and #478. ORM refactor that allows doorkeeper
|
38
|
+
to be extended more easily with unsupported ORMs. It also marks the boundaries
|
39
|
+
between shared model code and ORM specifics inside of the gem.
|
40
|
+
- [#496] Tests with Rails 4.2.
|
41
|
+
- [#489] Adds `force_ssl_in_redirect_uri` to force the usage of the HTTPS
|
42
|
+
protocol in non-native redirect uris.
|
43
|
+
- [#516] Adds `protect_from_forgery` to `Doorkeeper::ApplicationController`
|
44
|
+
- [#518] Fix random failures in mongodb.
|
45
|
+
|
4
46
|
|
5
47
|
## 1.4.0
|
6
48
|
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
We love pull requests. Here's a quick guide.
|
4
|
+
|
5
|
+
Fork, then clone the repo:
|
6
|
+
|
7
|
+
git clone git@github.com:your-username/doorkeeper.git
|
8
|
+
|
9
|
+
Set up Ruby dependencies via Bundler
|
10
|
+
|
11
|
+
bundle install
|
12
|
+
|
13
|
+
Make sure the tests pass:
|
14
|
+
|
15
|
+
rake
|
16
|
+
|
17
|
+
Make your change. Add tests for your change. Make the tests pass:
|
18
|
+
|
19
|
+
rake
|
20
|
+
|
21
|
+
Push to your fork and submit a pull request.
|
22
|
+
|
23
|
+
At this point you're waiting on us. We like to at least comment on pull requests
|
24
|
+
within three business days (and, typically, one business day). We may suggest
|
25
|
+
some changes or improvements or alternatives.
|
26
|
+
|
27
|
+
Some things that will increase the chance that your pull request is accepted:
|
28
|
+
|
29
|
+
* Write tests.
|
30
|
+
* Follow our [style guide][style]. Address Hound CI comments unless you have a
|
31
|
+
good reason not to.
|
32
|
+
* Write a [good commit message][commit].
|
33
|
+
|
34
|
+
[style]: https://github.com/thoughtbot/guides/tree/master/style
|
35
|
+
[commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
data/Gemfile
CHANGED
@@ -1,33 +1,11 @@
|
|
1
|
-
|
2
|
-
ENV['rails'] ||= ENV['orm'] == "mongoid4" ? '4.0.2' : '3.2.13'
|
3
|
-
ENV['orm'] ||= 'active_record'
|
1
|
+
ENV['rails'] ||= '4.2.0.rc2'
|
4
2
|
|
5
3
|
source 'https://rubygems.org'
|
6
4
|
|
7
|
-
|
8
|
-
gem 'rails', ENV['rails']
|
9
|
-
|
10
|
-
gem 'database_cleaner', '~> 1.0.0.RC1' if ENV['rails'][0] == '4'
|
11
|
-
|
12
|
-
case ENV['orm']
|
13
|
-
when 'active_record'
|
14
|
-
gem 'activerecord'
|
15
|
-
|
16
|
-
when 'mongoid2'
|
17
|
-
gem 'mongoid', '2.5.1'
|
18
|
-
gem 'bson_ext', '~> 1.7'
|
19
|
-
|
20
|
-
when 'mongoid3'
|
21
|
-
gem 'mongoid', '3.0.10'
|
22
|
-
|
23
|
-
when 'mongoid4'
|
24
|
-
gem 'mongoid', '4.0.0.beta1'
|
25
|
-
gem 'moped'
|
26
|
-
|
27
|
-
when 'mongo_mapper'
|
28
|
-
gem 'mongo_mapper', '0.12.0'
|
29
|
-
gem 'bson_ext', '~> 1.7'
|
5
|
+
gem 'rails', "~> #{ENV['rails']}"
|
30
6
|
|
7
|
+
if ENV['rails'][0] == '4'
|
8
|
+
gem 'database_cleaner'
|
31
9
|
end
|
32
10
|
|
33
11
|
gemspec
|
data/README.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# Doorkeeper - awesome oauth provider for your Rails app.
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/doorkeeper-gem/doorkeeper.
|
4
|
-
[![Dependency Status](https://gemnasium.com/applicake/doorkeeper.
|
5
|
-
[![Code Climate](https://codeclimate.com/github/applicake/doorkeeper.
|
6
|
-
[![Gem Version](https://badge.fury.io/rb/doorkeeper.
|
3
|
+
[![Build Status](https://travis-ci.org/doorkeeper-gem/doorkeeper.svg?branch=master)](https://travis-ci.org/doorkeeper-gem/doorkeeper)
|
4
|
+
[![Dependency Status](https://gemnasium.com/applicake/doorkeeper.svg?travis)](https://gemnasium.com/applicake/doorkeeper)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/applicake/doorkeeper.svg)](https://codeclimate.com/github/applicake/doorkeeper)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
|
7
7
|
|
8
8
|
Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider functionality to your application.
|
9
9
|
|
10
|
+
## Documentation valid for `master` branch
|
11
|
+
|
12
|
+
Please check the documentation for the version of doorkeeper you are using in:
|
13
|
+
https://github.com/doorkeeper-gem/doorkeeper/releases.
|
14
|
+
|
10
15
|
## Table of Contents
|
11
16
|
|
12
17
|
- [Useful links](#useful-links)
|
@@ -146,66 +151,25 @@ models, session or routes helpers. However, since this code is not run in the
|
|
146
151
|
context of your application's `ApplicationController` it doesn't have access to
|
147
152
|
the methods defined over there.
|
148
153
|
|
149
|
-
|
150
|
-
use warden to authenticate the block:
|
151
|
-
|
152
|
-
``` ruby
|
153
|
-
resource_owner_authenticator do
|
154
|
-
current_user || warden.authenticate!(:scope => :user)
|
155
|
-
end
|
156
|
-
```
|
157
|
-
|
158
|
-
Side note: when using devise you have access to `current_user` as devise extends
|
159
|
-
entire `ActionController::Base` with the `current_#{mapping}`.
|
160
|
-
|
161
|
-
If you are not using devise, you may want to check other ways of
|
162
|
-
authentication
|
154
|
+
You may want to check other ways of authentication
|
163
155
|
[here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Authenticating-using-Clearance-or-DIY).
|
164
156
|
|
165
157
|
## Protecting resources with OAuth (a.k.a your API endpoint)
|
166
158
|
|
167
|
-
To protect your API with OAuth,
|
168
|
-
|
169
|
-
|
170
|
-
For example, if you have a products controller under api/v1, you can require
|
171
|
-
the OAuth authentication with:
|
159
|
+
To protect your API with OAuth, you just need to setup `before_action`s
|
160
|
+
specifying the actions you want to protect. For example:
|
172
161
|
|
173
162
|
``` ruby
|
174
163
|
class Api::V1::ProductsController < Api::V1::ApiController
|
175
|
-
|
176
|
-
doorkeeper_for :all, except: :index # All actions except index
|
177
|
-
doorkeeper_for :index, :show # Only for index and show action
|
164
|
+
before_action :doorkeeper_authorize! # Require access token for all actions
|
178
165
|
|
179
166
|
# your actions
|
180
167
|
end
|
181
168
|
```
|
182
169
|
|
183
|
-
You
|
184
|
-
|
185
|
-
|
186
|
-
You can pass `if` or `unless` blocks that would specify when doorkeeper has to
|
187
|
-
guard the access.
|
188
|
-
|
189
|
-
``` ruby
|
190
|
-
class Api::V1::ProductsController < Api::V1::ApiController
|
191
|
-
doorkeeper_for :all, :if => lambda { request.xhr? }
|
192
|
-
end
|
193
|
-
```
|
194
|
-
|
195
|
-
### ActionController::Metal integration
|
170
|
+
You can pass any option `before_action` accepts, such as `if`, `only`,
|
171
|
+
`except`, and others.
|
196
172
|
|
197
|
-
The `doorkeeper_for` filter is intended to work with ActionController::Metal
|
198
|
-
too. You only need to include the required `ActionController` modules:
|
199
|
-
|
200
|
-
```ruby
|
201
|
-
class MetalController < ActionController::Metal
|
202
|
-
include AbstractController::Callbacks
|
203
|
-
include ActionController::Head
|
204
|
-
include Doorkeeper::Helpers::Filter
|
205
|
-
|
206
|
-
doorkeeper_for :all
|
207
|
-
end
|
208
|
-
```
|
209
173
|
|
210
174
|
### Route Constraints and other integrations
|
211
175
|
|
@@ -248,8 +212,10 @@ And in your controllers:
|
|
248
212
|
|
249
213
|
```ruby
|
250
214
|
class Api::V1::ProductsController < Api::V1::ApiController
|
251
|
-
|
252
|
-
|
215
|
+
before_action -> { doorkeeper_authorize! :public }, only: :index
|
216
|
+
before_action only: [:create, :update, :destroy] do
|
217
|
+
doorkeeper_authorize! :admin, :write
|
218
|
+
end
|
253
219
|
end
|
254
220
|
```
|
255
221
|
|
@@ -265,8 +231,8 @@ controller that returns the resource owner instance:
|
|
265
231
|
|
266
232
|
``` ruby
|
267
233
|
class Api::V1::CredentialsController < Api::V1::ApiController
|
268
|
-
|
269
|
-
respond_to
|
234
|
+
before_action :doorkeeper_authorize!
|
235
|
+
respond_to :json
|
270
236
|
|
271
237
|
# GET /me.json
|
272
238
|
def me
|
data/Rakefile
CHANGED
@@ -5,7 +5,9 @@ desc 'Default: run specs.'
|
|
5
5
|
task :default => :spec
|
6
6
|
|
7
7
|
desc "Run all specs"
|
8
|
-
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |config|
|
9
|
+
config.verbose = false
|
10
|
+
end
|
9
11
|
|
10
12
|
namespace :doorkeeper do
|
11
13
|
desc "Install doorkeeper in dummy app"
|
@@ -2,12 +2,12 @@ module Doorkeeper
|
|
2
2
|
class ApplicationController < ActionController::Base
|
3
3
|
include Helpers::Controller
|
4
4
|
|
5
|
-
helper 'doorkeeper/form_errors'
|
6
|
-
|
7
5
|
if ::Rails.version.to_i < 4
|
8
6
|
protect_from_forgery
|
9
7
|
else
|
10
8
|
protect_from_forgery with: :exception
|
11
9
|
end
|
10
|
+
|
11
|
+
helper 'doorkeeper/dashboard'
|
12
12
|
end
|
13
13
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class ApplicationsController < Doorkeeper::ApplicationController
|
3
3
|
layout 'doorkeeper/admin'
|
4
|
-
respond_to :html
|
5
4
|
|
6
5
|
before_filter :authenticate_admin!
|
7
6
|
before_filter :set_application, only: [:show, :edit, :update, :destroy]
|
@@ -18,7 +17,7 @@ module Doorkeeper
|
|
18
17
|
@application = Application.new(application_params)
|
19
18
|
if @application.save
|
20
19
|
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
|
21
|
-
|
20
|
+
redirect_to oauth_application_url(@application)
|
22
21
|
else
|
23
22
|
render :new
|
24
23
|
end
|
@@ -27,7 +26,7 @@ module Doorkeeper
|
|
27
26
|
def update
|
28
27
|
if @application.update_attributes(application_params)
|
29
28
|
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :update])
|
30
|
-
|
29
|
+
redirect_to oauth_application_url(@application)
|
31
30
|
else
|
32
31
|
render :edit
|
33
32
|
end
|
@@ -46,9 +45,9 @@ module Doorkeeper
|
|
46
45
|
|
47
46
|
def application_params
|
48
47
|
if params.respond_to?(:permit)
|
49
|
-
params.require(:
|
48
|
+
params.require(:doorkeeper_application).permit(:name, :redirect_uri)
|
50
49
|
else
|
51
|
-
params[:
|
50
|
+
params[:doorkeeper_application].slice(:name, :redirect_uri) rescue nil
|
52
51
|
end
|
53
52
|
end
|
54
53
|
end
|
@@ -4,7 +4,7 @@ module Doorkeeper
|
|
4
4
|
|
5
5
|
def new
|
6
6
|
if pre_auth.authorizable?
|
7
|
-
if
|
7
|
+
if skip_authorization? || matching_token?
|
8
8
|
auth = authorization.authorize
|
9
9
|
redirect_to auth.redirect_uri
|
10
10
|
else
|
@@ -41,7 +41,9 @@ module Doorkeeper
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def pre_auth
|
44
|
-
@pre_auth ||= OAuth::PreAuthorization.new(Doorkeeper.configuration,
|
44
|
+
@pre_auth ||= OAuth::PreAuthorization.new(Doorkeeper.configuration,
|
45
|
+
server.client_via_uid,
|
46
|
+
params)
|
45
47
|
end
|
46
48
|
|
47
49
|
def authorization
|
@@ -18,14 +18,14 @@ module Doorkeeper
|
|
18
18
|
revoke_token(request.POST['token']) if request.POST['token']
|
19
19
|
end
|
20
20
|
# The authorization server responds with HTTP status code 200 if the
|
21
|
-
# token has been revoked
|
21
|
+
# token has been revoked successfully or if the client submitted an invalid token
|
22
22
|
render json: {}, status: 200
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def revoke_token(token)
|
28
|
-
token = AccessToken.
|
28
|
+
token = AccessToken.by_token(token) || AccessToken.by_refresh_token(token)
|
29
29
|
if token && doorkeeper_token.same_credential?(token)
|
30
30
|
token.revoke
|
31
31
|
true
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Doorkeeper::
|
1
|
+
module Doorkeeper::DashboardHelper
|
2
2
|
def doorkeeper_errors_for(object, method)
|
3
3
|
if object.errors[method].present?
|
4
4
|
object.errors[method].map do |msg|
|
@@ -8,4 +8,8 @@ module Doorkeeper::FormErrorsHelper
|
|
8
8
|
end.reduce(&:join).html_safe
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
def doorkeeper_submit_path(application)
|
13
|
+
application.persisted? ? oauth_application_path(application) : oauth_applications_path
|
14
|
+
end
|
11
15
|
end
|
@@ -14,6 +14,7 @@ class RedirectUriValidator < ActiveModel::EachValidator
|
|
14
14
|
return if native_redirect_uri?(uri)
|
15
15
|
record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
|
16
16
|
record.errors.add(attribute, :relative_uri) if uri.scheme.nil? || uri.host.nil?
|
17
|
+
record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
rescue URI::InvalidURIError
|
@@ -25,4 +26,9 @@ class RedirectUriValidator < ActiveModel::EachValidator
|
|
25
26
|
def native_redirect_uri?(uri)
|
26
27
|
self.class.native_redirect_uri.present? && uri.to_s == self.class.native_redirect_uri.to_s
|
27
28
|
end
|
29
|
+
|
30
|
+
def invalid_ssl_uri?(uri)
|
31
|
+
forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
|
32
|
+
forces_ssl && uri.try(:scheme) != 'https'
|
33
|
+
end
|
28
34
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%- submit_btn_css ||= 'btn btn-link' %>
|
2
|
-
<%= form_tag
|
2
|
+
<%= form_tag oauth_application_path(application) do %>
|
3
3
|
<input type="hidden" name="_method" value="delete">
|
4
4
|
<%= submit_tag 'Destroy', onclick: "return confirm('Are you sure?')", class: submit_btn_css %>
|
5
5
|
<% end %>
|
@@ -1,10 +1,10 @@
|
|
1
|
-
<%= form_for
|
1
|
+
<%= form_for application, url: doorkeeper_submit_path(application), html: {class: 'form-horizontal', role: 'form'} do |f| %>
|
2
2
|
<% if application.errors.any? %>
|
3
3
|
<div class="alert alert-danger" data-alert><p>Whoops! Check your form for possible errors</p></div>
|
4
4
|
<% end %>
|
5
5
|
|
6
6
|
<%= content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do %>
|
7
|
-
<%= f.label :name, class: 'col-sm-2 control-label'
|
7
|
+
<%= f.label :name, class: 'col-sm-2 control-label' %>
|
8
8
|
<div class="col-sm-10">
|
9
9
|
<%= f.text_field :name, class: 'form-control' %>
|
10
10
|
<%= doorkeeper_errors_for application, :name %>
|
@@ -12,7 +12,7 @@
|
|
12
12
|
<% end %>
|
13
13
|
|
14
14
|
<%= content_tag :div, class: "form-group#{' has-error' if application.errors[:redirect_uri].present?}" do %>
|
15
|
-
<%= f.label :redirect_uri, class: 'col-sm-2 control-label'
|
15
|
+
<%= f.label :redirect_uri, class: 'col-sm-2 control-label' %>
|
16
16
|
<div class="col-sm-10">
|
17
17
|
<%= f.text_area :redirect_uri, class: 'form-control' %>
|
18
18
|
<%= doorkeeper_errors_for application, :redirect_uri %>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<tbody>
|
17
17
|
<% @applications.each do |application| %>
|
18
18
|
<tr id="application_<%= application.id %>">
|
19
|
-
<td><%= link_to application.name,
|
19
|
+
<td><%= link_to application.name, oauth_application_path(application) %></td>
|
20
20
|
<td><%= application.redirect_uri %></td>
|
21
21
|
<td><%= link_to 'Edit', edit_oauth_application_path(application), class: 'btn btn-link' %></td>
|
22
22
|
<td><%= render 'delete_form', application: application %></td>
|
data/config/locales/en.yml
CHANGED
@@ -2,30 +2,33 @@ en:
|
|
2
2
|
activerecord:
|
3
3
|
errors:
|
4
4
|
models:
|
5
|
-
application:
|
5
|
+
doorkeeper/application:
|
6
6
|
attributes:
|
7
7
|
redirect_uri:
|
8
8
|
fragment_present: 'cannot contain a fragment.'
|
9
9
|
invalid_uri: 'must be a valid URI.'
|
10
10
|
relative_uri: 'must be an absolute URI.'
|
11
|
+
secured_uri: 'must be an HTTPS/SSL URI.'
|
11
12
|
mongoid:
|
12
13
|
errors:
|
13
14
|
models:
|
14
|
-
application:
|
15
|
+
doorkeeper/application:
|
15
16
|
attributes:
|
16
17
|
redirect_uri:
|
17
18
|
fragment_present: 'cannot contain a fragment.'
|
18
19
|
invalid_uri: 'must be a valid URI.'
|
19
20
|
relative_uri: 'must be an absolute URI.'
|
21
|
+
secured_uri: 'must be an HTTPS/SSL URI.'
|
20
22
|
mongo_mapper:
|
21
23
|
errors:
|
22
24
|
models:
|
23
|
-
application:
|
25
|
+
doorkeeper/application:
|
24
26
|
attributes:
|
25
27
|
redirect_uri:
|
26
28
|
fragment_present: 'cannot contain a fragment.'
|
27
29
|
invalid_uri: 'must be a valid URI.'
|
28
30
|
relative_uri: 'must be an absolute URI.'
|
31
|
+
secured_uri: 'must be an HTTPS/SSL URI.'
|
29
32
|
doorkeeper:
|
30
33
|
errors:
|
31
34
|
messages:
|
data/doorkeeper.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "doorkeeper/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "doorkeeper"
|
7
7
|
s.version = Doorkeeper::VERSION
|
8
|
-
s.authors = ["Felipe Elias Philipp", "
|
9
|
-
s.email =
|
8
|
+
s.authors = ["Felipe Elias Philipp", "Tute Costa"]
|
9
|
+
s.email = %w(tutecosta@gmail.com)
|
10
10
|
s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
|
11
11
|
s.summary = "Doorkeeper is an OAuth 2 provider for Rails."
|
12
12
|
s.description = "Doorkeeper is an OAuth 2 provider for Rails."
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency "rspec-rails", "~> 2.99.0"
|
23
23
|
s.add_development_dependency "capybara", "~> 2.3.0"
|
24
24
|
s.add_development_dependency "generator_spec", "~> 0.9.0"
|
25
|
-
s.add_development_dependency "factory_girl", "~> 4.
|
25
|
+
s.add_development_dependency "factory_girl", "~> 4.5.0"
|
26
26
|
s.add_development_dependency "timecop", "~> 0.7.0"
|
27
27
|
s.add_development_dependency "database_cleaner", "~> 1.3.0"
|
28
28
|
s.add_development_dependency "rspec-activemodel-mocks", "~> 1.0.0"
|