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,8 +1,8 @@
1
1
  module Doorkeeper::FormErrorsHelper
2
- def errors_for(object, method)
2
+ def doorkeeper_errors_for(object, method)
3
3
  if object.errors[method].present?
4
4
  object.errors[method].map do |msg|
5
- content_tag(:span, :class => "help-block") do
5
+ content_tag(:span, class: 'help-block') do
6
6
  msg.capitalize
7
7
  end
8
8
  end.reduce(&:join).html_safe
@@ -21,7 +21,7 @@ class RedirectUriValidator < ActiveModel::EachValidator
21
21
  record.errors.add(attribute, :invalid_uri)
22
22
  end
23
23
 
24
- private
24
+ private
25
25
 
26
26
  def test_redirect_uri?(uri)
27
27
  self.class.test_redirect_uri.present? && uri.to_s == self.class.test_redirect_uri.to_s
@@ -7,7 +7,7 @@
7
7
  <%= f.label :name, class: 'col-sm-2 control-label', for: 'application_name' %>
8
8
  <div class="col-sm-10">
9
9
  <%= f.text_field :name, class: 'form-control' %>
10
- <%= errors_for application, :name %>
10
+ <%= doorkeeper_errors_for application, :name %>
11
11
  </div>
12
12
  <% end %>
13
13
 
@@ -15,7 +15,7 @@
15
15
  <%= f.label :redirect_uri, class: 'col-sm-2 control-label', for: 'application_redirect_uri' %>
16
16
  <div class="col-sm-10">
17
17
  <%= f.text_area :redirect_uri, class: 'form-control' %>
18
- <%= errors_for application, :redirect_uri %>
18
+ <%= doorkeeper_errors_for application, :redirect_uri %>
19
19
  <span class="help-block">
20
20
  Use one line per URI
21
21
  </span>
@@ -29,7 +29,7 @@
29
29
 
30
30
  <div class="form-group">
31
31
  <div class="col-sm-offset-2 col-sm-10">
32
- <%= f.submit 'Submit', :class => "btn btn-primary" %>
32
+ <%= f.submit 'Submit', class: "btn btn-primary" %>
33
33
  <%= link_to "Cancel", oauth_applications_path, :class => "btn btn-default" %>
34
34
  </div>
35
35
  </div>
@@ -2,4 +2,4 @@
2
2
  <h1>Edit application</h1>
3
3
  </div>
4
4
 
5
- <%= render 'form', :application => @application %>
5
+ <%= render 'form', application: @application %>
@@ -2,4 +2,4 @@
2
2
  <h1>New application</h1>
3
3
  </div>
4
4
 
5
- <%= render 'form', :application => @application %>
5
+ <%= render 'form', application: @application %>
@@ -21,7 +21,7 @@
21
21
  <code><%= uri %></code>
22
22
  </td>
23
23
  <td>
24
- <%= link_to 'Authorize', oauth_authorization_path(:client_id => @application.uid, :redirect_uri => uri, :response_type => 'code'), class: 'btn btn-success', target: '_blank' %>
24
+ <%= link_to 'Authorize', oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code'), class: 'btn btn-success', target: '_blank' %>
25
25
  </td>
26
26
  </tr>
27
27
  <% end %>
@@ -13,28 +13,28 @@
13
13
 
14
14
  <ul class="text-info">
15
15
  <% @pre_auth.scopes.each do |scope| %>
16
- <li><%= t scope, :scope => [:doorkeeper, :scopes] %></li>
16
+ <li><%= t scope, scope: [:doorkeeper, :scopes] %></li>
17
17
  <% end %>
18
18
  </ul>
19
19
  </div>
20
20
  <% end %>
21
21
 
22
22
  <div class="actions">
23
- <%= form_tag oauth_authorization_path, :method => :post do %>
23
+ <%= form_tag oauth_authorization_path, method: :post do %>
24
24
  <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
25
25
  <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
