doorkeeper 5.1.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (265) hide show
  1. checksums.yaml +4 -4
  2. data/{NEWS.md → CHANGELOG.md} +234 -25
  3. data/README.md +21 -11
  4. data/app/controllers/doorkeeper/application_controller.rb +2 -2
  5. data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
  6. data/app/controllers/doorkeeper/applications_controller.rb +8 -7
  7. data/app/controllers/doorkeeper/authorizations_controller.rb +56 -19
  8. data/app/controllers/doorkeeper/authorized_applications_controller.rb +5 -5
  9. data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
  10. data/app/controllers/doorkeeper/tokens_controller.rb +93 -25
  11. data/app/views/doorkeeper/applications/_form.html.erb +1 -7
  12. data/app/views/doorkeeper/applications/show.html.erb +35 -14
  13. data/app/views/doorkeeper/authorizations/form_post.html.erb +11 -0
  14. data/config/locales/en.yml +13 -3
  15. data/lib/doorkeeper/config/abstract_builder.rb +28 -0
  16. data/lib/doorkeeper/config/option.rb +20 -2
  17. data/lib/doorkeeper/config/validations.rb +53 -0
  18. data/lib/doorkeeper/config.rb +291 -121
  19. data/lib/doorkeeper/engine.rb +1 -1
  20. data/lib/doorkeeper/errors.rb +13 -18
  21. data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
  22. data/lib/doorkeeper/grant_flow/flow.rb +44 -0
  23. data/lib/doorkeeper/grant_flow/registry.rb +50 -0
  24. data/lib/doorkeeper/grant_flow.rb +45 -0
  25. data/lib/doorkeeper/grape/helpers.rb +7 -3
  26. data/lib/doorkeeper/helpers/controller.rb +36 -11
  27. data/lib/doorkeeper/models/access_grant_mixin.rb +22 -18
  28. data/lib/doorkeeper/models/access_token_mixin.rb +194 -51
  29. data/lib/doorkeeper/models/application_mixin.rb +8 -7
  30. data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
  31. data/lib/doorkeeper/models/concerns/resource_ownerable.rb +47 -0
  32. data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
  33. data/lib/doorkeeper/models/concerns/revocable.rb +1 -28
  34. data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
  35. data/lib/doorkeeper/models/concerns/secret_storable.rb +1 -3
  36. data/lib/doorkeeper/oauth/authorization/code.rb +25 -14
  37. data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
  38. data/lib/doorkeeper/oauth/authorization/token.rb +24 -19
  39. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +4 -4
  40. data/lib/doorkeeper/oauth/authorization_code_request.rb +40 -21
  41. data/lib/doorkeeper/oauth/base_request.rb +21 -23
  42. data/lib/doorkeeper/oauth/client/credentials.rb +2 -4
  43. data/lib/doorkeeper/oauth/client.rb +8 -9
  44. data/lib/doorkeeper/oauth/client_credentials/creator.rb +45 -5
  45. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +10 -8
  46. data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +13 -3
  47. data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -7
  48. data/lib/doorkeeper/oauth/code_request.rb +6 -12
  49. data/lib/doorkeeper/oauth/code_response.rb +24 -14
  50. data/lib/doorkeeper/oauth/error.rb +1 -1
  51. data/lib/doorkeeper/oauth/error_response.rb +10 -11
  52. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +8 -12
  53. data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
  54. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +19 -5
  55. data/lib/doorkeeper/oauth/hooks/context.rb +21 -0
  56. data/lib/doorkeeper/oauth/invalid_request_response.rb +43 -0
  57. data/lib/doorkeeper/oauth/invalid_token_response.rb +7 -4
  58. data/lib/doorkeeper/oauth/nonstandard.rb +39 -0
  59. data/lib/doorkeeper/oauth/password_access_token_request.rb +32 -10
  60. data/lib/doorkeeper/oauth/pre_authorization.rb +111 -42
  61. data/lib/doorkeeper/oauth/refresh_token_request.rb +45 -33
  62. data/lib/doorkeeper/oauth/token.rb +6 -7
  63. data/lib/doorkeeper/oauth/token_introspection.rb +24 -18
  64. data/lib/doorkeeper/oauth/token_request.rb +6 -20
  65. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  66. data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
  67. data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
  68. data/lib/doorkeeper/orm/active_record/application.rb +5 -83
  69. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +68 -0
  70. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +59 -0
  71. data/lib/doorkeeper/orm/active_record/mixins/application.rb +198 -0
  72. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +66 -0
  73. data/lib/doorkeeper/orm/active_record.rb +20 -6
  74. data/lib/doorkeeper/rails/helpers.rb +4 -4
  75. data/lib/doorkeeper/rails/routes/abstract_router.rb +35 -0
  76. data/lib/doorkeeper/rails/routes/mapper.rb +2 -2
  77. data/lib/doorkeeper/rails/routes/registry.rb +45 -0
  78. data/lib/doorkeeper/rails/routes.rb +17 -25
  79. data/lib/doorkeeper/rake/db.rake +6 -6
  80. data/lib/doorkeeper/rake/setup.rake +5 -0
  81. data/lib/doorkeeper/request/authorization_code.rb +5 -3
  82. data/lib/doorkeeper/request/client_credentials.rb +2 -2
  83. data/lib/doorkeeper/request/password.rb +2 -2
  84. data/lib/doorkeeper/request/refresh_token.rb +5 -4
  85. data/lib/doorkeeper/request/strategy.rb +2 -2
  86. data/lib/doorkeeper/request.rb +49 -17
  87. data/lib/doorkeeper/server.rb +7 -11
  88. data/lib/doorkeeper/stale_records_cleaner.rb +6 -2
  89. data/lib/doorkeeper/version.rb +1 -5
  90. data/lib/doorkeeper.rb +114 -79
  91. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  92. data/lib/generators/doorkeeper/confidential_applications_generator.rb +2 -2
  93. data/lib/generators/doorkeeper/enable_polymorphic_resource_owner_generator.rb +39 -0
  94. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  95. data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
  96. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -7
  97. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +3 -1
  98. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb +2 -0
  99. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +2 -0
  100. data/lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb +17 -0
  101. data/lib/generators/doorkeeper/templates/initializer.rb +205 -43
  102. data/lib/generators/doorkeeper/templates/migration.rb.erb +18 -6
  103. metadata +43 -310
  104. data/.coveralls.yml +0 -1
  105. data/.github/ISSUE_TEMPLATE.md +0 -25
  106. data/.github/PULL_REQUEST_TEMPLATE.md +0 -17
  107. data/.gitignore +0 -20
  108. data/.gitlab-ci.yml +0 -16
  109. data/.hound.yml +0 -3
  110. data/.rspec +0 -1
  111. data/.rubocop.yml +0 -50
  112. data/.travis.yml +0 -35
  113. data/Appraisals +0 -40
  114. data/CODE_OF_CONDUCT.md +0 -46
  115. data/CONTRIBUTING.md +0 -47
  116. data/Dangerfile +0 -67
  117. data/Gemfile +0 -24
  118. data/RELEASING.md +0 -10
  119. data/Rakefile +0 -28
  120. data/SECURITY.md +0 -15
  121. data/UPGRADE.md +0 -2
  122. data/app/validators/redirect_uri_validator.rb +0 -50
  123. data/bin/console +0 -16
  124. data/doorkeeper.gemspec +0 -34
  125. data/gemfiles/rails_5_0.gemfile +0 -17
  126. data/gemfiles/rails_5_1.gemfile +0 -17
  127. data/gemfiles/rails_5_2.gemfile +0 -17
  128. data/gemfiles/rails_6_0.gemfile +0 -17
  129. data/gemfiles/rails_master.gemfile +0 -17
  130. data/spec/controllers/application_metal_controller_spec.rb +0 -64
  131. data/spec/controllers/applications_controller_spec.rb +0 -180
  132. data/spec/controllers/authorizations_controller_spec.rb +0 -527
  133. data/spec/controllers/protected_resources_controller_spec.rb +0 -353
  134. data/spec/controllers/token_info_controller_spec.rb +0 -50
  135. data/spec/controllers/tokens_controller_spec.rb +0 -330
  136. data/spec/dummy/Rakefile +0 -9
  137. data/spec/dummy/app/assets/config/manifest.js +0 -2
  138. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  139. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
  140. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
  141. data/spec/dummy/app/controllers/home_controller.rb +0 -18
  142. data/spec/dummy/app/controllers/metal_controller.rb +0 -13
  143. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
  144. data/spec/dummy/app/helpers/application_helper.rb +0 -7
  145. data/spec/dummy/app/models/user.rb +0 -7
  146. data/spec/dummy/app/views/home/index.html.erb +0 -0
  147. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  148. data/spec/dummy/config/application.rb +0 -47
  149. data/spec/dummy/config/boot.rb +0 -7
  150. data/spec/dummy/config/database.yml +0 -15
  151. data/spec/dummy/config/environment.rb +0 -5
  152. data/spec/dummy/config/environments/development.rb +0 -31
  153. data/spec/dummy/config/environments/production.rb +0 -64
  154. data/spec/dummy/config/environments/test.rb +0 -45
  155. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
  156. data/spec/dummy/config/initializers/doorkeeper.rb +0 -121
  157. data/spec/dummy/config/initializers/secret_token.rb +0 -10
  158. data/spec/dummy/config/initializers/session_store.rb +0 -10
  159. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
  160. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
  161. data/spec/dummy/config/routes.rb +0 -13
  162. data/spec/dummy/config.ru +0 -6
  163. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
  164. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
  165. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
  166. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
  167. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
  168. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
  169. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
  170. data/spec/dummy/db/schema.rb +0 -68
  171. data/spec/dummy/public/404.html +0 -26
  172. data/spec/dummy/public/422.html +0 -26
  173. data/spec/dummy/public/500.html +0 -26
  174. data/spec/dummy/public/favicon.ico +0 -0
  175. data/spec/dummy/script/rails +0 -9
  176. data/spec/factories.rb +0 -30
  177. data/spec/generators/application_owner_generator_spec.rb +0 -28
  178. data/spec/generators/confidential_applications_generator_spec.rb +0 -29
  179. data/spec/generators/install_generator_spec.rb +0 -36
  180. data/spec/generators/migration_generator_spec.rb +0 -28
  181. data/spec/generators/pkce_generator_spec.rb +0 -28
  182. data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
  183. data/spec/generators/templates/routes.rb +0 -4
  184. data/spec/generators/views_generator_spec.rb +0 -29
  185. data/spec/grape/grape_integration_spec.rb +0 -137
  186. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
  187. data/spec/lib/config_spec.rb +0 -697
  188. data/spec/lib/doorkeeper_spec.rb +0 -27
  189. data/spec/lib/models/expirable_spec.rb +0 -61
  190. data/spec/lib/models/reusable_spec.rb +0 -40
  191. data/spec/lib/models/revocable_spec.rb +0 -59
  192. data/spec/lib/models/scopes_spec.rb +0 -53
  193. data/spec/lib/models/secret_storable_spec.rb +0 -135
  194. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
  195. data/spec/lib/oauth/authorization_code_request_spec.rb +0 -156
  196. data/spec/lib/oauth/base_request_spec.rb +0 -205
  197. data/spec/lib/oauth/base_response_spec.rb +0 -47
  198. data/spec/lib/oauth/client/credentials_spec.rb +0 -90
  199. data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -94
  200. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -112
  201. data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -59
  202. data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -29
  203. data/spec/lib/oauth/client_credentials_request_spec.rb +0 -109
  204. data/spec/lib/oauth/client_spec.rb +0 -38
  205. data/spec/lib/oauth/code_request_spec.rb +0 -47
  206. data/spec/lib/oauth/code_response_spec.rb +0 -36
  207. data/spec/lib/oauth/error_response_spec.rb +0 -66
  208. data/spec/lib/oauth/error_spec.rb +0 -23
  209. data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -22
  210. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -98
  211. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
  212. data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -247
  213. data/spec/lib/oauth/invalid_token_response_spec.rb +0 -55
  214. data/spec/lib/oauth/password_access_token_request_spec.rb +0 -192
  215. data/spec/lib/oauth/pre_authorization_spec.rb +0 -215
  216. data/spec/lib/oauth/refresh_token_request_spec.rb +0 -177
  217. data/spec/lib/oauth/scopes_spec.rb +0 -148
  218. data/spec/lib/oauth/token_request_spec.rb +0 -150
  219. data/spec/lib/oauth/token_response_spec.rb +0 -86
  220. data/spec/lib/oauth/token_spec.rb +0 -158
  221. data/spec/lib/request/strategy_spec.rb +0 -54
  222. data/spec/lib/secret_storing/base_spec.rb +0 -60
  223. data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
  224. data/spec/lib/secret_storing/plain_spec.rb +0 -44
  225. data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
  226. data/spec/lib/server_spec.rb +0 -61
  227. data/spec/lib/stale_records_cleaner_spec.rb +0 -89
  228. data/spec/models/doorkeeper/access_grant_spec.rb +0 -144
  229. data/spec/models/doorkeeper/access_token_spec.rb +0 -591
  230. data/spec/models/doorkeeper/application_spec.rb +0 -367
  231. data/spec/requests/applications/applications_request_spec.rb +0 -259
  232. data/spec/requests/applications/authorized_applications_spec.rb +0 -32
  233. data/spec/requests/endpoints/authorization_spec.rb +0 -73
  234. data/spec/requests/endpoints/token_spec.rb +0 -75
  235. data/spec/requests/flows/authorization_code_errors_spec.rb +0 -78
  236. data/spec/requests/flows/authorization_code_spec.rb +0 -447
  237. data/spec/requests/flows/client_credentials_spec.rb +0 -128
  238. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -34
  239. data/spec/requests/flows/implicit_grant_spec.rb +0 -90
  240. data/spec/requests/flows/password_spec.rb +0 -259
  241. data/spec/requests/flows/refresh_token_spec.rb +0 -233
  242. data/spec/requests/flows/revoke_token_spec.rb +0 -143
  243. data/spec/requests/flows/skip_authorization_spec.rb +0 -66
  244. data/spec/requests/protected_resources/metal_spec.rb +0 -16
  245. data/spec/requests/protected_resources/private_api_spec.rb +0 -83
  246. data/spec/routing/custom_controller_routes_spec.rb +0 -133
  247. data/spec/routing/default_routes_spec.rb +0 -41
  248. data/spec/routing/scoped_routes_spec.rb +0 -47
  249. data/spec/spec_helper.rb +0 -57
  250. data/spec/spec_helper_integration.rb +0 -4
  251. data/spec/support/dependencies/factory_bot.rb +0 -4
  252. data/spec/support/doorkeeper_rspec.rb +0 -22
  253. data/spec/support/helpers/access_token_request_helper.rb +0 -13
  254. data/spec/support/helpers/authorization_request_helper.rb +0 -43
  255. data/spec/support/helpers/config_helper.rb +0 -11
  256. data/spec/support/helpers/model_helper.rb +0 -78
  257. data/spec/support/helpers/request_spec_helper.rb +0 -98
  258. data/spec/support/helpers/url_helper.rb +0 -62
  259. data/spec/support/http_method_shim.rb +0 -29
  260. data/spec/support/orm/active_record.rb +0 -5
  261. data/spec/support/shared/controllers_shared_context.rb +0 -123
  262. data/spec/support/shared/hashing_shared_context.rb +0 -36
  263. data/spec/support/shared/models_shared_examples.rb +0 -54
  264. data/spec/validators/redirect_uri_validator_spec.rb +0 -158
  265. data/spec/version/version_spec.rb +0 -17
