doorkeeper 3.1.0 → 4.2.6

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.

Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +5 -0
  4. data/.travis.yml +16 -12
  5. data/Appraisals +14 -0
  6. data/CONTRIBUTING.md +2 -0
  7. data/Gemfile +5 -5
  8. data/NEWS.md +83 -2
  9. data/README.md +73 -43
  10. data/RELEASING.md +5 -12
  11. data/Rakefile +1 -1
  12. data/app/controllers/doorkeeper/application_controller.rb +3 -1
  13. data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
  14. data/app/controllers/doorkeeper/applications_controller.rb +3 -7
  15. data/app/controllers/doorkeeper/authorizations_controller.rb +1 -1
  16. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  17. data/app/controllers/doorkeeper/tokens_controller.rb +50 -14
  18. data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
  19. data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -2
  20. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  21. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  22. data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
  23. data/app/views/doorkeeper/authorized_applications/_delete_form.html.erb +1 -2
  24. data/app/views/layouts/doorkeeper/admin.html.erb +1 -1
  25. data/config/locales/en.yml +3 -2
  26. data/doorkeeper.gemspec +12 -10
  27. data/gemfiles/rails_4_2.gemfile +11 -0
  28. data/gemfiles/rails_5_0.gemfile +12 -0
  29. data/gemfiles/rails_5_1.gemfile +13 -0
  30. data/lib/doorkeeper/config.rb +73 -16
  31. data/lib/doorkeeper/engine.rb +11 -7
  32. data/lib/doorkeeper/errors.rb +18 -0
  33. data/lib/doorkeeper/grape/helpers.rb +2 -1
  34. data/lib/doorkeeper/helpers/controller.rb +8 -23
  35. data/lib/doorkeeper/models/access_grant_mixin.rb +21 -5
  36. data/lib/doorkeeper/models/access_token_mixin.rb +145 -23
  37. data/lib/doorkeeper/models/application_mixin.rb +21 -9
  38. data/lib/doorkeeper/models/concerns/accessible.rb +4 -0
  39. data/lib/doorkeeper/models/concerns/expirable.rb +10 -2
  40. data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
  41. data/lib/doorkeeper/models/concerns/revocable.rb +37 -2
  42. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +20 -18
  43. data/lib/doorkeeper/oauth/authorization_code_request.rb +1 -4
  44. data/lib/doorkeeper/oauth/{request_concern.rb → base_request.rb} +3 -1
  45. data/lib/doorkeeper/oauth/base_response.rb +29 -0
  46. data/lib/doorkeeper/oauth/client/credentials.rb +17 -6
  47. data/lib/doorkeeper/oauth/client.rb +0 -1
  48. data/lib/doorkeeper/oauth/client_credentials/creator.rb +1 -1
  49. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +3 -2
  50. data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -8
  52. data/lib/doorkeeper/oauth/code_response.rb +16 -16
  53. data/lib/doorkeeper/oauth/error_response.rb +9 -8
  54. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  55. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
  56. data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -0
  57. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -13
  58. data/lib/doorkeeper/oauth/refresh_token_request.rb +22 -14
  59. data/lib/doorkeeper/oauth/scopes.rb +2 -2
  60. data/lib/doorkeeper/oauth/token.rb +20 -21
  61. data/lib/doorkeeper/oauth/token_request.rb +1 -2
  62. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  63. data/lib/doorkeeper/orm/active_record/access_token.rb +25 -0
  64. data/lib/doorkeeper/orm/active_record/application.rb +12 -12
  65. data/lib/doorkeeper/orm/active_record.rb +0 -16
  66. data/lib/doorkeeper/rails/helpers.rb +1 -3
  67. data/lib/doorkeeper/rails/routes/mapper.rb +4 -4
  68. data/lib/doorkeeper/rails/routes/mapping.rb +1 -1
  69. data/lib/doorkeeper/rails/routes.rb +4 -4
  70. data/lib/doorkeeper/request/authorization_code.rb +7 -1
  71. data/lib/doorkeeper/request/password.rb +11 -1
  72. data/lib/doorkeeper/request/refresh_token.rb +1 -1
  73. data/lib/doorkeeper/server.rb +0 -8
  74. data/lib/doorkeeper/version.rb +1 -1
  75. data/lib/doorkeeper.rb +8 -2
  76. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
  77. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
  78. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
  79. data/lib/generators/doorkeeper/templates/initializer.rb +8 -3
  80. data/lib/generators/doorkeeper/templates/migration.rb +23 -5
  81. data/spec/controllers/application_metal_controller.rb +10 -0
  82. data/spec/controllers/authorizations_controller_spec.rb +39 -24
  83. data/spec/controllers/protected_resources_controller_spec.rb +47 -18
  84. data/spec/controllers/tokens_controller_spec.rb +1 -1
  85. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -4
  86. data/spec/dummy/app/controllers/home_controller.rb +1 -1
  87. data/spec/dummy/app/controllers/metal_controller.rb +1 -1
  88. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +3 -3
  89. data/spec/dummy/app/models/user.rb +0 -4
  90. data/spec/dummy/config/application.rb +2 -36
  91. data/spec/dummy/config/environment.rb +1 -1
  92. data/spec/dummy/config/environments/test.rb +4 -15
  93. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
  94. data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
  95. data/spec/dummy/db/migrate/{20130902165751_create_doorkeeper_tables.rb → 20151223192035_create_doorkeeper_tables.rb} +24 -5
  96. data/spec/dummy/db/migrate/{20130902175349_add_owner_to_application.rb → 20151223200000_add_owner_to_application.rb} +0 -0
  97. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
  98. data/spec/dummy/db/schema.rb +23 -22
  99. data/spec/factories.rb +3 -1
  100. data/spec/lib/config_spec.rb +19 -2
  101. data/spec/lib/doorkeeper_spec.rb +135 -13
  102. data/spec/lib/models/expirable_spec.rb +0 -1
  103. data/spec/lib/models/revocable_spec.rb +27 -4
  104. data/spec/lib/oauth/authorization/uri_builder_spec.rb +1 -2
  105. data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
  106. data/spec/lib/oauth/base_request_spec.rb +160 -0
  107. data/spec/lib/oauth/base_response_spec.rb +45 -0
  108. data/spec/lib/oauth/client/credentials_spec.rb +41 -0
  109. data/spec/lib/oauth/code_response_spec.rb +34 -0
  110. data/spec/lib/oauth/error_response_spec.rb +9 -9
  111. data/spec/lib/oauth/invalid_token_response_spec.rb +36 -8
  112. data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
  113. data/spec/lib/oauth/refresh_token_request_spec.rb +34 -3
  114. data/spec/lib/oauth/scopes_spec.rb +0 -1
  115. data/spec/lib/oauth/token_spec.rb +12 -5
  116. data/spec/lib/server_spec.rb +0 -3
  117. data/spec/models/doorkeeper/access_token_spec.rb +45 -1
  118. data/spec/models/doorkeeper/application_spec.rb +3 -11
  119. data/spec/requests/endpoints/authorization_spec.rb +5 -6
  120. data/spec/requests/flows/authorization_code_errors_spec.rb +11 -1
  121. data/spec/requests/flows/authorization_code_spec.rb +4 -12
  122. data/spec/requests/flows/password_spec.rb +26 -5
  123. data/spec/requests/flows/refresh_token_spec.rb +87 -17
  124. data/spec/requests/flows/revoke_token_spec.rb +100 -86
  125. data/spec/spec_helper.rb +2 -0
  126. data/spec/spec_helper_integration.rb +8 -1
  127. data/spec/support/helpers/model_helper.rb +27 -5
  128. data/spec/support/helpers/request_spec_helper.rb +12 -4
  129. data/spec/support/http_method_shim.rb +38 -0
  130. data/spec/support/shared/controllers_shared_context.rb +13 -4
  131. data/spec/support/shared/models_shared_examples.rb +1 -1
  132. metadata +72 -42
  133. data/lib/doorkeeper/oauth/client/methods.rb +0 -18
  134. data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
  135. data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
  136. data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +0 -5
  137. data/spec/lib/oauth/client/methods_spec.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03417189314de7b84fcfa05699c35a0346a55035