26
26
  <%= hidden_field_tag :state, @pre_auth.state %>
27
27
  <%= hidden_field_tag :response_type, @pre_auth.response_type %>
28
28
  <%= hidden_field_tag :scope, @pre_auth.scope %>
29
- <%= submit_tag "Authorize", :class => "btn btn-success btn-lg btn-block" %>
29
+ <%= submit_tag "Authorize", class: "btn btn-success btn-lg btn-block" %>
30
30
  <% end %>
31
- <%= form_tag oauth_authorization_path, :method => :delete do %>
31
+ <%= form_tag oauth_authorization_path, method: :delete do %>
32
32
  <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
33
33
  <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
34
34
  <%= hidden_field_tag :state, @pre_auth.state %>
35
35
  <%= hidden_field_tag :response_type, @pre_auth.response_type %>
36
36
  <%= hidden_field_tag :scope, @pre_auth.scope %>
37
- <%= submit_tag "Deny", :class => "btn btn-danger btn-lg btn-block" %>
37
+ <%= submit_tag "Deny", class: "btn btn-danger btn-lg btn-block" %>
38
38
  <% end %>
39
39
  </div>
40
40
  </main>
data/doorkeeper.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Doorkeeper::VERSION
8
8
  s.authors = ["Felipe Elias Philipp", "Piotr Jakubowski"]
9
9
  s.email = ["felipe@applicake.com", "piotr.jakubowski@applicake.com"]
10
- s.homepage = "https://github.com/applicake/doorkeeper"
10
+ s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
11
11
  s.summary = "Doorkeeper is an OAuth 2 provider for Rails."
12
12
  s.description = "Doorkeeper is an OAuth 2 provider for Rails."
13
13
  s.license = 'MIT'
data/lib/doorkeeper.rb CHANGED
@@ -1,45 +1,45 @@
1
- require "doorkeeper/version"
2
- require "doorkeeper/engine"
3
- require "doorkeeper/config"
4
- require "doorkeeper/doorkeeper_for"
1
+ require 'doorkeeper/version'
2
+ require 'doorkeeper/engine'
3
+ require 'doorkeeper/config'
4
+ require 'doorkeeper/doorkeeper_for'
5
5
 
6
6
  require 'doorkeeper/errors'
7
7
  require 'doorkeeper/server'
8
8
  require 'doorkeeper/request'
9
- require "doorkeeper/validations"
10
-
11
- require "doorkeeper/oauth/authorization/code"
12
- require "doorkeeper/oauth/authorization/token"
13
- require "doorkeeper/oauth/authorization/uri_builder"
14
- require "doorkeeper/oauth/helpers/scope_checker"
15
- require "doorkeeper/oauth/helpers/uri_checker"
16
- require "doorkeeper/oauth/helpers/unique_token"
17
-
18
- require "doorkeeper/oauth/scopes"
19
- require "doorkeeper/oauth/error"
20
- require "doorkeeper/oauth/code_response"
21
- require "doorkeeper/oauth/token_response"
22
- require "doorkeeper/oauth/error_response"
23
- require "doorkeeper/oauth/pre_authorization"
24
- require "doorkeeper/oauth/authorization_code_request"
25
- require "doorkeeper/oauth/refresh_token_request"
26
- require "doorkeeper/oauth/password_access_token_request"
27
- require "doorkeeper/oauth/client_credentials_request"
28
- require "doorkeeper/oauth/code_request"
29
- require "doorkeeper/oauth/token_request"
30
- require "doorkeeper/oauth/client"
31
- require "doorkeeper/oauth/token"
32
- require "doorkeeper/oauth/invalid_token_response"
9
+ require 'doorkeeper/validations'
10
+
11
+ require 'doorkeeper/oauth/authorization/code'
12
+ require 'doorkeeper/oauth/authorization/token'
13
+ require 'doorkeeper/oauth/authorization/uri_builder'
14
+ require 'doorkeeper/oauth/helpers/scope_checker'
15
+ require 'doorkeeper/oauth/helpers/uri_checker'
16
+ require 'doorkeeper/oauth/helpers/unique_token'
17
+
18
+ require 'doorkeeper/oauth/scopes'
19
+ require 'doorkeeper/oauth/error'
20
+ require 'doorkeeper/oauth/code_response'
21
+ require 'doorkeeper/oauth/token_response'
22
+ require 'doorkeeper/oauth/error_response'
23
+ require 'doorkeeper/oauth/pre_authorization'
24
+ require 'doorkeeper/oauth/authorization_code_request'
25
+ require 'doorkeeper/oauth/refresh_token_request'
26
+ require 'doorkeeper/oauth/password_access_token_request'
27
+ require 'doorkeeper/oauth/client_credentials_request'
28
+ require 'doorkeeper/oauth/code_request'
29
+ require 'doorkeeper/oauth/token_request'
30
+ require 'doorkeeper/oauth/client'
31
+ require 'doorkeeper/oauth/token'
32
+ require 'doorkeeper/oauth/invalid_token_response'
33
33
 