@@ -1,330 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe Doorkeeper::TokensController do
6
- describe "when authorization has succeeded" do
7
- let(:token) { double(:token, authorize: true) }
8
-
9
- it "returns the authorization" do
10
- skip "verify need of these specs"
11
-
12
- expect(token).to receive(:authorization)
13
-
14
- post :create
15
- end
16
- end
17
-
18
- describe "when authorization has failed" do
19
- it "returns the error response" do
20
- token = double(:token, authorize: false)
21
- allow(controller).to receive(:token) { token }
22
-
23
- post :create
24
-
25
- expect(response.status).to eq 400
26
- expect(response.headers["WWW-Authenticate"]).to match(/Bearer/)
27
- end
28
- end
29
-
30
- describe "when there is a failure due to a custom error" do
31
- it "returns the error response with a custom message" do
32
- # I18n looks for `doorkeeper.errors.messages.custom_message` in locale files
33
- custom_message = "my_message"
34
- allow(I18n).to receive(:translate)
35
- .with(
36
- custom_message,
37
- hash_including(scope: %i[doorkeeper errors messages])
38
- )
39
- .and_return("Authorization custom message")
40
-
41
- doorkeeper_error = Doorkeeper::Errors::DoorkeeperError.new(custom_message)
42
-
43
- strategy = double(:strategy)
44
- request = double(token_request: strategy)
45
- allow(strategy).to receive(:authorize).and_raise(doorkeeper_error)
46
- allow(controller).to receive(:server).and_return(request)
47
-
48
- post :create
49
-
50
- expected_response_body = {
51
- "error" => custom_message,
52
- "error_description" => "Authorization custom message",
53
- }
54
- expect(response.status).to eq 400
55
- expect(response.headers["WWW-Authenticate"]).to match(/Bearer/)
56
- expect(JSON.parse(response.body)).to eq expected_response_body
57
- end
58
- end
59
-
60
- # http://tools.ietf.org/html/rfc7009#section-2.2
61
- describe "revoking tokens" do
62
- let(:client) { FactoryBot.create(:application) }
63
- let(:access_token) { FactoryBot.create(:access_token, application: client) }
64
-
65
- context "when associated app is public" do
66
- let(:client) { FactoryBot.create(:application, confidential: false) }
67
-
68
- it "returns 200" do
69
- post :revoke, params: { token: access_token.token }
70
-
71
- expect(response.status).to eq 200
72
- end
73
-
74
- it "revokes the access token" do
75
- post :revoke, params: { token: access_token.token }
76
-
77
- expect(access_token.reload).to have_attributes(revoked?: true)
78
- end
79
- end
80
-
81
- context "when associated app is confidential" do
82
- let(:client) { FactoryBot.create(:application, confidential: true) }
83
- let(:oauth_client) { Doorkeeper::OAuth::Client.new(client) }
84
-
85
- before(:each) do
86
- allow_any_instance_of(Doorkeeper::Server).to receive(:client) { oauth_client }
87
- end
88
-
89
- it "returns 200" do
90
- post :revoke, params: { token: access_token.token }
91
-
92
- expect(response.status).to eq 200
93
- end
94
-
95
- it "revokes the access token" do
96
- post :revoke, params: { token: access_token.token }
97
-
98
- expect(access_token.reload).to have_attributes(revoked?: true)
99
- end
100
-
101
- context "when authorization fails" do
102
- let(:some_other_client) { FactoryBot.create(:application, confidential: true) }
103
- let(:oauth_client) { Doorkeeper::OAuth::Client.new(some_other_client) }
104
-
105
- it "returns 200" do
106
- post :revoke, params: { token: access_token.token }
107
-
108
- expect(response.status).to eq 200
109
- end
110
-
111
- it "does not revoke the access token" do
112
- post :revoke, params: { token: access_token.token }
113
-
114
- expect(access_token.reload).to have_attributes(revoked?: false)
115
- end
116
- end
117
- end
118
- end
119
-
120
- describe "authorize response memoization" do
121
- it "memoizes the result of the authorization" do
122
- strategy = double(:strategy, authorize: true)
123
- expect(strategy).to receive(:authorize).once
124
- allow(controller).to receive(:strategy) { strategy }
125
- allow(controller).to receive(:create) do
126
- 2.times { controller.send :authorize_response }
127
- controller.render json: {}, status: :ok
128
- end
129
-
130
- post :create
131
- end
132
- end
133
-
134
- describe "when requested token introspection" do
135
- let(:client) { FactoryBot.create(:application) }
136
- let(:access_token) { FactoryBot.create(:access_token, application: client) }
137
- let(:token_for_introspection) { FactoryBot.create(:access_token, application: client) }
138
-
139
- context "authorized using valid Bearer token" do
140
- it "responds with full token introspection" do
141
- request.headers["Authorization"] = "Bearer #{access_token.token}"
142
-
143
- post :introspect, params: { token: token_for_introspection.token }
144
-
145
- should_have_json "active", true
146
- expect(json_response).to include("client_id", "token_type", "exp", "iat")
147
- end
148
- end
149
-
150
- context "authorized using valid Client Authentication" do
151
- it "responds with full token introspection" do
152
- request.headers["Authorization"] = basic_auth_header_for_client(client)
153
-
154
- post :introspect, params: { token: token_for_introspection.token }
155
-
156
- should_have_json "active", true
157
- expect(json_response).to include("client_id", "token_type", "exp", "iat")
158
- should_have_json "client_id", client.uid
159
- end
160
- end
161
-
162
- context "using custom introspection response" do
163
- before do
164
- Doorkeeper.configure do
165
- orm DOORKEEPER_ORM
166
- custom_introspection_response do |_token, _context|
167
- {
168
- sub: "Z5O3upPC88QrAjx00dis",
169
- aud: "https://protected.example.net/resource",
170
- }
171
- end
172
- end
173
- end
174
-
175
- it "responds with full token introspection" do
176
- request.headers["Authorization"] = "Bearer #{access_token.token}"
177
-
178
- post :introspect, params: { token: token_for_introspection.token }
179
-
180
- expect(json_response).to include("client_id", "token_type", "exp", "iat", "sub", "aud")
181
- should_have_json "sub", "Z5O3upPC88QrAjx00dis"
182
- should_have_json "aud", "https://protected.example.net/resource"
183
- end
184
- end
185
-
186
- context "public access token" do
187
- let(:token_for_introspection) { FactoryBot.create(:access_token, application: nil) }
188
-
189
- it "responds with full token introspection" do
190
- request.headers["Authorization"] = basic_auth_header_for_client(client)
191
-
192
- post :introspect, params: { token: token_for_introspection.token }
193
-
194
- should_have_json "active", true
195
- expect(json_response).to include("client_id", "token_type", "exp", "iat")
196
- should_have_json "client_id", nil
197
- end
198
- end
199
-
200
- context "token was issued to a different client than is making this request" do
201
- let(:different_client) { FactoryBot.create(:application) }
202
-
203
- it "responds with only active state" do
204
- request.headers["Authorization"] = basic_auth_header_for_client(different_client)
205
-
206
- post :introspect, params: { token: token_for_introspection.token }
207
-
208
- expect(response).to be_successful
209
-
210
- should_have_json "active", false
211
- expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
212
- end
213
- end
214
-
215
- context "authorized using invalid Bearer token" do
216
- let(:access_token) do
217
- FactoryBot.create(:access_token, application: client, revoked_at: 1.day.ago)
218
- end
219
-
220
- it "responds with invalid token error" do
221
- request.headers["Authorization"] = "Bearer #{access_token.token}"
222
-
223
- post :introspect, params: { token: token_for_introspection.token }
224
-
225
- response_status_should_be 401
226
-
227
- should_not_have_json "active"
228
- should_have_json "error", "invalid_token"
229
- end
230
- end
231
-
232
- context "authorized using the Bearer token that need to be introspected" do
233
- it "responds with invalid token error" do
234
- request.headers["Authorization"] = "Bearer #{access_token.token}"
235
-
236
- post :introspect, params: { token: access_token.token }
237
-
238
- response_status_should_be 401
239
-
240
- should_not_have_json "active"
241
- should_have_json "error", "invalid_token"
242
- end
243
- end
244
-
245
- context "using invalid credentials to authorize" do
246
- let(:client) { double(uid: "123123", secret: "666999") }
247
- let(:access_token) { FactoryBot.create(:access_token) }
248
-
249
- it "responds with invalid_client error" do
250
- request.headers["Authorization"] = basic_auth_header_for_client(client)
251
-
252
- post :introspect, params: { token: access_token.token }
253
-
254
- expect(response).not_to be_successful
255
- response_status_should_be 401
256
-
257
- should_not_have_json "active"
258
- should_have_json "error", "invalid_client"
259
- end
260
- end
261
-
262
- context "using wrong token value" do
263
- context "authorized using client credentials" do
264
- it "responds with only active state" do
265
- request.headers["Authorization"] = basic_auth_header_for_client(client)
266
-
267
- post :introspect, params: { token: SecureRandom.hex(16) }
268
-
269
- should_have_json "active", false
270
- expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
271
- end
272
- end
273
-
274
- context "authorized using valid Bearer token" do
275
- it "responds with only active state" do
276
- request.headers["Authorization"] = "Bearer #{access_token.token}"
277
-
278
- post :introspect, params: { token: SecureRandom.hex(16) }
279
-
280
- should_have_json "active", false
281
- expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
282
- end
283
- end
284
- end
285
-
286
- context "when requested access token expired" do
287
- let(:token_for_introspection) do
288
- FactoryBot.create(:access_token, application: client, created_at: 1.year.ago)
289
- end
290
-
291
- it "responds with only active state" do
292
- request.headers["Authorization"] = basic_auth_header_for_client(client)
293
-
294
- post :introspect, params: { token: token_for_introspection.token }
295
-
296
- should_have_json "active", false
297
- expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
298
- end
299
- end
300
-
301
- context "when requested Access Token revoked" do
302
- let(:token_for_introspection) do
303
- FactoryBot.create(:access_token, application: client, revoked_at: 1.year.ago)
304
- end
305
-
306
- it "responds with only active state" do
307
- request.headers["Authorization"] = basic_auth_header_for_client(client)
308
-
309
- post :introspect, params: { token: token_for_introspection.token }
310
-
311
- should_have_json "active", false
312
- expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
313
- end
314
- end
315
-
316
- context "unauthorized (no bearer token or client credentials)" do
317
- let(:token_for_introspection) { FactoryBot.create(:access_token) }
318
-
319
- it "responds with invalid_request error" do
320
- post :introspect, params: { token: token_for_introspection.token }
321
-
322
- expect(response).not_to be_successful
323
- response_status_should_be 400
324
-
325
- should_not_have_json "active"
326
- should_have_json "error", "invalid_request"
327
- end
328
- end
329
- end
330
- end
data/spec/dummy/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env rake
2
- # frozen_string_literal: true
3
-
4
- # Add your own tasks in files placed in lib/tasks ending in .rake,
5
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
6
-
7
- require File.expand_path("config/application", __dir__)
8
-
9
- Dummy::Application.load_tasks
@@ -1,2 +0,0 @@
1
- // JS and CSS bundles
2
- //
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ApplicationController < ActionController::Base
4
- protect_from_forgery with: :exception
5
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CustomAuthorizationsController < ::ApplicationController
4
- %w[index show new create edit update destroy].each do |action|
5
- define_method action do
6
- render nothing: true
7
- end
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class FullProtectedResourcesController < ApplicationController
4
- before_action -> { doorkeeper_authorize! :write, :admin }, only: :show
5
- before_action :doorkeeper_authorize!, only: :index
6
-
7
- def index
8
- render plain: "index"
9
- end
10
-
11
- def show
12
- render plain: "show"
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class HomeController < ApplicationController
4
- def index; end
5
-
6
- def sign_in
7
- session[:user_id] = if Rails.env.development?
8
- User.first || User.create!(name: "Joe", password: "sekret")
9
- else
10
- User.first
11
- end
12
- redirect_to "/"
13
- end
14
-
15
- def callback
16
- render plain: "ok"
17
- end
18
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MetalController < ActionController::Metal
4
- include AbstractController::Callbacks
5
- include ActionController::Head
6
- include Doorkeeper::Rails::Helpers
7
-
8
- before_action :doorkeeper_authorize!
9
-
10
- def index
11
- self.response_body = { ok: true }.to_json
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class SemiProtectedResourcesController < ApplicationController
4
- before_action :doorkeeper_authorize!, only: :index
5
-
6
- def index
7
- render plain: "protected index"
8
- end
9
-
10
- def show
11
- render plain: "non protected show"
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApplicationHelper
4
- def current_user
5
- @current_user ||= User.find_by_id(session[:user_id])
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class User < ActiveRecord::Base
4
- def self.authenticate!(name, password)
5
- User.where(name: name, password: password).first
6
- end
7
- end
File without changes
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= csrf_meta_tags %>
6
- </head>
7
- <body>
8
-
9
- <%= link_to "Sign in", '/sign_in' %>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,47 +0,0 @@
1
- require File.expand_path('boot', __dir__)
2
-
3
- require "rails"
4
-
5
- %w[
6
- action_controller/railtie
7
- action_view/railtie
8
- sprockets/railtie
9
- ].each do |railtie|
10
- begin
11
- require railtie
12
- rescue LoadError
13
- end
14
- end
15
-
16
- Bundler.require(*Rails.groups)
17
-
18
- require 'yaml'
19
-
20
- orm = if DOORKEEPER_ORM =~ /mongoid/
21
- Mongoid.load!(File.join(File.dirname(File.expand_path(__FILE__)), "#{DOORKEEPER_ORM}.yml"))
22
- :mongoid
23
- else
24
- DOORKEEPER_ORM
25
- end
26
- require "#{orm}/railtie"
27
-
28
- module Dummy
29
- class Application < Rails::Application
30
- if Rails.gem_version < Gem::Version.new('5.1')
31
- config.action_controller.per_form_csrf_tokens = true
32
- config.action_controller.forgery_protection_origin_check = true
33
-
34
- ActiveSupport.to_time_preserves_timezone = true
35
-
36
- config.active_record.belongs_to_required_by_default = true
37
-
38
- config.ssl_options = { hsts: { subdomains: true } }
39
- else
40
- config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
41
- end
42
-
43
- # Settings in config/environments/* take precedence over those specified here.
44
- # Application configuration should go into files in config/initializers
45
- # -- all .rb files in that directory are automatically loaded.
46
- end
47
- end
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- orm = ENV['BUNDLE_GEMFILE'].match(/Gemfile\.(.+)\.rb/)
5
- DOORKEEPER_ORM = (orm && orm[1]) || :active_record unless defined?(DOORKEEPER_ORM)
6
-
7
- $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -1,15 +0,0 @@
1
- development:
2
- adapter: sqlite3
3
- database: db/development.sqlite3
4
- pool: 5
5
- timeout: 5000
6
-
7
- test:
8
- adapter: sqlite3
9
- database: ":memory:"
10
- timeout: 500
11
-
12
- production:
13
- adapter: sqlite3
14
- database: ":memory:"
15
- timeout: 500
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('application', __dir__)
3
-
4
- # Initialize the rails application
5
- Rails.application.initialize!
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Dummy::Application.configure do
4
- # Settings specified here will take precedence over those in config/application.rb
5
-
6
- # In the development environment your application's code is reloaded on
7
- # every request. This slows down response time but is perfect for development
8
- # since you don't have to restart the web server when you make code changes.
9
- config.cache_classes = false
10
-
11
- # Show full error reports and disable caching
12
- config.consider_all_requests_local = true
13
- config.action_controller.perform_caching = false
14
-
15
- # Don't care if the mailer can't send
16
- # config.action_mailer.raise_delivery_errors = false
17
-
18
- # Print deprecation notices to the Rails logger
19
- config.active_support.deprecation = :log
20
-
21
- # Only use best-standards-support built into browsers
22
- config.action_dispatch.best_standards_support = :builtin
23
-
24
- # Do not compress assets
25
- config.assets.compress = false
26
-
27
- # Expands the lines which load the assets
28
- config.assets.debug = true
29
-
30
- config.eager_load = false
31
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Dummy::Application.configure do
4
- # Settings specified here will take precedence over those in config/application.rb
5
-
6
- # Code is not reloaded between requests
7
- config.cache_classes = true
8
-
9
- # Full error reports are disabled and caching is turned on
10
- config.consider_all_requests_local = false
11
- config.action_controller.perform_caching = true
12
-
13
- # Disable Rails's static asset server (Apache or nginx will already do this)
14
- config.serve_static_assets = false
15
-
16
- # Compress JavaScripts and CSS
17
- config.assets.compress = true
18
-
19
- # Don't fallback to assets pipeline if a precompiled asset is missed
20
- config.assets.compile = false
21
-
22
- # Generate digests for assets URLs
23
- config.assets.digest = true
24
-
25
- # Defaults to Rails.root.join("public/assets")
26
- # config.assets.manifest = YOUR_PATH
27
-
28
- # Specifies the header that your server uses for sending files
29
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
30
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
31
-
32
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
33
- # config.force_ssl = true
34
-
35
- # See everything in the log (default is :info)
36
- # config.log_level = :debug
37
-
38
- # Use a different logger for distributed setups
39
- # config.logger = SyslogLogger.new
40
-
41
- # Use a different cache store in production
42
- # config.cache_store = :mem_cache_store
43
-
44
- # Enable serving of images, stylesheets, and JavaScripts from an asset server
45
- # config.action_controller.asset_host = "http://assets.example.com"
46
-
47
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
48
- # config.assets.precompile += %w( search.js )
49
-
50
- # Disable delivery errors, bad email addresses will be ignored
51
- # config.action_mailer.raise_delivery_errors = false
52
-
53
- # Enable threaded mode
54
- # config.threadsafe!
55
-
56
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
57
- # the I18n.default_locale when a translation can not be found)
58
- config.i18n.fallbacks = true
59
-
60
- # Send deprecation notices to registered listeners
61
- config.active_support.deprecation = :notify
62
-
63
- config.eager_load = true
64
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Dummy::Application.configure do
4
- # Settings specified here will take precedence over those in config/application.rb
5
-
6
- # The test environment is used exclusively to run your application's
7
- # test suite. You never need to work with it otherwise. Remember that
8
- # your test database is "scratch space" for the test suite and is wiped
9
- # and recreated between test runs. Don't rely on the data there!
10
- config.cache_classes = true
11
-
12
- config.assets.enabled = true
13
- config.assets.version = "1.0"
14
- config.assets.digest = false
15
-
16
- # Do not eager load code on boot. This avoids loading your whole application
17
- # just for the purpose of running a single test. If you are using a tool that
18
- # preloads Rails for running tests, you may have to set it to true.
19
- config.eager_load = false
20
-
21
- # Show full error reports and disable caching
22
- config.consider_all_requests_local = true
23
- config.action_controller.perform_caching = false
24
-
25
- # Raise exceptions instead of rendering exception templates
26
- config.action_dispatch.show_exceptions = false
27
-
28
- # Disable request forgery protection in test environment
29
- config.action_controller.allow_forgery_protection = false
30
-
31
- # Tell Action Mailer not to deliver emails to the real world.
32
- # The :test delivery method accumulates sent emails in the
33
- # ActionMailer::Base.deliveries array.
34
- # config.action_mailer.delivery_method = :test
35
-
36
- # Use SQL instead of Active Record's schema dumper when creating the test database.
37
- # This is necessary if your schema can't be completely dumped by the schema dumper,
38
- # like if you have constraints or database-specific column types
39
- # config.active_record.schema_format = :sql
40
-
41
- # Print deprecation notices to the stderr
42
- config.active_support.deprecation = :stderr
43
-
44
- config.eager_load = true
45
- end