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