doorkeeper 1.1.0 → 1.2.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.

Potentially problematic release.


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

Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.md +14 -2
  4. data/README.md +93 -42
  5. data/app/controllers/doorkeeper/application_controller.rb +1 -1
  6. data/app/controllers/doorkeeper/applications_controller.rb +4 -4
  7. data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
  8. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  9. data/app/controllers/doorkeeper/token_info_controller.rb +3 -3
  10. data/app/controllers/doorkeeper/tokens_controller.rb +29 -2
  11. data/app/helpers/doorkeeper/form_errors_helper.rb +2 -2
  12. data/app/validators/redirect_uri_validator.rb +1 -1
  13. data/app/views/doorkeeper/applications/_form.html.erb +3 -3
  14. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  15. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  16. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  17. data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
  18. data/doorkeeper.gemspec +1 -1
  19. data/lib/doorkeeper.rb +31 -31
  20. data/lib/doorkeeper/config.rb +66 -37
  21. data/lib/doorkeeper/doorkeeper_for.rb +6 -3
  22. data/lib/doorkeeper/engine.rb +2 -2
  23. data/lib/doorkeeper/helpers/controller.rb +9 -9
  24. data/lib/doorkeeper/helpers/filter.rb +1 -1
  25. data/lib/doorkeeper/models/access_grant.rb +5 -5
  26. data/lib/doorkeeper/models/access_token.rb +22 -18
  27. data/lib/doorkeeper/models/active_record/access_token.rb +8 -8
  28. data/lib/doorkeeper/models/active_record/application.rb +5 -5
  29. data/lib/doorkeeper/models/application.rb +8 -9
  30. data/lib/doorkeeper/models/expirable.rb +1 -1
  31. data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +2 -2
  32. data/lib/doorkeeper/models/mongo_mapper/access_token.rb +11 -11
  33. data/lib/doorkeeper/models/mongo_mapper/application.rb +4 -4
  34. data/lib/doorkeeper/models/mongoid/version.rb +2 -2
  35. data/lib/doorkeeper/models/mongoid2/access_grant.rb +7 -7
  36. data/lib/doorkeeper/models/mongoid2/access_token.rb +14 -14
  37. data/lib/doorkeeper/models/mongoid2/application.rb +7 -7
  38. data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +7 -7
  39. data/lib/doorkeeper/models/mongoid3_4/access_token.rb +13 -13
  40. data/lib/doorkeeper/models/mongoid3_4/application.rb +6 -6
  41. data/lib/doorkeeper/models/ownership.rb +5 -5
  42. data/lib/doorkeeper/oauth/authorization/code.rb +5 -5
  43. data/lib/doorkeeper/oauth/authorization/token.rb +7 -7
  44. data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -19
  45. data/lib/doorkeeper/oauth/client.rb +1 -1
  46. data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -4
  47. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -4
  48. data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -2
  49. data/lib/doorkeeper/oauth/client_credentials_request.rb +11 -15
  50. data/lib/doorkeeper/oauth/code_request.rb +5 -4
  51. data/lib/doorkeeper/oauth/code_response.rb +8 -7
  52. data/lib/doorkeeper/oauth/error.rb +1 -1
  53. data/lib/doorkeeper/oauth/error_response.rb +5 -5
  54. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
  55. data/lib/doorkeeper/oauth/invalid_token_response.rb +10 -10
  56. data/lib/doorkeeper/oauth/password_access_token_request.rb +57 -54
  57. data/lib/doorkeeper/oauth/pre_authorization.rb +7 -7
  58. data/lib/doorkeeper/oauth/refresh_token_request.rb +27 -24
  59. data/lib/doorkeeper/oauth/scopes.rb +3 -3
  60. data/lib/doorkeeper/oauth/token.rb +27 -1
  61. data/lib/doorkeeper/oauth/token_request.rb +14 -4
  62. data/lib/doorkeeper/rails/routes.rb +31 -22
  63. data/lib/doorkeeper/rails/routes/mapping.rb +11 -12
  64. data/lib/doorkeeper/request.rb +5 -5
  65. data/lib/doorkeeper/version.rb +1 -1
  66. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  67. data/lib/generators/doorkeeper/install_generator.rb +5 -5
  68. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  69. data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +2 -2
  70. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +2 -2
  71. data/lib/generators/doorkeeper/templates/initializer.rb +16 -3
  72. data/lib/generators/doorkeeper/templates/migration.rb +16 -17
  73. data/lib/generators/doorkeeper/views_generator.rb +1 -1
  74. data/spec/controllers/applications_controller_spec.rb +7 -7
  75. data/spec/controllers/authorizations_controller_spec.rb +48 -48
  76. data/spec/controllers/protected_resources_controller_spec.rb +108 -107
  77. data/spec/controllers/token_info_controller_spec.rb +11 -11
  78. data/spec/controllers/tokens_controller_spec.rb +8 -8
  79. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -2
  80. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +3 -3
  81. data/spec/dummy/app/controllers/home_controller.rb +5 -5
  82. data/spec/dummy/app/controllers/metal_controller.rb +1 -1
  83. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
  84. data/spec/dummy/app/models/user.rb +3 -3
  85. data/spec/dummy/config/application.rb +8 -9
  86. data/spec/dummy/config/boot.rb +1 -1
  87. data/spec/dummy/config/environments/test.rb +1 -1
  88. data/spec/dummy/config/initializers/doorkeeper.rb +5 -5
  89. data/spec/dummy/config/initializers/session_store.rb +1 -1
  90. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  91. data/spec/dummy/config/routes.rb +27 -27
  92. data/spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb +16 -17
  93. data/spec/dummy/db/migrate/20130902175349_add_owner_to_application.rb +3 -3
  94. data/spec/dummy/db/schema.rb +39 -39
  95. data/spec/factories/access_grant.rb +3 -3
  96. data/spec/factories/access_token.rb +1 -1
  97. data/spec/factories/application.rb +3 -3
  98. data/spec/generators/application_owner_generator_spec.rb +6 -7
  99. data/spec/generators/install_generator_spec.rb +9 -9
  100. data/spec/generators/migration_generator_spec.rb +4 -4
  101. data/spec/lib/config_spec.rb +136 -44
  102. data/spec/lib/models/expirable_spec.rb +9 -9
  103. data/spec/lib/models/revocable_spec.rb +4 -4
  104. data/spec/lib/oauth/authorization/uri_builder_spec.rb +4 -4
  105. data/spec/lib/oauth/authorization_code_request_spec.rb +2 -2
  106. data/spec/lib/oauth/client/credentials_spec.rb +4 -4
  107. data/spec/lib/oauth/client/methods_spec.rb +10 -10
  108. data/spec/lib/oauth/client_credentials/issuer_spec.rb +9 -7
  109. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -2
  110. data/spec/lib/oauth/client_credentials_request_spec.rb +6 -6
  111. data/spec/lib/oauth/client_spec.rb +4 -4
  112. data/spec/lib/oauth/code_request_spec.rb +10 -9
  113. data/spec/lib/oauth/error_response_spec.rb +8 -8
  114. data/spec/lib/oauth/error_spec.rb +1 -1
  115. data/spec/lib/oauth/helpers/scope_checker_spec.rb +17 -17
  116. data/spec/lib/oauth/helpers/unique_token_spec.rb +7 -7
  117. data/spec/lib/oauth/helpers/uri_checker_spec.rb +33 -33
  118. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  119. data/spec/lib/oauth/password_access_token_request_spec.rb +13 -13
  120. data/spec/lib/oauth/pre_authorization_spec.rb +47 -7
  121. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -21
  122. data/spec/lib/oauth/scopes_spec.rb +32 -32
  123. data/spec/lib/oauth/token_request_spec.rb +10 -9
  124. data/spec/lib/oauth/token_response_spec.rb +13 -15
  125. data/spec/lib/oauth/token_spec.rb +24 -10
  126. data/spec/lib/server_spec.rb +24 -2
  127. data/spec/models/doorkeeper/access_grant_spec.rb +8 -8
  128. data/spec/models/doorkeeper/access_token_spec.rb +79 -33
  129. data/spec/models/doorkeeper/application_spec.rb +29 -29
  130. data/spec/requests/applications/applications_request_spec.rb +15 -15
  131. data/spec/requests/applications/authorized_applications_spec.rb +7 -7
  132. data/spec/requests/endpoints/authorization_spec.rb +19 -12
  133. data/spec/requests/endpoints/token_spec.rb +26 -8
  134. data/spec/requests/flows/authorization_code_errors_spec.rb +17 -17
  135. data/spec/requests/flows/authorization_code_spec.rb +28 -28
  136. data/spec/requests/flows/client_credentials_spec.rb +3 -3
  137. data/spec/requests/flows/implicit_grant_errors_spec.rb +5 -5
  138. data/spec/requests/flows/implicit_grant_spec.rb +2 -2
  139. data/spec/requests/flows/password_spec.rb +32 -32
  140. data/spec/requests/flows/refresh_token_spec.rb +23 -23
  141. data/spec/requests/flows/revoke_token_spec.rb +165 -0
  142. data/spec/requests/flows/skip_authorization_spec.rb +10 -10
  143. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  144. data/spec/requests/protected_resources/private_api_spec.rb +5 -5
  145. data/spec/routing/custom_controller_routes_spec.rb +4 -0
  146. data/spec/routing/default_routes_spec.rb +5 -1
  147. data/spec/spec_helper.rb +2 -2
  148. data/spec/spec_helper_integration.rb +8 -10
  149. data/spec/support/helpers/access_token_request_helper.rb +3 -3
  150. data/spec/support/helpers/authorization_request_helper.rb +3 -3
  151. data/spec/support/helpers/config_helper.rb +1 -1
  152. data/spec/support/helpers/model_helper.rb +2 -2
  153. data/spec/support/helpers/request_spec_helper.rb +3 -3
  154. data/spec/support/helpers/url_helper.rb +25 -21
  155. data/spec/support/orm/active_record.rb +4 -4
  156. data/spec/support/orm/mongo_mapper.rb +2 -3
  157. data/spec/support/orm/mongoid.rb +5 -6
  158. data/spec/support/shared/controllers_shared_context.rb +15 -15
  159. data/spec/support/shared/models_shared_examples.rb +13 -13
  160. data/spec/validators/redirect_uri_validator_spec.rb +9 -9
  161. metadata +5 -4