34
34
  require 'doorkeeper/models/scopes'
35
35
  require 'doorkeeper/models/expirable'
36
36
  require 'doorkeeper/models/revocable'
37
37
  require 'doorkeeper/models/accessible'
38
38
 
39
- require "doorkeeper/helpers/filter"
40
- require "doorkeeper/helpers/controller"
39
+ require 'doorkeeper/helpers/filter'
40
+ require 'doorkeeper/helpers/controller'
41
41
 
42
- require "doorkeeper/rails/routes"
42
+ require 'doorkeeper/rails/routes'
43
43
 
44
44
  module Doorkeeper
45
45
  def self.configured?
@@ -1,7 +1,7 @@
1
1
  module Doorkeeper
2
2
  class MissingConfiguration < StandardError
3
3
  def initialize
4
- super("Configuration for doorkeeper missing. Do you have doorkeeper initializer?")
4
+ super('Configuration for doorkeeper missing. Do you have doorkeeper initializer?')
5
5
  end
6
6
  end
7
7
 
@@ -12,17 +12,16 @@ module Doorkeeper
12
12
  end
13
13
 
14
14
  def self.configuration
15
- @config || (raise MissingConfiguration.new)
15
+ @config || (fail MissingConfiguration.new)
16
16
  end
17
17
 
18
18
  def self.orm_model_dir
19
19
  case configuration.orm
20
20
  when :mongoid3, :mongoid4
21
- "mongoid3_4"
21
+ 'mongoid3_4'
22
22
  else
23
23
  configuration.orm
24
24
  end
25
-
26
25
  end
27
26
 
28
27
  def self.enable_orm
@@ -50,42 +49,41 @@ module Doorkeeper
50
49
  @config
51
50
  end
52
51
 
53
- def enable_application_owner(opts={})
54
- @config.instance_variable_set("@enable_application_owner", true)
52
+ def enable_application_owner(opts = {})
53
+ @config.instance_variable_set('@enable_application_owner', true)
55
54
  confirm_application_owner if opts[:confirmation].present? && opts[:confirmation]
56
55
  end
57
56
 
58
57
  def confirm_application_owner
59
- @config.instance_variable_set("@confirm_application_owner", true)
58
+ @config.instance_variable_set('@confirm_application_owner', true)
60
59
  end
61
60
 
62
61
  def default_scopes(*scopes)
63
- @config.instance_variable_set("@default_scopes", Doorkeeper::OAuth::Scopes.from_array(scopes))
62
+ @config.instance_variable_set('@default_scopes', Doorkeeper::OAuth::Scopes.from_array(scopes))
64
63
  end
65
64
 
66
65
  def optional_scopes(*scopes)
67
- @config.instance_variable_set("@optional_scopes", Doorkeeper::OAuth::Scopes.from_array(scopes))
66
+ @config.instance_variable_set('@optional_scopes', Doorkeeper::OAuth::Scopes.from_array(scopes))
68
67
  end