4
- data.tar.gz: e4026de8e9ed39d2bb270abc9efc4e1ccca20775
3
+ metadata.gz: b4b94e7f1fb4975a36ad84ccfda9bcfb0b5e2bd7
4
+ data.tar.gz: fc5914c689e55572a9313caa07f2644c29f37574
5
5
  SHA512:
6
- metadata.gz: bbe0a1693809bfc8802a66c50df30a128a527a3f239114ffdc69d46e948ac0516594fe3872f3624157632e91078a0ad64aa1f98932b26bdf389228b22bed246b
7
- data.tar.gz: 6d434e7dc34b65d1022914f8fd348c9d1c8e6ef41bb30761411eb0c693531ccb12c87c237c1e54fbcbee11a8dd0bf68c82768a6801f273dab2bcaf1fe96afea6
6
+ metadata.gz: f90cc508667ce0ec9693925a187fbc9ae5b9eeaf95b74648c9981ceea9eaef305d9981f75d48a8b8f0e00929bcc748a51da4b013b814ffa8a9344a4fc44257e1
7
+ data.tar.gz: 433cafea0488b8d0ab2d7d9b164b9510191f9a6d6534443674064e60c8ea2c0007494a9015b8c9d96a44b603182217496d4221db752c21d1cc5e56b1e377ae86
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -12,3 +12,8 @@ spec/generators/tmp
12
12
  .rvmrc