@@ -14,17 +14,17 @@ feature 'Implicit Grant Flow Errors' do
14
14
 
15
15
  [
16
16
  [:client_id, :invalid_client],
17
- [:redirect_uri, :invalid_redirect_uri],
17
+ [:redirect_uri, :invalid_redirect_uri]
18
18
  ].each do |error|
19
19
  scenario "displays #{error.last.inspect} error for invalid #{error.first.inspect}" do
20
- visit authorization_endpoint_url(:client => @client, error.first => "invalid", :response_type => "token")
21
- i_should_not_see "Authorize"
20
+ visit authorization_endpoint_url(client: @client, error.first => 'invalid', response_type: 'token')
21
+ i_should_not_see 'Authorize'
22
22
  i_should_see_translated_error_message error.last
23
23
  end
24
24
 
25
25
  scenario "displays #{error.last.inspect} error when #{error.first.inspect} is missing" do
26
- visit authorization_endpoint_url(:client => @client, error.first => "", :response_type => "token")
27
- i_should_not_see "Authorize"
26
+ visit authorization_endpoint_url(client: @client, error.first => '', response_type: 'token')
27
+ i_should_not_see 'Authorize'
28
28
  i_should_see_translated_error_message error.last
29
29
  end
30
30
  end
@@ -9,8 +9,8 @@ feature 'Implicit Grant Flow' do
9
9
  end
