doorkeeper 5.0.3 → 5.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.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -1
  3. data/.rubocop.yml +37 -4
  4. data/.travis.yml +11 -21
  5. data/Appraisals +29 -7
  6. data/Dangerfile +5 -2
  7. data/Gemfile +19 -5
  8. data/NEWS.md +81 -21
  9. data/README.md +75 -485
  10. data/Rakefile +10 -8
  11. data/app/controllers/doorkeeper/application_controller.rb +1 -2
  12. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -13
  13. data/app/controllers/doorkeeper/applications_controller.rb +20 -8
  14. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  15. data/app/controllers/doorkeeper/token_info_controller.rb +2 -2
  16. data/app/controllers/doorkeeper/tokens_controller.rb +11 -11
  17. data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
  18. data/app/validators/redirect_uri_validator.rb +5 -2
  19. data/app/views/doorkeeper/applications/_form.html.erb +6 -0
  20. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  21. data/app/views/layouts/doorkeeper/admin.html.erb +5 -3
  22. data/bin/console +16 -0
  23. data/config/locales/en.yml +1 -0
  24. data/doorkeeper.gemspec +24 -21
  25. data/gemfiles/rails_5_0.gemfile +9 -4
  26. data/gemfiles/rails_5_1.gemfile +9 -4
  27. data/gemfiles/rails_5_2.gemfile +10 -5
  28. data/gemfiles/rails_6_0.gemfile +17 -0
  29. data/gemfiles/rails_master.gemfile +9 -9
  30. data/lib/doorkeeper/config/option.rb +64 -0
  31. data/lib/doorkeeper/config.rb +191 -75
  32. data/lib/doorkeeper/engine.rb +1 -1
  33. data/lib/doorkeeper/grape/authorization_decorator.rb +4 -4
  34. data/lib/doorkeeper/grape/helpers.rb +3 -3
  35. data/lib/doorkeeper/helpers/controller.rb +3 -2
  36. data/lib/doorkeeper/models/access_grant_mixin.rb +20 -3
  37. data/lib/doorkeeper/models/access_token_mixin.rb +63 -19
  38. data/lib/doorkeeper/models/application_mixin.rb +43 -1
  39. data/lib/doorkeeper/models/concerns/expirable.rb +4 -2
  40. data/lib/doorkeeper/models/concerns/ownership.rb +1 -6
  41. data/lib/doorkeeper/models/concerns/reusable.rb +19 -0
  42. data/lib/doorkeeper/models/concerns/revocable.rb +2 -1
  43. data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
  44. data/lib/doorkeeper/models/concerns/secret_storable.rb +108 -0
  45. data/lib/doorkeeper/oauth/authorization/code.rb +2 -2
  46. data/lib/doorkeeper/oauth/authorization/token.rb +12 -7
  47. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
  48. data/lib/doorkeeper/oauth/authorization_code_request.rb +6 -4
  49. data/lib/doorkeeper/oauth/client.rb +1 -1
  50. data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -4
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
  52. data/lib/doorkeeper/oauth/code_response.rb +2 -2
  53. data/lib/doorkeeper/oauth/error_response.rb +10 -6
  54. data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
  55. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +23 -8
  56. data/lib/doorkeeper/oauth/helpers/unique_token.rb +13 -1
  57. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +37 -1
  58. data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -1
  59. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -2
  60. data/lib/doorkeeper/oauth/pre_authorization.rb +11 -5
  61. data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -2
  62. data/lib/doorkeeper/oauth/scopes.rb +5 -3
  63. data/lib/doorkeeper/oauth/token.rb +2 -2
  64. data/lib/doorkeeper/oauth/token_introspection.rb +74 -8
  65. data/lib/doorkeeper/oauth/token_response.rb +9 -9
  66. data/lib/doorkeeper/oauth.rb +5 -5
  67. data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -13
  68. data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
  69. data/lib/doorkeeper/orm/active_record/application.rb +21 -57
  70. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
  71. data/lib/doorkeeper/orm/active_record.rb +6 -6
  72. data/lib/doorkeeper/rails/helpers.rb +1 -1
  73. data/lib/doorkeeper/rails/routes/mapping.rb +7 -7
  74. data/lib/doorkeeper/rails/routes.rb +11 -11
  75. data/lib/doorkeeper/rake/db.rake +13 -13
  76. data/lib/doorkeeper/rake.rb +1 -1
  77. data/lib/doorkeeper/request.rb +1 -1
  78. data/lib/doorkeeper/secret_storing/base.rb +64 -0
  79. data/lib/doorkeeper/secret_storing/bcrypt.rb +60 -0
  80. data/lib/doorkeeper/secret_storing/plain.rb +33 -0
  81. data/lib/doorkeeper/secret_storing/sha256_hash.rb +26 -0
  82. data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
  83. data/lib/doorkeeper/version.rb +3 -3
  84. data/lib/doorkeeper.rb +69 -60
  85. data/lib/generators/doorkeeper/application_owner_generator.rb +10 -9
  86. data/lib/generators/doorkeeper/confidential_applications_generator.rb +10 -9
  87. data/lib/generators/doorkeeper/install_generator.rb +11 -9
  88. data/lib/generators/doorkeeper/migration_generator.rb +9 -9
  89. data/lib/generators/doorkeeper/pkce_generator.rb +10 -9
  90. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +10 -9
  91. data/lib/generators/doorkeeper/templates/initializer.rb +120 -13
  92. data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -7
  93. data/lib/generators/doorkeeper/views_generator.rb +6 -4
  94. data/spec/controllers/application_metal_controller_spec.rb +24 -10
  95. data/spec/controllers/applications_controller_spec.rb +54 -52
  96. data/spec/controllers/authorizations_controller_spec.rb +139 -145
  97. data/spec/controllers/protected_resources_controller_spec.rb +78 -76
  98. data/spec/controllers/token_info_controller_spec.rb +14 -12
  99. data/spec/controllers/tokens_controller_spec.rb +167 -108
  100. data/spec/dummy/Rakefile +3 -1
  101. data/spec/dummy/app/controllers/application_controller.rb +3 -1
  102. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -0
  103. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -2
  104. data/spec/dummy/app/controllers/home_controller.rb +5 -3
  105. data/spec/dummy/app/controllers/metal_controller.rb +2 -0
  106. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +4 -2
  107. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  108. data/spec/dummy/app/models/user.rb +2 -0
  109. data/spec/dummy/config/application.rb +25 -1
  110. data/spec/dummy/config/environments/development.rb +2 -0
  111. data/spec/dummy/config/environments/production.rb +2 -0
  112. data/spec/dummy/config/environments/test.rb +3 -1
  113. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  114. data/spec/dummy/config/initializers/doorkeeper.rb +5 -2
  115. data/spec/dummy/config/initializers/secret_token.rb +3 -1
  116. data/spec/dummy/config/initializers/session_store.rb +3 -1
  117. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  118. data/spec/dummy/config.ru +3 -1
  119. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +17 -10
  120. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +2 -0
  121. data/spec/dummy/db/schema.rb +1 -1
  122. data/spec/dummy/script/rails +5 -3
  123. data/spec/factories.rb +8 -6
  124. data/spec/generators/application_owner_generator_spec.rb +13 -26
  125. data/spec/generators/confidential_applications_generator_spec.rb +12 -28
  126. data/spec/generators/install_generator_spec.rb +17 -15
  127. data/spec/generators/migration_generator_spec.rb +13 -26
  128. data/spec/generators/pkce_generator_spec.rb +11 -26
  129. data/spec/generators/previous_refresh_token_generator_spec.rb +16 -29
  130. data/spec/generators/templates/routes.rb +2 -0
  131. data/spec/generators/views_generator_spec.rb +14 -12
  132. data/spec/grape/grape_integration_spec.rb +34 -32
  133. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +9 -7
  134. data/spec/lib/config_spec.rb +268 -99
  135. data/spec/lib/doorkeeper_spec.rb +3 -1
  136. data/spec/lib/models/expirable_spec.rb +22 -8
  137. data/spec/lib/models/reusable_spec.rb +40 -0
  138. data/spec/lib/models/revocable_spec.rb +8 -6
  139. data/spec/lib/models/scopes_spec.rb +27 -13
  140. data/spec/lib/models/secret_storable_spec.rb +135 -0
  141. data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
  142. data/spec/lib/oauth/authorization_code_request_spec.rb +34 -11
  143. data/spec/lib/oauth/base_request_spec.rb +20 -8
  144. data/spec/lib/oauth/base_response_spec.rb +3 -1
  145. data/spec/lib/oauth/client/credentials_spec.rb +24 -22
  146. data/spec/lib/oauth/client_credentials/creator_spec.rb +56 -10
  147. data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -18
  148. data/spec/lib/oauth/client_credentials/validation_spec.rb +20 -15
  149. data/spec/lib/oauth/client_credentials_integration_spec.rb +7 -5
  150. data/spec/lib/oauth/client_credentials_request_spec.rb +27 -21
  151. data/spec/lib/oauth/client_spec.rb +15 -13
  152. data/spec/lib/oauth/code_request_spec.rb +8 -6
  153. data/spec/lib/oauth/code_response_spec.rb +9 -7
  154. data/spec/lib/oauth/error_response_spec.rb +19 -11
  155. data/spec/lib/oauth/error_spec.rb +4 -2
  156. data/spec/lib/oauth/forbidden_token_response_spec.rb +7 -5
  157. data/spec/lib/oauth/helpers/scope_checker_spec.rb +68 -31
  158. data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
  159. data/spec/lib/oauth/helpers/uri_checker_spec.rb +115 -95
  160. data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
  161. data/spec/lib/oauth/password_access_token_request_spec.rb +79 -30
  162. data/spec/lib/oauth/pre_authorization_spec.rb +80 -54
  163. data/spec/lib/oauth/refresh_token_request_spec.rb +36 -33
  164. data/spec/lib/oauth/scopes_spec.rb +63 -61
  165. data/spec/lib/oauth/token_request_spec.rb +79 -24
  166. data/spec/lib/oauth/token_response_spec.rb +40 -38
  167. data/spec/lib/oauth/token_spec.rb +60 -44
  168. data/spec/lib/request/strategy_spec.rb +3 -1
  169. data/spec/lib/secret_storing/base_spec.rb +60 -0
  170. data/spec/lib/secret_storing/bcrypt_spec.rb +49 -0
  171. data/spec/lib/secret_storing/plain_spec.rb +44 -0
  172. data/spec/lib/secret_storing/sha256_hash_spec.rb +48 -0
  173. data/spec/lib/server_spec.rb +16 -14
  174. data/spec/lib/stale_records_cleaner_spec.rb +17 -17
  175. data/spec/models/doorkeeper/access_grant_spec.rb +80 -15
  176. data/spec/models/doorkeeper/access_token_spec.rb +198 -73
  177. data/spec/models/doorkeeper/application_spec.rb +280 -288
  178. data/spec/requests/applications/applications_request_spec.rb +98 -66
  179. data/spec/requests/applications/authorized_applications_spec.rb +20 -18
  180. data/spec/requests/endpoints/authorization_spec.rb +25 -23
  181. data/spec/requests/endpoints/token_spec.rb +38 -36
  182. data/spec/requests/flows/authorization_code_errors_spec.rb +26 -24
  183. data/spec/requests/flows/authorization_code_spec.rb +193 -151
  184. data/spec/requests/flows/client_credentials_spec.rb +54 -52
  185. data/spec/requests/flows/implicit_grant_errors_spec.rb +10 -8
  186. data/spec/requests/flows/implicit_grant_spec.rb +27 -25
  187. data/spec/requests/flows/password_spec.rb +59 -55
  188. data/spec/requests/flows/refresh_token_spec.rb +45 -43
  189. data/spec/requests/flows/revoke_token_spec.rb +40 -54
  190. data/spec/requests/flows/skip_authorization_spec.rb +23 -21
  191. data/spec/requests/protected_resources/metal_spec.rb +7 -5
  192. data/spec/requests/protected_resources/private_api_spec.rb +35 -33
  193. data/spec/routing/custom_controller_routes_spec.rb +71 -65
  194. data/spec/routing/default_routes_spec.rb +22 -20
  195. data/spec/routing/scoped_routes_spec.rb +20 -18
  196. data/spec/spec_helper.rb +15 -13
  197. data/spec/spec_helper_integration.rb +3 -1
  198. data/spec/support/dependencies/factory_bot.rb +3 -1
  199. data/spec/support/doorkeeper_rspec.rb +3 -1
  200. data/spec/support/helpers/access_token_request_helper.rb +3 -1
  201. data/spec/support/helpers/authorization_request_helper.rb +4 -2
  202. data/spec/support/helpers/config_helper.rb +2 -0
  203. data/spec/support/helpers/model_helper.rb +3 -1
  204. data/spec/support/helpers/request_spec_helper.rb +5 -3
  205. data/spec/support/helpers/url_helper.rb +9 -7
  206. data/spec/support/http_method_shim.rb +4 -9
  207. data/spec/support/orm/active_record.rb +3 -1
  208. data/spec/support/shared/controllers_shared_context.rb +18 -16
  209. data/spec/support/shared/hashing_shared_context.rb +36 -0
  210. data/spec/support/shared/models_shared_examples.rb +12 -10
  211. data/spec/validators/redirect_uri_validator_spec.rb +74 -45
  212. data/spec/version/version_spec.rb +7 -5
  213. metadata +60 -26
  214. data/gemfiles/rails_4_2.gemfile +0 -13
  215. data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -8
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
  [![Coverage Status](https://coveralls.io/repos/github/doorkeeper-gem/doorkeeper/badge.svg?branch=master)](https://coveralls.io/github/doorkeeper-gem/doorkeeper?branch=master)
7
7
  [![Security](https://hakiri.io/github/doorkeeper-gem/doorkeeper/master.svg)](https://hakiri.io/github/doorkeeper-gem/doorkeeper/master)
8
8
  [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
9
+ [![GuardRails badge](https://badges.production.guardrails.io/doorkeeper-gem/doorkeeper.svg?token=66768ce8f6995814df81f65a2cff40f739f688492704f973e62809e15599bb62)](https://dashboard.guardrails.io/default/gh/doorkeeper-gem/doorkeeper)
10
+ [![Dependabot](https://img.shields.io/badge/dependabot-enabled-success.svg)](https://dependabot.com)
9
11
 
10
12
  Doorkeeper is a gem (Rails engine) that makes it easy to introduce OAuth 2 provider
11
13
  functionality to your Ruby on Rails or Grape application.
@@ -22,504 +24,117 @@ Supported features:
22
24
  - [Proof Key for Code Exchange](https://tools.ietf.org/html/rfc7636)
23
25
  - [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
24
26
  - [OAuth 2.0 Token Introspection](https://tools.ietf.org/html/rfc7662)
25
-
26
- See [list of tutorials](https://github.com/doorkeeper-gem/doorkeeper/wiki#how-tos--tutorials) in order to
27
- learn how to use the gem or integrate it with other solutions / gems.
28
-
29
- ## Documentation valid for `master` branch
30
-
31
- Please check the documentation for the version of doorkeeper you are using in:
32
- https://github.com/doorkeeper-gem/doorkeeper/releases
33
-
34
- - See the [Wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
35
- - See [upgrade guides](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions)
36
- - For general questions, please post in [Stack Overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
37
- - See [SECURITY.md](SECURITY.md) for this project's security disclose
38
- policy
27
+ - [OAuth 2.0 Threat Model and Security Considerations](http://tools.ietf.org/html/rfc6819)
39
28
 
40
29
  ## Table of Contents
41
30
 
42
31
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
43
32
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
44
33
 
34
+
35
+ - [Documentation](#documentation)
45
36
  - [Installation](#installation)
46
- - [Configuration](#configuration)
47
- - [ORM](#orm)
48
- - [Active Record](#active-record)
49
- - [MongoDB](#mongodb)
50
- - [Sequel](#sequel)
51
- - [Couchbase](#couchbase)
52
- - [API mode](#api-mode)
53
- - [Routes](#routes)
54
- - [Authenticating](#authenticating)
55
- - [Internationalization (I18n)](#internationalization-i18n)
56
- - [Customizing errors](#customizing-errors)
57
- - [Rake Tasks](#rake-tasks)
58
- - [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
59
- - [Ruby on Rails controllers](#ruby-on-rails-controllers)
60
- - [Grape endpoints](#grape-endpoints)
61
- - [Route Constraints and other integrations](#route-constraints-and-other-integrations)
62
- - [Access Token Scopes](#access-token-scopes)
63
- - [Custom Access Token Generator](#custom-access-token-generator)
64
- - [Authenticated resource owner](#authenticated-resource-owner)
65
- - [Applications list](#applications-list)
66
- - [Other customizations](#other-customizations)
67
- - [Testing](#testing)
68
- - [Upgrading](#upgrading)
37
+ - [Ruby on Rails](#ruby-on-rails)
38
+ - [Grape](#grape)
39
+ - [ORMs](#orms)
40
+ - [Extensions](#extensions)
41
+ - [Example Applications](#example-applications)
42
+ - [Tutorials](#tutorials)
43
+ - [Sponsors](#sponsors)
69
44
  - [Development](#development)
70
45
  - [Contributing](#contributing)
71
- - [Other resources](#other-resources)
72
- - [Wiki](#wiki)
73
- - [Screencast](#screencast)
74
- - [Client applications](#client-applications)
75
- - [Contributors](#contributors)
76
- - [IETF Standards](#ietf-standards)
77
- - [License](#license)
46
+ - [Contributors](#contributors)
47
+ - [License](#license)
78
48
 
79
49
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
80
50
 
81
- ## Installation
82
-
83
- Put this in your Gemfile:
84
-
85
- ``` ruby
86
- gem 'doorkeeper'
87
- ```
88
-
89
- Run the installation generator with:
90
-
91
- rails generate doorkeeper:install
92
-
93
- This will install the doorkeeper initializer into `config/initializers/doorkeeper.rb`.
94
-
95
- ## Configuration
96
-
97
- ### ORM
98
-
99
- #### Active Record
100
-
101
- By default doorkeeper is configured to use Active Record, so to start you have
102
- to generate the migration tables (supports Rails >= 5 migrations versioning):
103
-
104
- rails generate doorkeeper:migration
105
-
106
- You may want to add foreign keys to your migration. For example, if you plan on
107
- using `User` as the resource owner, add the following line to the migration file
108
- for each table that includes a `resource_owner_id` column:
109
-
110
- ```ruby
111
- add_foreign_key :table_name, :users, column: :resource_owner_id
112
- ```
113
-
114
- If you want to enable [PKCE flow] for mobile apps, you need to generate another
115
- migration:
116
-
117
- [PKCE flow]: https://tools.ietf.org/html/rfc7636
118
-
119
- ```sh
120
- rails generate doorkeeper:pkce
121
- ```
122
-
123
- Then run migrations:
124
-
125
- ```sh
126
- rake db:migrate
127
- ```
128
-
129
- Ensure to use non-confidential apps for pkce. PKCE is created, because
130
- you cannot trust its apps' secret. So whatever app needs pkce: it means, it cannot
131
- be a confidential app by design.
132
-
133
-
134
- Remember to add associations to your model so the related records are deleted.
135
- If you don't do this an `ActiveRecord::InvalidForeignKey`-error will be raised
136
- when you try to destroy a model with related access grants or access tokens.
137
-
138
- ```ruby
139
- class User < ApplicationRecord
140
- has_many :access_grants, class_name: "Doorkeeper::AccessGrant",
141
- foreign_key: :resource_owner_id,
142
- dependent: :delete_all # or :destroy if you need callbacks
143
-
144
- has_many :access_tokens, class_name: "Doorkeeper::AccessToken",
145
- foreign_key: :resource_owner_id,
146
- dependent: :delete_all # or :destroy if you need callbacks
147
- end
148
- ```
149
-
150
- #### MongoDB
151
-
152
- See [doorkeeper-mongodb project] for Mongoid and MongoMapper support. Follow along
153
- the implementation in that repository to extend doorkeeper with other ORMs.
154
-
155
- [doorkeeper-mongodb project]: https://github.com/doorkeeper-gem/doorkeeper-mongodb
156
-
157
- #### Sequel
158
-
159
- If you are using [Sequel gem] then you can add [doorkeeper-sequel extension] to your project.
160
- Follow configuration instructions for setting up the necessary Doorkeeper ORM.
161
-
162
- [Sequel gem]: https://github.com/jeremyevans/sequel/
163
- [doorkeeper-sequel extension]: https://github.com/nbulaj/doorkeeper-sequel
164
-
165
- #### Couchbase
166
-
167
- Use [doorkeeper-couchbase] extension if you are using Couchbase database.
168
-
169
- [doorkeeper-couchbase]: https://github.com/acaprojects/doorkeeper-couchbase
170
-
171
- ### API mode
172
-
173
- By default Doorkeeper uses full Rails stack to provide all the OAuth 2 functionality
174
- with additional features like administration area for managing applications. By the
175
- way, starting from Doorkeeper 5 you can use API mode for your [API only Rails 5 applications](http://edgeguides.rubyonrails.org/api_app.html).
176
- All you need is just to configure the gem to work in desired mode:
177
-
178
- ``` ruby
179
- Doorkeeper.configure do
180
- # ...
181
-
182
- api_only
183
- end
184
- ```
185
-
186
- Keep in mind, that in this mode you will not be able to access `Applications` or
187
- `Authorized Applications` controllers because they will be skipped. CSRF protections (which are otherwise enabled) will be skipped, and all the redirects will be returned as JSON response with corresponding locations.
188
-
189
- ### Routes
190
-
191
- The installation script will also automatically add the Doorkeeper routes into
192
- your app, like this:
193
-
194
- ``` ruby
195
- Rails.application.routes.draw do
196
- use_doorkeeper
197
- # your routes
198
- end
199
- ```
200
-
201
- This will mount following routes:
202
-
203
- GET /oauth/authorize/native?code
204
- GET /oauth/authorize
205
- POST /oauth/authorize
206
- DELETE /oauth/authorize
207
- POST /oauth/token
208
- POST /oauth/revoke
209
- POST /oauth/introspect
210
- resources /oauth/applications
211
- GET /oauth/authorized_applications
212
- DELETE /oauth/authorized_applications/:id
213
- GET /oauth/token/info
214
-
215
- For more information on how to customize routes, check out [this page on the
216
- wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
217
-
218
- ### Authenticating
219
-
220
- You need to configure Doorkeeper in order to provide `resource_owner` model
221
- and authentication block in `config/initializers/doorkeeper.rb`:
222
-
223
- ``` ruby
224
- Doorkeeper.configure do
225
- resource_owner_authenticator do
226
- User.find_by(id: session[:current_user_id]) || redirect_to(login_url)
227
- end
228
- end
229
- ```
230
-
231
- This code is run in the context of your application so you have access to your
232
- models, session or routes helpers. However, since this code is not run in the
233
- context of your application's `ApplicationController` it doesn't have access to
234
- the methods defined over there.
235
-
236
- You may want to check other ways of authentication
237
- [here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Authenticating-using-Clearance-or-DIY).
238
-
239
- ### Internationalization (I18n)
240
-
241
- Doorkeeper support multiple languages. See language files in
242
- [the I18n repository](https://github.com/doorkeeper-gem/doorkeeper-i18n).
243
-
244
- ### Customizing errors
245
-
246
- If you don't want to use default Doorkeeper error responses you can raise and rescue it's
247
- exceptions. All you need is to set configuration option `handle_auth_errors` to `:raise`.
248
- In this case Doorkeeper will raise `Doorkeeper::Errors::TokenForbidden`,
249
- `Doorkeeper::Errors::TokenExpired`, `Doorkeeper::Errors::TokenRevoked` or other exceptions
250
- that you need to care about.
251
-
252
- ### Rake Tasks
253
-
254
- If you are using `rake`, you can load rake tasks provided by this gem, by adding
255
- the following line to your `Rakefile`:
256
-
257
- ```ruby
258
- Doorkeeper::Rake.load_tasks
259
- ```
260
-
261
- #### Cleaning up
262
-
263
- By default Doorkeeper is retaining expired and revoked access tokens and grants.
264
- This allows to keep an audit log of those records, but it also leads to the
265
- corresponding tables to grow large over the lifetime of your application.
266
-
267
- If you are concerned about those tables growing too large,
268
- you can regularly run the following rake task to remove stale entries
269
- from the database:
270
-
271
- ```rake
272
- rake doorkeeper:db:cleanup
273
- ```
51
+ ## Documentation
274
52
 
275
- Note that this will remove tokens that are expired according to the configured TTL
276
- in `Doorkeeper.configuration.access_token_expires_in`. The specific `expires_in`
277
- value of each access token **is not considered**. The same is true for access
278
- grants.
53
+ This documentation is valid for `master` branch. Please check the documentation for the version of doorkeeper you are using in:
54
+ https://github.com/doorkeeper-gem/doorkeeper/releases.
279
55
 
280
- ## Protecting resources with OAuth (a.k.a your API endpoint)
56
+ Additionally, other resources can be found on:
281
57
 
282
- ### Ruby on Rails controllers
283
-
284
- To protect your controllers (usual one or `ActionController::API`) with OAuth,
285
- you just need to setup `before_action`s specifying the actions you want to
286
- protect. For example:
287
-
288
- ``` ruby
289
- class Api::V1::ProductsController < Api::V1::ApiController
290
- before_action :doorkeeper_authorize! # Requires access token for all actions
291
-
292
- # before_action -> { doorkeeper_authorize! :read, :write }
293
-
294
- # your actions
295
- end
296
- ```
297
-
298
- You can pass any option `before_action` accepts, such as `if`, `only`,
299
- `except`, and others.
300
-
301
- ### Grape endpoints
302
-
303
- Starting from version 2.2 Doorkeeper provides helpers for the
304
- [Grape framework] >= 0.10. One of them is `doorkeeper_authorize!` that
305
- can be used in a similar way as an example above to protect your API
306
- with OAuth. Note that you have to use `require 'doorkeeper/grape/helpers'`
307
- and `helpers Doorkeeper::Grape::Helpers` in your Grape API class.
308
-
309
- For more information about integration with Grape see the [Wiki].
310
-
311
- [Grape framework]: https://github.com/ruby-grape/grape
312
- [Wiki]: https://github.com/doorkeeper-gem/doorkeeper/wiki/Grape-Integration
313
-
314
- ``` ruby
315
- require 'doorkeeper/grape/helpers'
316
-
317
- module API
318
- module V1
319
- class Users < Grape::API
320
- helpers Doorkeeper::Grape::Helpers
321
-
322
- before do
323
- doorkeeper_authorize!
324
- end
325
-
326
- # route_setting :scopes, ['user:email'] - for old versions of Grape
327
- get :emails, scopes: [:user, :write] do
328
- [{'email' => current_user.email}]
329
- end
330
-
331
- # ...
332
- end
333
- end
334
- end
335
- ```
336
-
337
- ### Route Constraints and other integrations
338
-
339
- You can leverage the `Doorkeeper.authenticate` facade to easily extract a
340
- `Doorkeeper::OAuth::Token` based on the current request. You can then ensure
341
- that token is still good, find its associated `#resource_owner_id`, etc.
342
-
343
- ```ruby
344
- module Constraint
345
- class Authenticated
346
-
347
- def matches?(request)
348
- token = Doorkeeper.authenticate(request)
349
- token && token.accessible?
350
- end
351
- end
352
- end
353
- ```
354
-
355
- For more information about integration and other integrations, check out [the
356
- related wiki
357
- page](https://github.com/doorkeeper-gem/doorkeeper/wiki/ActionController::Metal-with-doorkeeper).
358
-
359
- ### Access Token Scopes
360
-
361
- You can also require the access token to have specific scopes in certain
362
- actions:
363
-
364
- First configure the scopes in `initializers/doorkeeper.rb`
365
-
366
- ```ruby
367
- Doorkeeper.configure do
368
- default_scopes :public # if no scope was requested, this will be the default
369
- optional_scopes :admin, :write
370
- end
371
- ```
372
-
373
- And in your controllers:
374
-
375
- ```ruby
376
- class Api::V1::ProductsController < Api::V1::ApiController
377
- before_action -> { doorkeeper_authorize! :public }, only: :index
378
- before_action only: [:create, :update, :destroy] do
379
- doorkeeper_authorize! :admin, :write
380
- end
381
- end
382
- ```
383
-
384
- Please note that there is a logical OR between multiple required scopes. In the
385
- above example, `doorkeeper_authorize! :admin, :write` means that the access
386
- token is required to have either `:admin` scope or `:write` scope, but does not
387
- need to have both of them.
388
-
389
- If you want to require the access token to have multiple scopes at the same
390
- time, use multiple `doorkeeper_authorize!`, for example:
391
-
392
- ```ruby
393
- class Api::V1::ProductsController < Api::V1::ApiController
394
- before_action -> { doorkeeper_authorize! :public }, only: :index
395
- before_action only: [:create, :update, :destroy] do
396
- doorkeeper_authorize! :admin
397
- doorkeeper_authorize! :write
398
- end
399
- end
400
- ```
401
-
402
- In the above example, a client can call `:create` action only if its access token
403
- has both `:admin` and `:write` scopes.
404
-
405
- ### Custom Access Token Generator
406
-
407
- By default a 128 bit access token will be generated. If you require a custom
408
- token, such as [JWT](http://jwt.io), specify an object that responds to
409
- `.generate(options = {})` and returns a string to be used as the token.
410
-
411
- ```ruby
412
- Doorkeeper.configure do
413
- access_token_generator "Doorkeeper::JWT"
414
- end
415
- ```
416
-
417
- JWT token support is available with
418
- [Doorkeeper-JWT](https://github.com/chriswarren/doorkeeper-jwt).
58
+ - [Guides](https://doorkeeper.gitbook.io/guides/) with how-to get started and configuration documentation
59
+ - See the [Wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki) with articles and other documentation
60
+ - Screencast from [railscasts.com](http://railscasts.com/): [#353
61
+ OAuth with
62
+ Doorkeeper](http://railscasts.com/episodes/353-oauth-with-doorkeeper)
63
+ - See [upgrade guides](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions)
64
+ - For general questions, please post on [Stack Overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
65
+ - See [SECURITY.md](SECURITY.md) for this project's security disclose
66
+ policy
419
67
 
420
- ### Custom Base Controller
68
+ ## Installation
421
69
 
422
- By default Doorkeeper's main controller `Doorkeeper::ApplicationController`
423
- inherits from `ActionController::Base`. You may want to use your own
424
- controller to inherit from, to keep Doorkeeper controllers in the same
425
- context than the rest your app:
70
+ Installation depends on the framework you're using. The first step is to add the following to your Gemfile:
426
71
 
427
72
  ```ruby
428
- Doorkeeper.configure do
429
- base_controller 'ApplicationController'
430
- end
73
+ gem 'doorkeeper'
431
74
  ```
432
75
 
433
- ### Authenticated resource owner
76
+ And run `bundle install`. After this, check out the guide related to the framework you're using.
434
77
 
435
- If you want to return data based on the current resource owner, in other
436
- words, the access token owner, you may want to define a method in your
437
- controller that returns the resource owner instance:
78
+ ### Ruby on Rails
438
79
 
439
- ``` ruby
440
- class Api::V1::CredentialsController < Api::V1::ApiController
441
- before_action :doorkeeper_authorize!
442
- respond_to :json
80
+ Doorkeeper currently supports Ruby on Rails >= 5.0. See the guide [here](https://doorkeeper.gitbook.io/guides/ruby-on-rails/getting-started).
443
81
 
444
- # GET /me.json
445
- def me
446
- respond_with current_resource_owner
447
- end
82
+ ### Grape
448
83
 
449
- private
84
+ Guide for integration with Grape framework can be found [here](https://doorkeeper.gitbook.io/guides/grape/grape).
450
85
 
451
- # Find the user that owns the access token
452
- def current_resource_owner
453
- User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
454
- end
455
- end
456
- ```
86
+ ## ORMs
457
87
 
458
- In this example, we're returning the credentials (`me.json`) of the access
459
- token owner.
88
+ Doorkeeper supports Active Record by default, but can be configured to work with the following ORMs:
460
89
 
461
- ### Applications list
90
+ | ORM | Support via |
91
+ | :--- | :--- |
92
+ | Active Record | by default |
93
+ | MongoDB | [doorkeeper-gem/doorkeeper-mongodb](https://github.com/doorkeeper-gem/doorkeeper-mongodb) |
94
+ | Sequel | [nbulaj/doorkeeper-sequel](https://github.com/nbulaj/doorkeeper-sequel) |
95
+ | Couchbase | [acaprojects/doorkeeper-couchbase](https://github.com/acaprojects/doorkeeper-couchbase) |
462
96
 
463
- By default, the applications list (`/oauth/applications`) is publicly available (before 5.0 release).
464
- Starting from Doorkeeper 5.0 it returns 403 Forbidden if `admin_authenticator` option is not configured
465
- by developers.
97
+ ## Extensions
466
98
 
467
- To change the protection rules of this endpoint you should uncomment these lines:
99
+ Extensions that are not included by default and can be installed separately.
468
100
 
469
- ```ruby
470
- # config/initializers/doorkeeper.rb
471
- Doorkeeper.configure do
472
- admin_authenticator do |routes|
473
- Admin.find_by(id: session[:admin_id]) || redirect_to(routes.new_admin_session_url)
474
- end
475
- end
476
- ```
477
-
478
- The logic is the same as the `resource_owner_authenticator` block. **Note:**
479
- since the application list is just a scaffold, it's recommended to either
480
- customize the controller used by the list or skip the controller all together.
481
- For more information see the page
482
- [in the wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
101
+ | | Link |
102
+ | :--- | :--- |
103
+ | OpenID Connect extension | [doorkeeper-gem/doorkeeper-openid\_connect](https://github.com/doorkeeper-gem/doorkeeper-openid_connect) |
104
+ | JWT Token support | [doorkeeper-gem/doorkeeper-jwt](https://github.com/doorkeeper-gem/doorkeeper-jwt) |
105
+ | Assertion grant extension | [doorkeeper-gem/doorkeeper-grants\_assertion](https://github.com/doorkeeper-gem/doorkeeper-grants_assertion) |
106
+ | I18n translations | [doorkeeper-gem/doorkeeper-i18n](https://github.com/doorkeeper-gem/doorkeeper-i18n) |
483
107
 
484
- By default, everybody can create application with any scopes. However,
485
- you can enforce users to create applications only with configured scopes
486
- (`default_scopes` and `optional_scopes` from the Doorkeeper initializer):
108
+ ## Example Applications
487
109
 
488
- ```ruby
489
- # config/initializers/doorkeeper.rb
490
- Doorkeeper.configure do
491
- # ...
110
+ These applications show how Doorkeeper works and how to integrate with it. Start with the oAuth2 server and use the clients to connect with the server.
492
111
 
493
- default_scopes :read, :write
494
- optional_scopes :create, :update
112
+ | Application | Link |
113
+ | :--- | :--- |
114
+ | oAuth2 Server with Doorkeeper | [doorkeeper-gem/doorkeeper-provider-app](https://github.com/doorkeeper-gem/doorkeeper-provider-app) |
115
+ | Sinatra Client connected to Provider App | [doorkeeper-gem/doorkeeper-sinatra-client](https://github.com/doorkeeper-gem/doorkeeper-sinatra-client) |
116
+ | Devise + Omniauth Client | [doorkeeper-gem/doorkeeper-devise-client](https://github.com/doorkeeper-gem/doorkeeper-devise-client) |
495
117
 
496
- enforce_configured_scopes
497
- end
498
- ```
118
+ You may want to create a client application to
119
+ test the integration. Check out these [client
120
+ examples](https://github.com/doorkeeper-gem/doorkeeper/wiki/Example-Applications)
121
+ in our wiki or follow this [tutorial
122
+ here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Testing-your-provider-with-OAuth2-gem).
499
123
 
500
- ## Other customizations
124
+ ## Tutorials
501
125
 
502
- - [Associate users to OAuth applications (ownership)](https://github.com/doorkeeper-gem/doorkeeper/wiki/Associate-users-to-OAuth-applications-%28ownership%29)
503
- - [CORS - Cross Origin Resource Sharing](https://github.com/doorkeeper-gem/doorkeeper/wiki/%5BCORS%5D-Cross-Origin-Resource-Sharing)
504
- - see more on [Wiki page](https://github.com/doorkeeper-gem/doorkeeper/wiki)
126
+ See [list of tutorials](https://github.com/doorkeeper-gem/doorkeeper/wiki#how-tos--tutorials) in order to learn how to use the gem or integrate it with other solutions / gems.
505
127
 
506
- ## Testing
128
+ ## Sponsors
507
129
 
508
- You can use Doorkeeper models in your application test suite. Note that starting from
509
- Doorkeeper 4.3.0 it uses [ActiveSupport lazy loading hooks](http://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html)
510
- to load models. There are [known issue](https://github.com/doorkeeper-gem/doorkeeper/issues/1043)
511
- with the `factory_bot_rails` gem (it executes factories building before `ActiveRecord::Base`
512
- is initialized using hooks in gem railtie, so you can catch a `uninitialized constant` error).
513
- It is recommended to use pure `factory_bot` gem to solve this problem.
130
+ [![OpenCollective](https://opencollective.com/doorkeeper-gem/backers/badge.svg)](#backers)
131
+ [![OpenCollective](https://opencollective.com/doorkeeper-gem/sponsors/badge.svg)](#sponsors)
514
132
 
515
- ## Upgrading
133
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/doorkeeper-gem#sponsor)]
516
134
 
517
- If you want to upgrade doorkeeper to a new version, check out the [upgrading
518
- notes](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions)
519
- and take a look at the
520
- [changelog](https://github.com/doorkeeper-gem/doorkeeper/blob/master/NEWS.md).
135
+ <a href="https://oauth.io/?utm_source=doorkeeper-gem" target="_blank"><img src="https://oauth.io/img/logo_text.png"/></a>
521
136
 
522
- Doorkeeper follows [semantic versioning](http://semver.org/).
137
+ > If you prefer not to deal with the gory details of OAuth 2, need dedicated customer support & consulting, try the cloud-based SaaS version: [https://oauth.io](https://oauth.io/?utm_source=doorkeeper-gem)
523
138
 
524
139
  ## Development
525
140
 
@@ -534,7 +149,7 @@ By default, it uses the latest Rails version with ActiveRecord. To run the
534
149
  tests with a specific ORM and Rails version:
535
150
 
536
151
  ```
537
- rails=4.2.0 orm=active_record bundle exec rake
152
+ rails=5.2 orm=active_record bundle exec rake
538
153
  ```
539
154
 
540
155
  ## Contributing
@@ -548,38 +163,13 @@ integrate the gem with your app and let us know!
548
163
  Also, check out our [contributing guidelines
549
164
  page](https://github.com/doorkeeper-gem/doorkeeper/wiki/Contributing).
550
165
 
551
- ## Other resources
552
-
553
- ### Wiki
554
-
555
- You can find everything about Doorkeeper in our [wiki
556
- here](https://github.com/doorkeeper-gem/doorkeeper/wiki).
557
-
558
- ### Screencast
559
-
560
- Check out this screencast from [railscasts.com](http://railscasts.com/): [#353
561
- OAuth with
562
- Doorkeeper](http://railscasts.com/episodes/353-oauth-with-doorkeeper)
563
-
564
- ### Client applications
565
-
566
- After you set up the provider, you may want to create a client application to
567
- test the integration. Check out these [client
568
- examples](https://github.com/doorkeeper-gem/doorkeeper/wiki/Example-Applications)
569
- in our wiki or follow this [tutorial
570
- here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Testing-your-provider-with-OAuth2-gem).
571
-
572
- ### Contributors
166
+ ## Contributors
573
167
 
574
168
  Thanks to all our [awesome
575
169
  contributors](https://github.com/doorkeeper-gem/doorkeeper/graphs/contributors)!
576
170
 
577
- ### IETF Standards
578
-
579
- * [The OAuth 2.0 Authorization Framework](http://tools.ietf.org/html/rfc6749)
580
- * [OAuth 2.0 Threat Model and Security Considerations](http://tools.ietf.org/html/rfc6819)
581
- * [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
171
+ <a href="https://github.com/doorkeeper-gem/doorkeeper/graphs/contributors"><img src="https://opencollective.com/doorkeeper-gem/contributors.svg?width=890&button=false" /></a>
582
172
 
583
- ### License
173
+ ## License
584
174
 
585
175
  MIT License. Copyright 2011 Applicake.
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
- require 'bundler/setup'
2
- require 'rspec/core/rake_task'
1
+ # frozen_string_literal: true
3
2
 
4
- desc 'Default: run specs.'
3
+ require "bundler/setup"
4
+ require "rspec/core/rake_task"
5
+
6
+ desc "Default: run specs."
5
7
  task default: :spec
6
8
 
7
9
  desc "Run all specs"
@@ -12,14 +14,14 @@ end
12
14
  namespace :doorkeeper do
13
15
  desc "Install doorkeeper in dummy app"
14
16
  task :install do
15
- cd 'spec/dummy'
16
- system 'bundle exec rails g doorkeeper:install --force'
17
+ cd "spec/dummy"
18
+ system "bundle exec rails g doorkeeper:install --force"
17
19
  end
18
20
 
19
- desc 'Runs local test server'
21
+ desc "Runs local test server"
20
22
  task :server do
21
- cd 'spec/dummy'
22
- system 'bundle exec rails server'
23
+ cd "spec/dummy"
24
+ system "bundle exec rails server"
23
25
  end
24
26
  end
25
27
 
@@ -3,12 +3,11 @@
3
3
  module Doorkeeper
4
4
  class ApplicationController <
5
5
  Doorkeeper.configuration.base_controller.constantize
6
-
7
6
  include Helpers::Controller
8
7
 
9
8
  unless Doorkeeper.configuration.api_only
10
9
  protect_from_forgery with: :exception
11
- helper 'doorkeeper/dashboard'
10
+ helper "doorkeeper/dashboard"
12
11
  end
13
12
  end
14
13
  end