doorkeeper 1.1.0 → 1.2.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 (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
@@ -1,71 +1,74 @@
1
- module Doorkeeper::OAuth
2
- class PasswordAccessTokenRequest
3
- include Doorkeeper::Validations
4
- include Doorkeeper::OAuth::Helpers
1
+ module Doorkeeper
2
+ module OAuth
3
+ class PasswordAccessTokenRequest
4
+ include Doorkeeper::Validations
5
+ include Doorkeeper::OAuth::Helpers
5
6
 
6
- validate :client, :error => :invalid_client
7
- validate :resource_owner, :error => :invalid_resource_owner
8
- validate :scopes, :error => :invalid_scope
7
+ validate :client, error: :invalid_client
8
+ validate :resource_owner, error: :invalid_resource_owner
9
+ validate :scopes, error: :invalid_scope
9
10
 
10
- attr_accessor :server, :resource_owner, :credentials, :access_token
11
- attr_accessor :client
11
+ attr_accessor :server, :resource_owner, :credentials, :access_token
12
+ attr_accessor :client
12
13
 
13
- def initialize(server, credentials, resource_owner, parameters = {})
14
- @server = server
15
- @resource_owner = resource_owner
16
- @credentials = credentials
17
- @original_scopes = parameters[:scope]
14
+ def initialize(server, credentials, resource_owner, parameters = {})
15
+ @server = server
16
+ @resource_owner = resource_owner
17
+ @credentials = credentials
18
+ @original_scopes = parameters[:scope]
18
19
 
19
- @client = Doorkeeper::Application.authenticate(credentials.uid, credentials.secret) if credentials
20
- end
21
-
22
- def authorize
23
- validate
24
- @response = if valid?
25
- issue_token
26
- TokenResponse.new access_token
27
- else
28
- ErrorResponse.from_request self
20
+ if credentials
21
+ @client = Doorkeeper::Application.authenticate credentials.uid,
22
+ credentials.secret
23
+ end
29
24
  end
30
- end
31
25
 
32
- def valid?
33
- self.error.nil?
34
- end
26
+ def authorize
27
+ validate
28
+ @response = if valid?
29
+ issue_token
30
+ TokenResponse.new access_token
31
+ else
32
+ ErrorResponse.from_request self
33
+ end
34
+ end
35
35
 
36
- def scopes
37
- @scopes ||= if @original_scopes.present?
38
- Doorkeeper::OAuth::Scopes.from_string(@original_scopes)
39
- else
40
- server.default_scopes
36
+ def valid?
37
+ error.nil?
41
38
  end
42
- end
43
39
 
44
- private
40
+ def scopes
41
+ @scopes ||= if @original_scopes.present?
42
+ Doorkeeper::OAuth::Scopes.from_string(@original_scopes)
43
+ else
44
+ server.default_scopes
45
+ end
46
+ end
45
47
 
46
- def issue_token
47
- application_id = client.id if client
48
+ private
48
49
 
49
- @access_token = Doorkeeper::AccessToken.create!({
50
- :application_id => application_id,
51
- :resource_owner_id => resource_owner.id,
52
- :scopes => scopes.to_s,
53
- :expires_in => server.access_token_expires_in,
54
- :use_refresh_token => server.refresh_token_enabled?
55
- })
56
- end
50
+ def issue_token
51
+ @access_token = Doorkeeper::AccessToken.create!(
52
+ application_id: client.try(:id),
53
+ resource_owner_id: resource_owner.id,
54
+ scopes: scopes.to_s,
55
+ expires_in: server.access_token_expires_in,
56
+ use_refresh_token: server.refresh_token_enabled?
57
+ )
58
+ end
57
59
 
58
- def validate_scopes
59
- return true unless @original_scopes.present?
60
- ScopeChecker.valid?(@original_scopes, @server.scopes)
61
- end
60
+ def validate_scopes
61
+ return true unless @original_scopes.present?
62
+ ScopeChecker.valid?(@original_scopes, @server.scopes)
63
+ end
62
64
 
63
- def validate_resource_owner
64
- !!resource_owner
65
- end
65
+ def validate_resource_owner
66
+ !!resource_owner
67
+ end
66
68
 
67
- def validate_client
68
- !credentials || !!client
69
+ def validate_client
70
+ !credentials || !!client
71
+ end
69
72
  end
70
73
  end
71
74
  end
@@ -3,10 +3,10 @@ module Doorkeeper
3
3
  class PreAuthorization
4
4
  include Doorkeeper::Validations
5
5
 
6
- validate :response_type, :error => :unsupported_response_type
7
- validate :client, :error => :invalid_client
8
- validate :scopes, :error => :invalid_scope
9
- validate :redirect_uri, :error => :invalid_redirect_uri
6
+ validate :response_type, error: :unsupported_response_type
7
+ validate :client, error: :invalid_client
8
+ validate :scopes, error: :invalid_scope
9
+ validate :redirect_uri, error: :invalid_redirect_uri
10
10
 
11
11
  attr_accessor :server, :client, :response_type, :redirect_uri, :state
12
12
  attr_writer :scope
@@ -36,10 +36,10 @@ module Doorkeeper
36
36
  Doorkeeper::OAuth::ErrorResponse.from_request(self)
37
37
  end
38
38
 
39
- private
39
+ private
40
40
 
41
41
  def validate_response_type
42
- %w[code token].include? response_type
42
+ server.authorization_response_types.include? response_type
43
43
  end
44
44
 
45
45
  def validate_client
@@ -55,7 +55,7 @@ module Doorkeeper
55
55
  def validate_redirect_uri
56
56
  return false unless redirect_uri.present?
57
57
  Helpers::URIChecker.test_uri?(redirect_uri) ||
58
- Helpers::URIChecker.valid_for_authorization?(redirect_uri, client.redirect_uri)
58
+ Helpers::URIChecker.valid_for_authorization?(redirect_uri, client.redirect_uri)
59
59
  end
60
60
  end
61
61
  end
@@ -4,10 +4,10 @@ module Doorkeeper
4
4
  include Doorkeeper::Validations
5
5
  include Doorkeeper::OAuth::Helpers
6
6
 
7
- validate :token, :error => :invalid_request
8
- validate :client, :error => :invalid_client
9
- validate :client_match, :error => :invalid_grant
10
- validate :scope, :error => :invalid_scope
7
+ validate :token, error: :invalid_request
8
+ validate :client, error: :invalid_client
9
+ validate :client_match, error: :invalid_grant
10
+ validate :scope, error: :invalid_scope
11
11
 
12
12
  attr_accessor :server, :refresh_token, :credentials, :access_token
13
13
  attr_accessor :client
@@ -18,32 +18,35 @@ module Doorkeeper
18
18
  @credentials = credentials
19
19
  @requested_scopes = parameters[:scopes]
20
20
 
21
- @client = Doorkeeper::Application.authenticate(credentials.uid, credentials.secret) if credentials
21
+ if credentials
22
+ @client = Doorkeeper::Application.authenticate credentials.uid,
23
+ credentials.secret
24
+ end
22
25
  end
23
26
 
24
27
  def authorize
25
28
  validate
26
29
  @response = if valid?
27
- revoke_and_create_access_token
28
- TokenResponse.new access_token
29
- else
30
- ErrorResponse.from_request self
31
- end
30
+ revoke_and_create_access_token
31
+ TokenResponse.new access_token
32
+ else
33
+ ErrorResponse.from_request self
34
+ end
32
35
  end
33
36
 
34
37
  def valid?
35
- self.error.nil?
38
+ error.nil?
36
39
  end
37
40
 
38
41
  def scopes
39
42
  @scopes ||= if @requested_scopes.present?
40
- Scopes.from_string @requested_scopes
41
- else
42
- refresh_token.scopes
43
- end
43
+ Scopes.from_string @requested_scopes
44
+ else
45
+ refresh_token.scopes
46
+ end
44
47
  end
45
48
 
46
- private
49
+ private
47
50
 
48
51
  def revoke_and_create_access_token
49
52
  refresh_token.revoke
@@ -51,13 +54,13 @@ module Doorkeeper
51
54
  end
52
55
 
53
56
  def create_access_token
54
- @access_token = Doorkeeper::AccessToken.create!({
55
- :application_id => refresh_token.application_id,
56
- :resource_owner_id => refresh_token.resource_owner_id,
57
- :scopes => scopes.to_s,
58
- :expires_in => server.access_token_expires_in,
59
- :use_refresh_token => true
60
- })
57
+ @access_token = Doorkeeper::AccessToken.create!(
58
+ application_id: refresh_token.application_id,
59
+ resource_owner_id: refresh_token.resource_owner_id,
60
+ scopes: scopes.to_s,
61
+ expires_in: server.access_token_expires_in,
62
+ use_refresh_token: true
63
+ )
61
64
  end
62
65
 
63
66
  def validate_token
@@ -65,7 +68,7 @@ module Doorkeeper
65
68
  end
66
69
 
67
70
  def validate_client
68
- (!credentials || !!client)
71
+ !credentials || !!client
69
72
  end
70
73
 
71
74
  def validate_client_match
@@ -5,7 +5,7 @@ module Doorkeeper
5
5
  include Comparable
6
6
 
7
7
  def self.from_string(string)
8
- string ||= ""
8
+ string ||= ''
9
9
  new.tap do |scope|
10
10
  scope.add(*string.split)
11
11
  end
@@ -17,7 +17,7 @@ module Doorkeeper
17
17
  end
18
18
  end
19
19
 
20
- delegate :each, :to => :@scopes
20
+ delegate :each, to: :@scopes
21
21
 
22
22
  def initialize
23
23
  @scopes = []
@@ -37,7 +37,7 @@ module Doorkeeper
37
37
  end
38
38
 
39
39
  def to_s
40
- @scopes.join(" ")
40
+ @scopes.join(' ')
41
41
  end
42
42
 
43
43
  def has_scopes?(scopes)
@@ -13,7 +13,33 @@ module Doorkeeper
13
13
  def from_bearer_authorization(request)
14
14
  pattern = /^Bearer /
15
15
  header = request.authorization
16
- header.gsub pattern, '' if header && header.match(pattern)
16
+ token_from_header(header, pattern) if match?(header, pattern)
17
+ end
18
+
19
+ def from_basic_authorization(request)
20
+ pattern = /^Basic /
21
+ header = request.authorization
22
+ token_from_basic_header(header, pattern) if match?(header, pattern)
23
+ end
24
+
25
+ private
26
+
27
+ def token_from_basic_header(header, pattern)
28
+ encoded_header = token_from_header(header, pattern)
29
+ token, _ = decode_basic_credentials(encoded_header)
30
+ token
31
+ end
32
+
33
+ def decode_basic_credentials(encoded_header)
34
+ Base64.decode64(encoded_header).split(/:/, 2)
35
+ end
36
+
37
+ def token_from_header(header, pattern)
38
+ header.gsub pattern, ''
39
+ end
40
+
41
+ def match?(header, pattern)
42
+ header && header.match(pattern)
17
43
  end
18
44
  end
19
45
 
@@ -10,18 +10,28 @@ module Doorkeeper
10
10
  end
11
11
 
12
12
  def authorize
13
- @response = if pre_auth.authorizable?
13
+ if pre_auth.authorizable?
14
14
  auth = Authorization::Token.new(pre_auth, resource_owner)
15
15
  auth.issue_token
16
- CodeResponse.new pre_auth, auth, :response_on_fragment => true
16
+ @response = CodeResponse.new pre_auth,
17
+ auth,
18
+ response_on_fragment: true
17
19
  else
18
- ErrorResponse.from_request pre_auth, :redirect_uri => pre_auth.redirect_uri, :response_on_fragment => true
20
+ @response = error_response
19
21
  end
20
22
  end
21
23
 
22
24
  def deny
23
25
  pre_auth.error = :access_denied
24
- ErrorResponse.from_request(pre_auth, :redirect_uri => pre_auth.redirect_uri, :response_on_fragment => true)
26
+ error_response
27
+ end
28
+
29
+ private
30
+
31
+ def error_response
32
+ ErrorResponse.from_request pre_auth,
33
+ redirect_uri: pre_auth.redirect_uri,
34
+ response_on_fragment: true
25
35
  end
26
36
  end
27
37
  end
@@ -16,11 +16,11 @@ module Doorkeeper
16
16
  end
17
17
 
18
18
  def self.warn_if_using_mount_method!
19
- paths = ::Rails.application.config.paths["config/routes"] ||
20
- ::Rails.application.config.paths["config/routes.rb"]
19
+ paths = ::Rails.application.config.paths['config/routes'] ||
20
+ ::Rails.application.config.paths['config/routes.rb']
21
21
 
22
22
  paths.each do |path|
23
- if File.read(::Rails.root.join(path)) =~ %r[mount Doorkeeper::Engine]
23
+ if File.read(::Rails.root.join(path)) =~ %r{mount Doorkeeper::Engine}
24
24
  warn "\n[DOORKEEPER] `mount Doorkeeper::Engine` is not being used anymore. Please replace it with `use_doorkeeper` in your #{path} file\n"
25
25
  end
26
26
  end
@@ -34,16 +34,18 @@ module Doorkeeper
34
34
 
35
35
  def generate_routes!(options)
36
36
  @mapping = Mapper.new.map(&@block)
37
- routes.scope options[:scope] || 'oauth', :as => 'oauth' do
37
+ routes.scope options[:scope] || 'oauth', as: 'oauth' do
38
38
  map_route(:authorizations, :authorization_routes)
39
39
  map_route(:tokens, :token_routes)
40
+ map_route(:tokens, :revoke_routes)
40
41
  map_route(:applications, :application_routes)
41
42
  map_route(:authorized_applications, :authorized_applications_routes)
42
43
  map_route(:token_info, :token_info_routes)
43
44
  end
44
45
  end
45
46
 
46
- private
47
+ private
48
+
47
49
  def map_route(name, method)
48
50
  unless @mapping.skipped?(name)
49
51
  send method, @mapping[name]
@@ -51,39 +53,46 @@ module Doorkeeper
51
53
  end
52
54
 
53
55
  def authorization_routes(mapping)
54
- routes.resource(
55
- :authorization, :path => 'authorize',
56
- :only => [:create, :update, :destroy],
57
- :as => mapping[:as],
58
- :controller => mapping[:controllers]
59
- ) do
60
- routes.get '/:code', :action => :show, :on => :member
61
- routes.get '/', :action => :new, :on => :member
62
- end
56
+ routes.resource(
57
+ :authorization,
58
+ path: 'authorize',
59
+ only: [:create, :update, :destroy],
60
+ as: mapping[:as],
61
+ controller: mapping[:controllers]
62
+ ) do
63
+ routes.get '/:code', action: :show, on: :member
64
+ routes.get '/', action: :new, on: :member
65
+ end
63
66
  end
64
67
 
65
68
  def token_routes(mapping)
66
69
  routes.resource(
67
- :token, :path => 'token',
68
- :only => [:create], :as => mapping[:as],
69
- :controller => mapping[:controllers]
70
+ :token,
71
+ path: 'token',
72
+ only: [:create], as: mapping[:as],
73
+ controller: mapping[:controllers]
70
74
  )
71
75
  end
72
76
 
77
+ def revoke_routes(mapping)
78
+ routes.post 'revoke', controller: mapping[:controllers], action: :revoke
79
+ end
80
+
73
81
  def token_info_routes(mapping)
74
82
  routes.resource(
75
- :token_info, :path => 'token/info',
76
- :only => [:show], :as => mapping[:as],
77
- :controller => mapping[:controllers]
83
+ :token_info,
84
+ path: 'token/info',
85
+ only: [:show], as: mapping[:as],
86
+ controller: mapping[:controllers]
78
87
  )
79
88
  end
80
89
 
81
90
  def application_routes(mapping)
82
- routes.resources :applications, :controller => mapping[:controllers]
91
+ routes.resources :applications, controller: mapping[:controllers]
83
92
  end
84
93
 
85
94
  def authorized_applications_routes(mapping)
86
- routes.resources :authorized_applications, :only => [:index, :destroy], :controller => mapping[:controllers]
95
+ routes.resources :authorized_applications, only: [:index, :destroy], controller: mapping[:controllers]
87
96
  end
88
97
  end
89
98
  end