10
10
 
11
11
  scenario 'resource owner authorizes the client' do
12
- visit authorization_endpoint_url(:client => @client, :response_type => 'token')
13
- click_on "Authorize"
12
+ visit authorization_endpoint_url(client: @client, response_type: 'token')
13
+ click_on 'Authorize'
14
14
 
15
15
  access_token_should_exist_for @client, @resource_owner
16
16
 
@@ -12,11 +12,11 @@ feature 'Resource Owner Password Credentials Flow inproperly set up' do
12
12
  end
13
13
 
14
14
  context 'with valid user credentials' do
15
- scenario "should issue new token" do
15
+ scenario 'should issue new token' do
16
16
  pending 'Check a way to supress warnings here (or handle config better)'
17
- expect {
18
- post password_token_endpoint_url(:client => @client, :resource_owner => @resource_owner)
19
- }.to_not change { Doorkeeper::AccessToken.count }
17
+ expect do
18
+ post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
19
+ end.to_not change { Doorkeeper::AccessToken.count }
20
20
  end
21
21
  end
22
22
  end
@@ -29,30 +29,30 @@ feature 'Resource Owner Password Credentials Flow' do
29
29
  end
30
30
 
31
31
  context 'with valid user credentials' do
32
- scenario "should issue new token" do
33
- expect {
34
- post password_token_endpoint_url(:client => @client, :resource_owner => @resource_owner)
35
- }.to change { Doorkeeper::AccessToken.count }.by(1)
32
+ scenario 'should issue new token' do
33
+ expect do
34
+ post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
35
+ end.to change { Doorkeeper::AccessToken.count }.by(1)
36
36
 