69
68
 
70
69
  def client_credentials(*methods)
71
- @config.instance_variable_set("@client_credentials", methods)
70
+ @config.instance_variable_set('@client_credentials', methods)
72
71
  end
73
72
 
74
73
  def access_token_methods(*methods)
75
- @config.instance_variable_set("@access_token_methods", methods)
74
+ @config.instance_variable_set('@access_token_methods', methods)
76
75
  end
77
76
 
78
77
  def use_refresh_token
79
- @config.instance_variable_set("@refresh_token_enabled", true)
78
+ @config.instance_variable_set('@refresh_token_enabled', true)
80
79
  end
81
80
 
82
81
  def realm(realm)
83
- @config.instance_variable_set("@realm", realm)
82
+ @config.instance_variable_set('@realm', realm)
84
83
  end
85
84
  end
86
85
 
87
86
  module Option
88
-
89
87
  # Defines configuration option
90
88
  #
91
89
  # When you call option, it defines two methods. One method will take place
@@ -109,9 +107,9 @@ module Doorkeeper
109
107
  # ==== Examples
110
108
  #
111
109
  # option :name
112
- # option :name, :as => :set_name
113
- # option :name, :default => "My Name"
114
- # option :scopes :builder_class => ScopesBuilder
110
+ # option :name, as: :set_name
111
+ # option :name, default: 'My Name'
112
+ # option :scopes builder_class: ScopesBuilder
115
113
  #
116
114
  def option(name, options = {})
117
115
  attribute = options[:as] || name
@@ -121,10 +119,10 @@ module Doorkeeper
121
119
  define_method name do |*args, &block|
122
120
  # TODO: is builder_class option being used?
123
121
  value = unless attribute_builder
124
- block ? block : args.first
125
- else
126
- attribute_builder.new(&block).build
127
- end
122
+ block ? block : args.first
123
+ else
124
+ attribute_builder.new(&block).build
125
+ end
128
126
 
129
127
  @config.instance_variable_set(:"@#{attribute}", value)
130
128
  end
@@ -149,27 +147,29 @@ module Doorkeeper
149
147
  extend Option
150
148
 
151
149
  option :resource_owner_authenticator,