13
13
  *.swp
14
14
  .idea
15
+ /.yardoc/
16
+ /_yardoc/
17
+ /doc/
18
+ /rdoc/
19
+ coverage
data/.travis.yml CHANGED
@@ -3,20 +3,24 @@ language: ruby
3
3
  sudo: false
4
4
 
5
5
  rvm:
6
- - 2.0
7
6
  - 2.1
8
- - 2.2
9
- - jruby-head
7
+ - 2.2.6
8
+ - 2.3.3
9
+ - 2.4.0
10
10
 
11
- env:
12
- - rails=3.2.0
13
- - rails=4.1.0
14
- - rails=4.2.0
11
+ before_install:
12
+ - gem install bundler -v '~> 1.10'
13
+
14
+ gemfile:
15
+ - gemfiles/rails_4_2.gemfile
16
+ - gemfiles/rails_5_0.gemfile
17
+ - gemfiles/rails_5_1.gemfile
15
18
 
16
19
  matrix:
17
20
  exclude:
18
- - env: rails=3.2.0
19
- rvm: jruby-head
20
- exclude:
21
- - env: rails=3.2.0
22
- rvm: 2.2
21
+ - gemfile: gemfiles/rails_5_0.gemfile
22
+ rvm: 2.1
23
+ - gemfile: gemfiles/rails_5_1.gemfile
24
+ rvm: 2.1
25
+ allowed_failures:
26
+ - gemfile: gemfiles/rails_5_1.gemfile
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise "rails-4-2" do
2
+ gem "rails", "~> 4.2.0"
3
+ end
4
+
5
+ appraise "rails-5-0" do
6
+ gem "rails", "~> 5.0.0"
7
+ gem "rspec-rails", "~> 3.5"
8
+ end
9
+
10
+ appraise "rails-5-1" do
11
+ gem "rails", github: "rails/rails"
12
+ gem "arel", github: "rails/arel"
13
+ gem "rspec-rails", "~> 3.5"
14
+ end
data/CONTRIBUTING.md CHANGED
@@ -26,6 +26,8 @@ Make the tests pass:
26
26
 
27
27
  rake
28
28
 
29
+ Add notes on your change to the `NEWS.md` file.
30
+
29
31
  Write a [good commit message][commit].
30
32
  Push to your fork.
31
33
  [Submit a pull request][pr].
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
- ENV['rails'] ||= '4.2.0'
1
+ source "https://rubygems.org"
2
2
 
3
- source 'https://rubygems.org'
3
+ gem "rails", "~> 4.2.0"
4
4
 
5
- gem 'rails', "~> #{ENV['rails']}"
5
+ gem "appraisal"
6
6
 
7
- gem "sqlite3", platform: [:ruby, :mswin, :mingw]
8
7
  gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
9
-
8
+ gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
9
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
10
10
  gemspec
data/NEWS.md CHANGED
@@ -2,7 +2,88 @@
2
2
 
3
3
  User-visible changes worth mentioning.
4
4
 