37
37
  token = Doorkeeper::AccessToken.first
38
38
 
39
39
  should_have_json 'access_token', token.token
40
40
  end
41
41
 
42
- scenario "should issue new token without client credentials" do
43
- expect {
44
- post password_token_endpoint_url(:resource_owner => @resource_owner)
45
- }.to change { Doorkeeper::AccessToken.count }.by(1)
42
+ scenario 'should issue new token without client credentials' do
43
+ expect do
44
+ post password_token_endpoint_url(resource_owner: @resource_owner)
45
+ end.to change { Doorkeeper::AccessToken.count }.by(1)
46
46
 
47
47
  token = Doorkeeper::AccessToken.first
48
48
 
49
49
  should_have_json 'access_token', token.token
50
50
  end
51
51
 
52
- scenario "should issue a refresh token if enabled" do
52
+ scenario 'should issue a refresh token if enabled' do
53
53
  config_is_set(:refresh_token_enabled, true)
54
54
 
55
- post password_token_endpoint_url(:client => @client, :resource_owner => @resource_owner)
55
+ post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
56
56
 
57
57
  token = Doorkeeper::AccessToken.first
58
58
 
@@ -60,29 +60,29 @@ feature 'Resource Owner Password Credentials Flow' do
60
60
  end
61
61
  end
62
62
 
63
- context "with invalid user credentials" do
64
- scenario "should not issue new token with bad password" do
65
- expect {
66
- post password_token_endpoint_url( :client => @client,
67
- :resource_owner_username => @resource_owner.name,
68
- :resource_owner_password => 'wrongpassword')
69
- }.to_not change { Doorkeeper::AccessToken.count }
63
+ context 'with invalid user credentials' do
64
+ scenario 'should not issue new token with bad password' do
65
+ expect do
66
+ post password_token_endpoint_url(client: @client,
67
+ resource_owner_username: @resource_owner.name,
68
+ resource_owner_password: 'wrongpassword')
69
+ end.to_not change { Doorkeeper::AccessToken.count }
70
70
  end
71
71
 
72
- scenario "should not issue new token without credentials" do
73
- expect {
74
- post password_token_endpoint_url( :client => @client)
75
- }.to_not change { Doorkeeper::AccessToken.count }
72
+ scenario 'should not issue new token without credentials' do
73
+ expect do
74
+ post password_token_endpoint_url(client: @client)
75
+ end.to_not change { Doorkeeper::AccessToken.count }
76
76
  end
77
77
  end
78
78
 
79
- context "with invalid client credentials" do
80
- scenario "should not issue new token with bad client credentials" do
81
- expect {
82
- post password_token_endpoint_url( :client_id => @client.uid,
83
- :client_secret => "bad_secret",
84
- :resource_owner => @resource_owner)
85
- }.to_not change { Doorkeeper::AccessToken.count }
79
+ context 'with invalid client credentials' do
80
+ scenario 'should not issue new token with bad client credentials' do
81
+ expect do
82
+ post password_token_endpoint_url(client_id: @client.uid,
83
+ client_secret: 'bad_secret',
84
+ resource_owner: @resource_owner)
85
+ end.to_not change { Doorkeeper::AccessToken.count }
86
86
  end
87
87
  end
88
88
  end
@@ -1,21 +1,21 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
- feature "Refresh Token Flow" do
3
+ feature 'Refresh Token Flow' do
4
4
  before do