152
- :as => :authenticate_resource_owner,
153
- :default => lambda{|routes|
150
+ as: :authenticate_resource_owner,
151
+ default: (lambda do |routes|
154
152
  logger.warn(I18n.translate('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))
155
153
  nil
156
- }
154
+ end)
157
155
  option :admin_authenticator,
158
- :as => :authenticate_admin,
159
- :default => lambda{|routes| }
156
+ as: :authenticate_admin,
157
+ default: ->(routes) {}
160
158
  option :resource_owner_from_credentials,
161
- :default => lambda{|routes|
159
+ default: (lambda do |routes|
162
160
  warn(I18n.translate('doorkeeper.errors.messages.credential_flow_not_configured'))
163
161
  nil
164
- }
165
- option :skip_authorization, :default => lambda{|routes|}
166
- option :access_token_expires_in, :default => 7200
167
- option :authorization_code_expires_in,:default => 600
168
- option :orm, :default => :active_record
169
- option :test_redirect_uri, :default => 'urn:ietf:wg:oauth:2.0:oob'
170
- option :active_record_options, :default => {}
171
- option :realm, :default => "Doorkeeper"
172
- option :wildcard_redirect_uri, :default => false
162
+ end)
163
+ option :skip_authorization, default: ->(routes) {}
164
+ option :access_token_expires_in, default: 7200
165
+ option :authorization_code_expires_in, default: 600
166
+ option :orm, default: :active_record
167
+ option :test_redirect_uri, default: 'urn:ietf:wg:oauth:2.0:oob'
168
+ option :active_record_options, default: {}
169
+ option :realm, default: 'Doorkeeper'
170
+ option :wildcard_redirect_uri, default: false
171
+ option :grant_flows,
172
+ default: %w(authorization_code implicit password client_credentials)
173
173
 
174
174
  def refresh_token_enabled?
175
175
  !!@refresh_token_enabled
@@ -208,7 +208,36 @@ module Doorkeeper
208
208
  end
209
209
 
210
210
  def realm
211
- @realm ||= "Doorkeeper"
211
+ @realm ||= 'Doorkeeper'
212
+ end
213
+
214
+ def authorization_response_types
215
+ @authorization_response_types ||= calculate_authorization_response_types
216
+ end
217
+
218
+ def token_grant_types
219
+ @token_grant_types ||= calculate_token_grant_types
220
+ end
221
+
222
+ private
223
+
224
+ # Determines what values are acceptable for 'response_type' param in
225
+ # authorization request endpoint, and return them as an array of strings.
226
+ #
227
+ def calculate_authorization_response_types
228
+ types = []
229
+ types << 'code' if grant_flows.include? 'authorization_code'
230
+ types << 'token' if grant_flows.include? 'implicit'
231
+ types
232
+ end
233
+
234
+ # Determines what values are acceptable for 'grant_type' param token
235
+ # request endpoint, and return them in array.
236
+ #
237
+ def calculate_token_grant_types
238
+ types = grant_flows - ['implicit']
239
+ types << 'refresh_token' if refresh_token_enabled?
240
+ types
212
241
  end
213
242
  end
214
243
  end
@@ -3,7 +3,7 @@ module Doorkeeper
3
3
  class DoorkeeperFor
4
4
  def initialize(options)
5
5
  options ||= {}
6
- raise InvalidSyntax unless options.is_a? Hash
6
+ fail InvalidSyntax unless options.is_a? Hash
7
7
  @filter_options = {}
8
8
 
9
9
  options.each do |k, v|
@@ -14,7 +14,7 @@ module Doorkeeper
14
14
  # TODO: move this to Token class
15
15
  def validate_token(token)
16
16
  return false unless token
17
- token.accessible? and validate_token_scopes(token)
17
+ token.accessible? && validate_token_scopes(token)
18
18
  end
19
19
 
20
20
  def filter_options
@@ -22,6 +22,7 @@ module Doorkeeper
22
22
  end
23
23
 
24
24
  private
25
+
25
26
  def scopes(scopes)
26
27
  @scopes = scopes.map(&:to_s)
27
28
  end
@@ -43,6 +44,7 @@ module Doorkeeper
43
44
 
44
45
  class AllDoorkeeperFor < DoorkeeperFor
45
46
  private
47
+
46
48
  def except(actions)
47
49
  @filter_options[:except] = actions
48
50
  end
@@ -56,6 +58,7 @@ module Doorkeeper
56
58
  end
57
59
 
58
60
  private
61
+
59
62
  def only(actions)
60
63
  @filter_options[:only] = actions
61
64
  end
@@ -67,7 +70,7 @@ module Doorkeeper
67
70
  when :all
68
71
  AllDoorkeeperFor.new(args[1] || {})
69
72
  when Hash, nil
70
- raise InvalidSyntax
73
+ fail InvalidSyntax
71
74
  else
72
75
  SelectedDoorkeeperFor.new(*args)
73
76
  end
@@ -1,11 +1,11 @@
1
1
  module Doorkeeper
2
2
  class Engine < Rails::Engine
3
- initializer "doorkeeper.routes" do
3
+ initializer 'doorkeeper.routes' do
4
4
  Doorkeeper::Rails::Routes.warn_if_using_mount_method!
5
5
  Doorkeeper::Rails::Routes.install!
6
6
  end
7
7
 
8
- initializer "doorkeeper.helpers" do
8
+ initializer 'doorkeeper.helpers' do
9
9
  ActiveSupport.on_load(:action_controller) do
10
10
  include Doorkeeper::Helpers::Filter
11
11
  end