5
- ---
5
+ ## master
6
+
7
+ - [#970] Escape certain attributes in authorization forms.
8
+
9
+ ## 4.2.5
10
+
11
+ - [#936] Deprecate `Doorkeeper#configured?`, `Doorkeeper#database_installed?`, and
12
+ `Doorkeeper#installed?`
13
+ - [#909] Add `InvalidTokenResponse#reason` reader method to allow read the kind
14
+ of invalid token error.
15
+ - [#928] Test against more recent Ruby versions
16
+ - Small refactorings within the codebase
17
+ - [#921] Switch to Appraisal, and test against Rails master
18
+ - [#892] Add minimum Ruby version requirement
19
+
20
+ ## 4.2.0
21
+
22
+ - Security fix: Address CVE-2016-6582, implement token revocation according to
23
+ spec (tokens might not be revoked if client follows the spec).
24
+ - [#873] Add hooks to Doorkeeper::ApplicationMetalController
25
+ - [#871] Allow downstream users to better utilize doorkeeper spec factories by
26
+ eliminating name conflict on `:user` factory.
27
+
28
+ ## 4.1.0
29
+
30
+ - [#845] Allow customising the `Doorkeeper::ApplicationController` base
31
+ controller
32
+
33
+ ## 4.0.0
34
+
35
+ - [#834] Fix AssetNotPrecompiled error with Sprockets 4
36
+ - [#843] Revert "Fix validation error messages"
37
+ - [#847] Specify Null option to timestamps
38
+
39
+ ## 4.0.0.rc4
40
+
41
+ - [#777] Add support for public client in password grant flow
42
+ - [#823] Make configuration and specs ORM independent
43
+ - [#745] Add created_at timestamp to token generation options
44
+ - [#838] Drop `Application#scopes` generator and warning, introduced for
45
+ upgrading doorkeeper from v2 to v3.
46
+ - [#801] Fix Rails 5 warning messages
47
+ - Test against Rails 5 RC1
48
+
49
+ ## 4.0.0.rc3
50
+
51
+ - [#769] Revoke refresh token on access token use. To make use of the new config
52
+ add `previous_refresh_token` column to `oauth_access_tokens`:
53
+
54
+ ```
55
+ rails generate doorkeeper:previous_refresh_token
56
+ ```
57
+ - [#811] Toughen parameters filter with exact match
58
+ - [#813] Applications admin bugfix
59
+ - [#799] Fix Ruby Warnings
60
+ - Drop `attr_accessible` from models
61
+
62
+ ### Backward incompatible changes
63
+
64
+ - [#730] Force all timezones to use UTC to prevent comparison issues.
65
+ - [#802] Remove `config.i18n.fallbacks` from engine
66
+
67
+ ## 4.0.0.rc2
68
+
69
+ - Fix optional belongs_to for Rails 5
70
+ - Fix Ruby warnings
71
+
72
+ ## 4.0.0.rc1
73
+
74
+ ### Backward incompatible changes
75
+
76
+ - Drops support for Rails 4.1 and earlier
77
+ - Drops support for Ruby 2.0
78
+ - [#778] Bug fix: use the remaining time that a token is still valid when
79
+ building the redirect URI for the implicit grant flow
80
+
81
+ ### Other changes
82
+
83
+ - [#771] Validation error messages fixes
84
+ - Adds foreign key constraints in generated migrations between tokens and
85
+ grants, and applications
86
+ - Support Rails 5
6
87
 
7
88
  ## 3.1.0
8
89
 
@@ -67,7 +148,7 @@ User-visible changes worth mentioning.
67
148
  - Remove `applications.scopes` upgrade notice.
68
149
 
69
150
 
70
- ## 2.2.2 (unreleased)
151
+ ## 2.2.2
71
152
 
72
153
  - [#541] Fixed `undefined method attr_accessible` problem on Rails 4
73
154
  (happens only when ProtectedAttributes gem is used) in #599
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
- # Doorkeeper - awesome oauth provider for your Rails app.
1
+ # Doorkeeper - awesome OAuth2 provider for your Rails app.
2
2
 
3
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)
4
+ [![Dependency Status](https://gemnasium.com/doorkeeper-gem/doorkeeper.svg?travis)](https://gemnasium.com/doorkeeper-gem/doorkeeper)
5
+ [![Code Climate](https://codeclimate.com/github/doorkeeper-gem/doorkeeper.svg)](https://codeclimate.com/github/doorkeeper-gem/doorkeeper)
6
6
  [![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
7
+ [![Security](https://hakiri.io/github/doorkeeper-gem/doorkeeper/master.svg)](https://hakiri.io/github/doorkeeper-gem/doorkeeper/master)
7
8
 
8
9
  Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider
9
10
  functionality to your Rails or Grape application.
@@ -16,43 +17,41 @@ functionality to your Rails or Grape application.
16
17
  Please check the documentation for the version of doorkeeper you are using in:
17
18
  https://github.com/doorkeeper-gem/doorkeeper/releases
18
19
 
20
+ - See the [wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
21
+ - For general questions, please post in [Stack Overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
22
+
19
23
  ## Table of Contents
20
24
 
21
25
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
22
26
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
23
- - [Useful links](#useful-links)
27
+
24
28
  - [Installation](#installation)
25
29
  - [Configuration](#configuration)
26
- - [Active Record](#active-record)
27
- - [Other ORMs](#other-orms)
28
- - [Routes](#routes)
29
- - [Authenticating](#authenticating)
30
- - [Internationalization (I18n)](#internationalization-i18n)
30
+ - [Active Record](#active-record)
31
+ - [Other ORMs](#other-orms)
32
+ - [Routes](#routes)
33
+ - [Authenticating](#authenticating)
34
+ - [Internationalization (I18n)](#internationalization-i18n)
31
35
  - [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
32
- - [Protect your API with OAuth when using Grape](#protect-your-api-with-oauth-when-using-grape)
33
- - [Route Constraints and other integrations](#route-constraints-and-other-integrations)
34
- - [Access Token Scopes](#access-token-scopes)
35
- - [Custom Access Token Generator](#custom-access-token-generator)
36
- - [Authenticated resource owner](#authenticated-resource-owner)
37
- - [Applications list](#applications-list)
36
+ - [Protect your API with OAuth when using Grape](#protect-your-api-with-oauth-when-using-grape)
37
+ - [Route Constraints and other integrations](#route-constraints-and-other-integrations)
38
+ - [Access Token Scopes](#access-token-scopes)
39
+ - [Custom Access Token Generator](#custom-access-token-generator)
40
+ - [Authenticated resource owner](#authenticated-resource-owner)
41
+ - [Applications list](#applications-list)
38
42
  - [Other customizations](#other-customizations)
39
43
  - [Upgrading](#upgrading)
40
44
  - [Development](#development)
41
45
  - [Contributing](#contributing)
42
46
  - [Other resources](#other-resources)
43
- - [Wiki](#wiki)
44
- - [Screencast](#screencast)
45
- - [Client applications](#client-applications)
46
- - [Contributors](#contributors)
47
- - [IETF Standards](#ietf-standards)
48
- - [License](#license)
49
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
47
+ - [Wiki](#wiki)
48
+ - [Screencast](#screencast)
49
+ - [Client applications](#client-applications)
50
+ - [Contributors](#contributors)
51
+ - [IETF Standards](#ietf-standards)
52
+ - [License](#license)
50
53
 
51
-
52
- ## Useful links
53
-
54
- - For documentation, please check out our [wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
55
- - For general questions, please post it in [stack overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
54
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
56
55
 
57
56
  ## Installation
58
57
 
@@ -77,17 +76,33 @@ to generate the migration tables:
77
76
 
78
77
  rails generate doorkeeper:migration
79
78
 
80
- Don't forget to run the migration with:
79
+ You may want to add foreign keys to your migration. For example, if you plan on
80
+ using `User` as the resource owner, add the following line to the migration file
81
+ for each table that includes a `resource_owner_id` column:
81
82
 
82
- rake db:migrate
83
+ ```ruby
84
+ add_foreign_key :table_name, :users, column: :resource_owner_id
85
+ ```
86
+
87
+ Then run migrations:
88
+
89
+ ```sh
90
+ rake db:migrate
91
+ ```
83
92
 
84
93
  ### Other ORMs
85
94
 
86
- See [doorkeeper-mongodb project] for mongoid and mongomapper support. Follow along
95
+ See [doorkeeper-mongodb project] for Mongoid and MongoMapper support. Follow along
87
96
  the implementation in that repository to extend doorkeeper with other ORMs.
88
97
 
89
98
  [doorkeeper-mongodb project]: https://github.com/doorkeeper-gem/doorkeeper-mongodb
90
99
 
100
+ If you are using [Sequel gem] then you can add [doorkeeper-sequel extension] to your project.
101
+ Follow configuration instructions for setting up the necessary Doorkeeper ORM.
102
+
103
+ [Sequel gem]: https://github.com/jeremyevans/sequel/
104
+ [doorkeeper-sequel extension]: https://github.com/nbulaj/doorkeeper-sequel
105
+
91
106
  ### Routes
92
107
 
93
108
  The installation script will also automatically add the Doorkeeper routes into
@@ -119,7 +134,7 @@ wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
119
134
  ### Authenticating
120
135
 
121
136
  You need to configure Doorkeeper in order to provide `resource_owner` model
122
- and authentication block `initializers/doorkeeper.rb`
137
+ and authentication block in `config/initializers/doorkeeper.rb`:
123
138
 
124
139
  ``` ruby
125
140
  Doorkeeper.configure do
@@ -161,7 +176,7 @@ You can pass any option `before_action` accepts, such as `if`, `only`,
161
176
 
162
177
  ### Protect your API with OAuth when using Grape
163
178
 
164
- As of [PR 567] doorkeeper has helpers for Grape. One of them is
179
+ As of [PR 567] doorkeeper has helpers for Grape >= 0.10. One of them is
165
180
  `doorkeeper_authorize!` and can be used in a similar way as an example above.
166
181
  Note that you have to use `require 'doorkeeper/grape/helpers'` and
167
182
  `helpers Doorkeeper::Grape::Helpers`.
@@ -183,6 +198,11 @@ module API
183
198
  doorkeeper_authorize!
184
199
  end
185
200
 
201
+ route_setting :scopes, ['user:email']
202
+ get :emails do
203
+ [{'email' => current_user.email}]
204
+ end
205
+
186
206
  # ...
187
207
  end
188
208
  end
@@ -238,13 +258,13 @@ class Api::V1::ProductsController < Api::V1::ApiController
238
258
  end
239
259
  ```
240
260
 
241
- Please note that there is a logical OR between multiple required scopes. In
261
+ Please note that there is a logical OR between multiple required scopes. In the
242
262
  above example, `doorkeeper_authorize! :admin, :write` means that the access
243
- token is required to have either `:admin` scope or `:write` scope, but not need
244
- have both of them.
263
+ token is required to have either `:admin` scope or `:write` scope, but does not
264
+ need have both of them.
245
265
 
246
- If want to require the access token to have multiple scopes at the same time,
247
- use multiple `doorkeeper_authorize!`, for example:
266
+ If you want to require the access token to have multiple scopes at the same
267
+ time, use multiple `doorkeeper_authorize!`, for example:
248
268
 
249
269
  ```ruby
250
270
  class Api::V1::ProductsController < Api::V1::ApiController
@@ -256,8 +276,8 @@ class Api::V1::ProductsController < Api::V1::ApiController
256
276
  end
257
277
  ```
258
278
 
259
- In above example, a client can call `:create` action only if its access token
260
- have both `:admin` and `:write` scopes.
279
+ In the above example, a client can call `:create` action only if its access token
280
+ has both `:admin` and `:write` scopes.
261
281
 
262
282
  ### Custom Access Token Generator
263
283
 
@@ -274,6 +294,16 @@ end
274
294
  JWT token support is available with
275
295
  [Doorkeeper-JWT](https://github.com/chriswarren/doorkeeper-jwt).
276
296
 
297
+ ### Custom Base Controller
298
+
299
+ By default Doorkeeper's main controller `Doorkeeper::ApplicationController` inherits from `ActionController::Base`.
300
+ You may want to use your own controller to inherit from, to keep Doorkeeper controllers in the same context than the rest your app:
301
+
302
+ ```ruby
303
+ Doorkeeper.configure do
304
+ base_controller 'ApplicationController'
305
+ end
306
+ ```
277
307
 
278
308
  ### Authenticated resource owner
279
309
 
@@ -305,7 +335,7 @@ token owner.
305
335
 
306
336
  ### Applications list
307
337
 
308
- By default, the applications list (`/oauth/applications`) is public available.
338
+ By default, the applications list (`/oauth/applications`) is publicly available.
309
339
  To protect the endpoint you should uncomment these lines:
310
340
 
311
341
  ```ruby
@@ -319,9 +349,9 @@ end
319
349
 
320
350
  The logic is the same as the `resource_owner_authenticator` block. **Note:**
321
351
  since the application list is just a scaffold, it's recommended to either
322
- customize the controller used by the list or skip the controller at all. For
323
- more information see the page [in the
324
- wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
352
+ customize the controller used by the list or skip the controller all together.
353
+ For more information see the page
354
+ [in the wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
325
355
 
326
356
  ## Other customizations
327
357
 
data/RELEASING.md CHANGED
@@ -1,17 +1,10 @@
1
1
  # Releasing doorkeeper
2
2
 
3
+ How to release doorkeeper in five easy steps!
4
+
3
5
  1. Update `lib/doorkeeper/version.rb` file accordingly.
4
6
  2. Update `NEWS.md` to reflect the changes since last release.
5
- 3. Commit changes. There shouldn’t be code changes, and thus CI doesn’t need to
6
- run, you can then add “[ci skip]” to the commit message.
7
- 4. Tag the release: `git tag vVERSION -m "Release vVERSION"`
8
- 5. Push changes: `git push && git push --tags`
9
- 6. Build and publish the gem:
10
-
11
- ```bash
12
- gem build doorkeeper.gemspec
13
- gem push doorkeeper-*.gem
14
- ```
15
-
16
- 7. Announce the new release, making sure to say “thank you” to the contributors
7
+ 3. Commit changes: `git commit -am 'Bump to vVERSION'`
8
+ 4. Run `rake release`
9
+ 5. Announce the new release, making sure to say “thank you” to the contributors
17
10
  who helped shape this version!
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'bundler/setup'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  desc 'Default: run specs.'
5
- task :default => :spec
5
+ task default: :spec
6
6
 
7
7
  desc "Run all specs"
8
8
  RSpec::Core::RakeTask.new(:spec) do |config|
@@ -1,5 +1,7 @@
1
1
  module Doorkeeper
2
- class ApplicationController < ActionController::Base
2
+ class ApplicationController <
3
+ Doorkeeper.configuration.base_controller.constantize
4
+
3
5
  include Helpers::Controller
4
6
 
5
7
  if ::Rails.version.to_i < 4
@@ -1,16 +1,17 @@
1
1
  module Doorkeeper
2
2
  class ApplicationMetalController < ActionController::Metal
3
3
  MODULES = [
4
- ActionController::RackDelegation,
5
4
  ActionController::Instrumentation,
6
5
  AbstractController::Rendering,
7
6
  ActionController::Rendering,
8
7
  ActionController::Renderers::All,
9
8
  Helpers::Controller
10
- ]
9
+ ].freeze
11
10
 
12
11
  MODULES.each do |mod|
13
12
  include mod
14
13
  end
14
+
15
+ ActiveSupport.run_load_hooks(:doorkeeper_metal_controller, self)
15
16
  end
16
17
  end
@@ -2,8 +2,8 @@ module Doorkeeper
2
2
  class ApplicationsController < Doorkeeper::ApplicationController
3
3
  layout 'doorkeeper/admin'
4
4
 
5
- before_filter :authenticate_admin!
6
- before_filter :set_application, only: [:show, :edit, :update, :destroy]
5
+ before_action :authenticate_admin!
6
+ before_action :set_application, only: [:show, :edit, :update, :destroy]
7
7
 
8
8
  def index
9
9
  @applications = Application.all
@@ -44,11 +44,7 @@ module Doorkeeper
44
44
  end
45
45
 
46
46
  def application_params
47
- if params.respond_to?(:permit)
48
- params.require(:doorkeeper_application).permit(:name, :redirect_uri, :scopes)
49
- else
50
- params[:doorkeeper_application].slice(:name, :redirect_uri, :scopes) rescue nil
51
- end
47
+ params.require(:doorkeeper_application).permit(:name, :redirect_uri, :scopes)
52
48
  end
53
49
  end
54
50
  end
@@ -1,6 +1,6 @@
1
1
  module Doorkeeper
2
2
  class AuthorizationsController < Doorkeeper::ApplicationController
3
- before_filter :authenticate_resource_owner!
3
+ before_action :authenticate_resource_owner!
4
4
 
5
5
  def new
6
6
  if pre_auth.authorizable?
@@ -1,6 +1,6 @@
1
1
  module Doorkeeper
2
2
  class AuthorizedApplicationsController < Doorkeeper::ApplicationController
3
- before_filter :authenticate_resource_owner!
3
+ before_action :authenticate_resource_owner!
4
4
 
5
5
  def index
6
6
  @applications = Application.authorized_for(current_resource_owner)
@@ -2,7 +2,7 @@ module Doorkeeper
2
2
  class TokensController < Doorkeeper::ApplicationMetalController
3
3
  def create
4
4
  response = authorize_response
5
- self.headers.merge! response.headers
5
+ headers.merge! response.headers
6
6
  self.response_body = response.body.to_json
7
7
  self.status = response.status
8
8
  rescue Errors::DoorkeeperError => e
@@ -11,29 +11,65 @@ module Doorkeeper
11
11
 
12
12
  # OAuth 2.0 Token Revocation - http://tools.ietf.org/html/rfc7009
13
13
  def revoke
14
- # The authorization server first validates the client credentials
15
- if doorkeeper_token && doorkeeper_token.accessible?
16
- # Doorkeeper does not use the token_type_hint logic described in the RFC 7009
17
- # due to the refresh token implementation that is a field in the access token model.
18
- revoke_token(request.POST['token']) if request.POST['token']
14
+ # The authorization server, if applicable, first authenticates the client
15
+ # and checks its ownership of the provided token.
16
+ #
17
+ # Doorkeeper does not use the token_type_hint logic described in the
18
+ # RFC 7009 due to the refresh token implementation that is a field in
19
+ # the access token model.
20
+ if authorized?
21
+ revoke_token
19
22
  end
20
- # The authorization server responds with HTTP status code 200 if the
21
- # token has been revoked successfully or if the client submitted an invalid token
23
+
24
+ # The authorization server responds with HTTP status code 200 if the token
25
+ # has been revoked successfully or if the client submitted an invalid
26
+ # token
22
27
  render json: {}, status: 200
23
28
  end
24
29
 
25
30
  private
26
31
 
27
- def revoke_token(token)
28
- token = AccessToken.by_token(token) || AccessToken.by_refresh_token(token)
29
- if token && doorkeeper_token.same_credential?(token)
32
+ # OAuth 2.0 Section 2.1 defines two client types, "public" & "confidential".
33
+ # Public clients (as per RFC 7009) do not require authentication whereas
34
+ # confidential clients must be authenticated for their token revocation.
35
+ #
36
+ # Once a confidential client is authenticated, it must be authorized to
37
+ # revoke the provided access or refresh token. This ensures one client
38
+ # cannot revoke another's tokens.
39
+ #
40
+ # Doorkeeper determines the client type implicitly via the presence of the
41
+ # OAuth client associated with a given access or refresh token. Since public
42
+ # clients authenticate the resource owner via "password" or "implicit" grant
43
+ # types, they set the application_id as null (since the claim cannot be
44
+ # verified).
45
+ #
46
+ # https://tools.ietf.org/html/rfc6749#section-2.1
47
+ # https://tools.ietf.org/html/rfc7009
48
+ def authorized?
49
+ if token.present?
50
+ # Client is confidential, therefore client authentication & authorization
51
+ # is required
52
+ if token.application_id?
53
+ # We authorize client by checking token's application
54
+ server.client && server.client.application == token.application
55
+ else
56
+ # Client is public, authentication unnecessary
57
+ true
58
+ end
59
+ end
60
+ end
61
+
62
+ def revoke_token
63
+ if token.accessible?
30
64
  token.revoke
31
- true
32
- else
33
- false
34
65
  end
35
66
  end
36
67
 
68
+ def token
69
+ @token ||= AccessToken.by_token(request.POST['token']) ||
70
+ AccessToken.by_refresh_token(request.POST['token'])
71
+ end
72
+
37
73
  def strategy
38
74
  @strategy ||= server.token_request params[:grant_type]
39
75
  end
@@ -1,15 +1,17 @@
1
- module Doorkeeper::DashboardHelper
2
- def doorkeeper_errors_for(object, method)
3
- if object.errors[method].present?
4
- object.errors[method].map do |msg|
5
- content_tag(:span, class: 'help-block') do
6
- msg.capitalize
7
- end
8
- end.join.html_safe
1
+ module Doorkeeper
2
+ module DashboardHelper
3
+ def doorkeeper_errors_for(object, method)
4
+ if object.errors[method].present?
5
+ object.errors[method].map do |msg|
6
+ content_tag(:span, class: 'help-block') do
7
+ msg.capitalize
8
+ end
9
+ end.join.html_safe
10
+ end
9
11
  end
10
- end
11
12
 
12
- def doorkeeper_submit_path(application)
13
- application.persisted? ? oauth_application_path(application) : oauth_applications_path
13
+ def doorkeeper_submit_path(application)
14
+ application.persisted? ? oauth_application_path(application) : oauth_applications_path
15
+ end
14
16
  end
15
17
  end
@@ -1,5 +1,4 @@
1
1
  <%- submit_btn_css ||= 'btn btn-link' %>
2
- <%= form_tag oauth_application_path(application) do %>
3
- <input type="hidden" name="_method" value="delete">
2
+ <%= form_tag oauth_application_path(application), method: :delete do %>
4
3
  <%= submit_tag t('doorkeeper.applications.buttons.destroy'), onclick: "return confirm('#{ t('doorkeeper.applications.confirmations.destroy') }')", class: submit_btn_css %>
5
4
  <% end %>
@@ -21,7 +21,7 @@
21
21
  </span>
22
22
  <% if Doorkeeper.configuration.native_redirect_uri %>
23
23
  <span class="help-block">
24
- <%= raw t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: "<code>#{ Doorkeeper.configuration.native_redirect_uri }</code>") %>
24
+ <%= raw t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: content_tag(:code) { Doorkeeper.configuration.native_redirect_uri }) %>
25
25
  </span>
26
26
  <% end %>
27
27
  </div>