5
- Doorkeeper.configure {
5
+ Doorkeeper.configure do
6
6
  orm DOORKEEPER_ORM
7
7
  use_refresh_token
8
- }
8
+ end
9
9
  client_exists
10
10
  end
11
11
 
12
- context "issuing a refresh token" do
12
+ context 'issuing a refresh token' do
13
13
  before do
14
- authorization_code_exists :application => @client
14
+ authorization_code_exists application: @client
15
15
  end
16
16
 
17
- scenario "client gets the refresh token and refreshses it" do
18
- post token_endpoint_url(:code => @authorization.token, :client => @client)
17
+ scenario 'client gets the refresh token and refreshses it' do
18
+ post token_endpoint_url(code: @authorization.token, client: @client)
19
19
 
20
20
  token = Doorkeeper::AccessToken.first
21
21
 
@@ -24,7 +24,7 @@ feature "Refresh Token Flow" do
24
24
 
25
25
  expect(@authorization.reload).to be_revoked
26
26
 
27
- post refresh_token_endpoint_url(:client => @client, :refresh_token => token.refresh_token)
27
+ post refresh_token_endpoint_url(client: @client, refresh_token: token.refresh_token)
28
28
 
29
29
  new_token = Doorkeeper::AccessToken.last
30
30
  should_have_json 'access_token', new_token.token
@@ -35,52 +35,52 @@ feature "Refresh Token Flow" do
35
35
  end
36
36
  end
37
37
 
38
- context "refreshing the token" do
38
+ context 'refreshing the token' do
39
39
  before do
40
- @token = FactoryGirl.create(:access_token, :application => @client, :resource_owner_id => 1, :use_refresh_token => true)
40
+ @token = FactoryGirl.create(:access_token, application: @client, resource_owner_id: 1, use_refresh_token: true)
41
41
  end
42
42
 
43
- scenario "client request a token with refresh token" do
44
- post refresh_token_endpoint_url(:client => @client, :refresh_token => @token.refresh_token)
43
+ scenario 'client request a token with refresh token' do
44
+ post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
45
45
  should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
46
46
  expect(@token.reload).to be_revoked
47
47
  end
48
48
 
49
- scenario "client request a token with expired access token" do
49
+ scenario 'client request a token with expired access token' do
50
50
  @token.update_column :expires_in, -100
51
- post refresh_token_endpoint_url(:client => @client, :refresh_token => @token.refresh_token)
51
+ post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
52
52
  should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
53
53
  expect(@token.reload).to be_revoked
54
54
  end
55
55
 
56
56
  # TODO: verify proper error code for this (previously was invalid_grant)
57
- scenario "client gets an error for invalid refresh token" do
58
- post refresh_token_endpoint_url(:client => @client, :refresh_token => "invalid")
57
+ scenario 'client gets an error for invalid refresh token' do
58
+ post refresh_token_endpoint_url(client: @client, refresh_token: 'invalid')
59
59
  should_not_have_json 'refresh_token'
60
60
  should_have_json 'error', 'invalid_request'
61
61
  end
62
62
 
63
63
  # TODO: verify proper error code for this (previously was invalid_grant)
64
- scenario "client gets an error for revoked acccess token" do
64
+ scenario 'client gets an error for revoked acccess token' do
65
65
  @token.revoke
66
- post refresh_token_endpoint_url(:client => @client, :refresh_token => @token.refresh_token)
66
+ post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
67
67
  should_not_have_json 'refresh_token'
68
68
  should_have_json 'error', 'invalid_request'
69
69
  end
70
70
  end
71
71
 
72
- context "refreshing the token with multiple sessions (devices)" do
72
+ context 'refreshing the token with multiple sessions (devices)' do
73
73
  before do
74
74
  # enable password auth to simulate other devices
75
75
  config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
76
76
  create_resource_owner
77
- @token = FactoryGirl.create(:access_token, :application => @client, :resource_owner_id => @resource_owner.id, :use_refresh_token => true)
77
+ @token = FactoryGirl.create(:access_token, application: @client, resource_owner_id: @resource_owner.id, use_refresh_token: true)
78
78
  end
79
79
 
80
- scenario "client request a token after creating another token with the same user" do
80
+ scenario 'client request a token after creating another token with the same user' do
81
81
  @token.update_column :expires_in, -100
82
- post password_token_endpoint_url(:client => @client, :resource_owner => @resource_owner)
83
- post refresh_token_endpoint_url(:client => @client, :refresh_token => @token.refresh_token)
82
+ post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
83
+ post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
84
84
  should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
85
85
  expect(@token.reload).to be_revoked
86
86
  end
@@ -0,0 +1,165 @@
1
+ require 'spec_helper_integration'
2
+
3
+ feature 'Revoke Token Flow' do
4
+
5
+ before do
6
+ Doorkeeper.configure { orm DOORKEEPER_ORM }
7
+ end
8
+
9
+ context 'with default parameters' do
10
+
11
+ let(:client_application) { FactoryGirl.create :application }
12
+ let(:resource_owner) { User.create!(name: 'John', password: 'sekret') }
13
+ let(:authorization_access_token) do
14
+ FactoryGirl.create(:access_token,
15
+ application: client_application,
16
+ resource_owner_id: resource_owner.id,
17
+ use_refresh_token: true)
18
+ end
19
+
20
+ let(:headers) { { 'HTTP_AUTHORIZATION' => "Bearer #{authorization_access_token.token}" } }
21
+
22
+ context 'With invalid token to revoke' do
23
+
24
+ scenario 'client wants to revoke the given access token' do
25
+
26
+ post revocation_token_endpoint_url, { token: 'I_AM_AN_INVALIDE_TOKEN' }, headers
27
+
28
+ authorization_access_token.reload
29
+ # The authorization server responds with HTTP status code 200 if the token
30
+ # has been revoked successfully or if the client submitted an invalid token.
31
+ expect(response).to be_success
32
+ expect(authorization_access_token).to_not be_revoked
33
+ end
34
+ end
35
+
36
+ context 'The access token to revoke is the same than the authorization access token' do
37
+
38
+ let(:token_to_revoke) { authorization_access_token }
39
+
40
+ scenario 'client wants to revoke the given access token' do
41
+
42
+ post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
43
+
44
+ token_to_revoke.reload
45
+ authorization_access_token.reload
46
+
47
+ expect(response).to be_success
48
+ expect(token_to_revoke.revoked?).to be_true
49
+ expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_true
50
+
51
+ end
52
+
53
+ scenario 'client wants to revoke the given access token using the POST query string' do
54
+
55
+ url_with_query_string = revocation_token_endpoint_url + '?' + Rack::Utils.build_query(token: token_to_revoke.token)
56
+ post url_with_query_string, {}, headers
57
+
58
+ token_to_revoke.reload
59
+ authorization_access_token.reload
60
+
61
+ expect(response).to be_success
62
+ expect(token_to_revoke.revoked?).to be_false
63
+ expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_false
64
+ expect(authorization_access_token.revoked?).to be_false
65
+
66
+ end
67
+
68
+ end
69
+
70
+ context 'The access token to revoke app and owners are the same than the authorization access token' do
71
+
72
+ let(:token_to_revoke) do
73
+ FactoryGirl.create(:access_token,
74
+ application: client_application,
75
+ resource_owner_id: resource_owner.id,
76
+ use_refresh_token: true)
77
+ end
78
+
79
+ scenario 'client wants to revoke the given access token' do
80
+
81
+ post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
82
+
83
+ token_to_revoke.reload
84
+ authorization_access_token.reload
85
+
86
+ expect(response).to be_success
87
+ expect(token_to_revoke.revoked?).to be_true
88
+ expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_true
89
+ expect(authorization_access_token.revoked?).to be_false
90
+
91
+ end
92
+ end
93
+
94
+ context 'The access token to revoke authorization owner is the same than the authorization access token' do
95
+
96
+ let(:other_client_application) { FactoryGirl.create :application }
97
+ let(:token_to_revoke) do
98
+ FactoryGirl.create(:access_token,
99
+ application: other_client_application,
100
+ resource_owner_id: resource_owner.id,
101
+ use_refresh_token: true)
102
+ end
103
+
104
+ scenario 'client wants to revoke the given access token' do
105
+
106
+ post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
107
+
108
+ token_to_revoke.reload
109
+ authorization_access_token.reload
110
+
111
+ expect(response).to be_success
112
+ expect(token_to_revoke.revoked?).to be_false
113
+ expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_false
114
+ expect(authorization_access_token.revoked?).to be_false
115
+
116
+ end
117
+ end
118
+ context 'The access token to revoke app is the same than the authorization access token' do
119
+
120
+ let(:other_resource_owner) { User.create!(name: 'Matheo', password: 'pareto') }
121
+ let(:token_to_revoke) do
122
+ FactoryGirl.create(:access_token,
123
+ application: client_application,
124
+ resource_owner_id: other_resource_owner.id,
125
+ use_refresh_token: true)
126
+ end
127
+
128
+ scenario 'client wants to revoke the given access token' do
129
+
130
+ post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
131
+
132
+ token_to_revoke.reload
133
+ authorization_access_token.reload
134
+
135
+ expect(response).to be_success
136
+ expect(token_to_revoke.revoked?).to be_false
137
+ expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_false
138
+ expect(authorization_access_token.revoked?).to be_false
139
+
140
+ end
141
+ end
142
+
143
+ context 'With valid refresh token to revoke' do
144
+
145
+ let(:token_to_revoke) do
146
+ FactoryGirl.create(:access_token,
147
+ application: client_application,
148
+ resource_owner_id: resource_owner.id,
149
+ use_refresh_token: true)
150
+ end
151
+
152
+ scenario 'client wants to revoke the given refresh token' do
153
+
154
+ post revocation_token_endpoint_url, { token: token_to_revoke.refresh_token, token_type_hint: 'refresh_token' }, headers
155
+ authorization_access_token.reload
156
+ token_to_revoke.reload
157
+
158
+ expect(response).to be_success
159
+ expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_true
160
+ expect(authorization_access_token).to_not be_revoked
161
+
162
+ end
163
+ end
164
+ end
165
+ end
@@ -15,25 +15,25 @@ feature 'Skip authorization form' do
15
15
  end
16
16
 
17
17
  scenario 'skips the authorization and return a new grant code' do
18
- client_is_authorized(@client, @resource_owner, :scopes => "public")
19
- visit authorization_endpoint_url(:client => @client)
18
+ client_is_authorized(@client, @resource_owner, scopes: 'public')
19
+ visit authorization_endpoint_url(client: @client)
20
20
 
21
- i_should_not_see "Authorize"
21
+ i_should_not_see 'Authorize'
22
22
  client_should_be_authorized @client
23
23
  i_should_be_on_client_callback @client
24
- url_should_have_param "code", Doorkeeper::AccessGrant.first.token
24
+ url_should_have_param 'code', Doorkeeper::AccessGrant.first.token
25
25
  end
26
26
 
27
27
  scenario 'does not skip authorization when scopes differ' do
28
- client_is_authorized(@client, @resource_owner, :scopes => "public write")
29
- visit authorization_endpoint_url(:client => @client, :scope => "public")
30
- i_should_see "Authorize"
28
+ client_is_authorized(@client, @resource_owner, scopes: 'public write')
29
+ visit authorization_endpoint_url(client: @client, scope: 'public')
30
+ i_should_see 'Authorize'
31
31
  end
32
32
 
33
33
  scenario 'creates grant with new scope when scopes differ' do
34
- client_is_authorized(@client, @resource_owner, :scopes => "public write")
35
- visit authorization_endpoint_url(:client => @client, :scope => "public")
36
- click_on "Authorize"
34
+ client_is_authorized(@client, @resource_owner, scopes: 'public write')
35
+ visit authorization_endpoint_url(client: @client, scope: 'public')
36
+ click_on 'Authorize'
37
37
  access_grant_should_have_scopes :public
38
38
  end
39
39
  end
@@ -3,7 +3,7 @@ require 'spec_helper_integration'
3
3
  feature 'ActionController::Metal API' do
4
4
  background do
5
5
  @client = FactoryGirl.create(:application)
6
- @resource = User.create!(:name => "Joe", :password => "sekret")
6
+ @resource = User.create!(name: 'Joe', password: 'sekret')
7
7
  @token = client_is_authorized(@client, @resource)
8
8
  end
9
9