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
@@ -32,20 +32,20 @@ module Doorkeeper
32
32
 
33
33
  def get_error_response_from_exception(exception)
34
34
  error_name = case exception
35
- when Errors::InvalidTokenStrategy
36
- :unsupported_grant_type
37
- when Errors::InvalidAuthorizationStrategy
38
- :unsupported_response_type
39
- when Errors::MissingRequestStrategy
40
- :invalid_request
41
- end
35
+ when Errors::InvalidTokenStrategy
36
+ :unsupported_grant_type
37
+ when Errors::InvalidAuthorizationStrategy
38
+ :unsupported_response_type
39
+ when Errors::MissingRequestStrategy
40
+ :invalid_request
41
+ end
42
42
 
43
- OAuth::ErrorResponse.new :name => error_name, :state => params[:state]
43
+ OAuth::ErrorResponse.new name: error_name, state: params[:state]
44
44
  end
45
45
 
46
46
  def handle_token_exception(exception)
47
47
  error = get_error_response_from_exception exception
48
- self.headers.merge! error.headers
48
+ self.headers.merge! error.headers
49
49
  self.response_body = error.body.to_json
50
50
  self.status = error.status
51
51
  end
@@ -8,7 +8,7 @@ module Doorkeeper
8
8
  before_filter doorkeeper_for.filter_options do
9
9
  unless doorkeeper_for.validate_token(doorkeeper_token)
10
10
  @error = OAuth::InvalidTokenResponse.from_access_token(doorkeeper_token)
11
- headers.merge!(@error.headers.reject {|k, v| ['Content-Type'].include? k })
11
+ headers.merge!(@error.headers.reject { |k, v| ['Content-Type'].include? k })
12
12
  render_options = doorkeeper_unauthorized_render_options
13
13
 
14
14
  if render_options.nil? || render_options.empty?
@@ -6,19 +6,19 @@ module Doorkeeper
6
6
  include Doorkeeper::Models::Accessible
7
7
  include Doorkeeper::Models::Scopes
8
8
 
9
- belongs_to :application, :class_name => "Doorkeeper::Application", :inverse_of => :access_grants
9
+ belongs_to :application, class_name: 'Doorkeeper::Application', inverse_of: :access_grants
10
10
 
11
11
  if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
12
12
  attr_accessible :resource_owner_id, :application_id, :expires_in, :redirect_uri, :scopes
13
13
  end
14
14
 
15
- validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, :presence => true
16
- validates :token, :uniqueness => true
15
+ validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, presence: true
16
+ validates :token, uniqueness: true
17
17
 
18
- before_validation :generate_token, :on => :create
18
+ before_validation :generate_token, on: :create
19
19
 
20
20
  def self.authenticate(token)
21
- where(:token => token).first
21
+ where(token: token).first
22
22
  end
23
23
 
24
24
  private
@@ -6,32 +6,32 @@ module Doorkeeper
6
6
  include Doorkeeper::Models::Accessible
7
7
  include Doorkeeper::Models::Scopes
8
8
 
9
- belongs_to :application, :class_name => "Doorkeeper::Application", :inverse_of => :access_tokens
9
+ belongs_to :application, class_name: 'Doorkeeper::Application', inverse_of: :access_tokens
10
10
 
11
- validates :token, :presence => true
12
- validates :token, :uniqueness => true
13
- validates :refresh_token, :uniqueness => true, :if => :use_refresh_token?
11
+ validates :token, presence: true
12
+ validates :token, uniqueness: true
13
+ validates :refresh_token, uniqueness: true, if: :use_refresh_token?
14
14
 
15
15
  attr_accessor :use_refresh_token
16
16
  if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
17
17
  attr_accessible :application_id, :resource_owner_id, :expires_in, :scopes, :use_refresh_token
18
18
  end
19
19
 
20
- before_validation :generate_token, :on => :create
21
- before_validation :generate_refresh_token, :on => :create, :if => :use_refresh_token?
20
+ before_validation :generate_token, on: :create
21
+ before_validation :generate_refresh_token, on: :create, if: :use_refresh_token?
22
22
 
23
23
  def self.authenticate(token)
24
- where(:token => token).first
24
+ where(token: token).first
25
25
  end
26
26
 
27
27
  def self.by_refresh_token(refresh_token)
28
- where(:refresh_token => refresh_token).first
28
+ where(refresh_token: refresh_token).first
29
29
  end
30
30
 
31
31
  def self.revoke_all_for(application_id, resource_owner)
32
- where(:application_id => application_id,
33
- :resource_owner_id => resource_owner.id,
34
- :revoked_at => nil)
32
+ where(application_id: application_id,
33
+ resource_owner_id: resource_owner.id,
34
+ revoked_at: nil)
35
35
  .map(&:revoke)
36
36
  end
37
37
 
@@ -42,22 +42,27 @@ module Doorkeeper
42
42
  end
43
43
 
44
44
  def token_type
45
- "bearer"
45
+ 'bearer'
46
46
  end
47
47
 
48
48
  def use_refresh_token?
49
49
  self.use_refresh_token
50
50
  end
51
51
 
52
- def as_json(options={})
52
+ def as_json(options = {})
53
53
  {
54
- :resource_owner_id => self.resource_owner_id,
55
- :scopes => self.scopes,
56
- :expires_in_seconds => self.expires_in_seconds,
57
- :application => { :uid => self.application.uid }
54
+ resource_owner_id: self.resource_owner_id,
55
+ scopes: self.scopes,
56
+ expires_in_seconds: self.expires_in_seconds,
57
+ application: { uid: self.application.uid }
58
58
  }
59
59
  end
60
60
 
61
+ # It indicates whether the tokens have the same credential
62
+ def same_credential?(access_token)
63
+ application_id == access_token.application_id && resource_owner_id == access_token.resource_owner_id
64
+ end
65
+
61
66
  private
62
67
 
63
68
  def generate_refresh_token
@@ -67,6 +72,5 @@ module Doorkeeper
67
72
  def generate_token
68
73
  self.token = UniqueToken.generate
69
74
  end
70
-
71
75
  end
72
76
  end
@@ -7,18 +7,18 @@ module Doorkeeper
7
7
  self.table_name = "#{self.table_name_prefix}oauth_access_tokens#{self.table_name_suffix}".to_sym
8
8
 
9
9
  def self.delete_all_for(application_id, resource_owner)
10
- where(:application_id => application_id,
11
- :resource_owner_id => resource_owner.id).delete_all
10
+ where(application_id: application_id,
11
+ resource_owner_id: resource_owner.id).delete_all
12
12
  end
13
13
  private_class_method :delete_all_for
14
14
 
15
15
  def self.last_authorized_token_for(application, resource_owner_id)
16
- where(:application_id => application.id,
17
- :resource_owner_id => resource_owner_id,
18
- :revoked_at => nil).
19
- order('created_at desc').
20
- limit(1).
21
- first
16
+ where(application_id: application.id,
17
+ resource_owner_id: resource_owner_id,
18
+ revoked_at: nil).
19
+ order('created_at desc').
20
+ limit(1).
21
+ first
22
22
  end
23
23
  private_class_method :last_authorized_token_for
24
24
  end
@@ -7,9 +7,9 @@ module Doorkeeper
7
7
  self.table_name = "#{self.table_name_prefix}oauth_applications#{self.table_name_suffix}".to_sym
8
8
 
9
9
  if ActiveRecord::VERSION::MAJOR >= 4
10
- has_many :authorized_tokens, -> { where(revoked_at: nil) }, class_name: "AccessToken"
10
+ has_many :authorized_tokens, -> { where(revoked_at: nil) }, class_name: 'AccessToken'
11
11
  else
12
- has_many :authorized_tokens, class_name: "AccessToken", conditions: { revoked_at: nil }
12
+ has_many :authorized_tokens, class_name: 'AccessToken', conditions: { revoked_at: nil }
13
13
  end
14
14
  has_many :authorized_applications, through: :authorized_tokens, source: :application
15
15
 
@@ -18,9 +18,9 @@ module Doorkeeper
18
18
  end
19
19
 
20
20
  def self.authorized_for(resource_owner)
21
- joins(:authorized_applications)
22
- .where(Doorkeeper::AccessToken.table_name => { resource_owner_id: resource_owner.id, revoked_at: nil })
23
- .group(column_names_with_table.join(','))
21
+ joins(:authorized_applications).
22
+ where(Doorkeeper::AccessToken.table_name => { resource_owner_id: resource_owner.id, revoked_at: nil }).
23
+ group(column_names_with_table.join(','))
24
24
  end
25
25
  end
26
26
  end
@@ -2,15 +2,14 @@ module Doorkeeper
2
2
  class Application
3
3
  include Doorkeeper::OAuth::Helpers
4
4
 
5
- has_many :access_grants, :dependent => :destroy, :class_name => "Doorkeeper::AccessGrant"
6
- has_many :access_tokens, :dependent => :destroy, :class_name => "Doorkeeper::AccessToken"
5
+ has_many :access_grants, dependent: :destroy, class_name: 'Doorkeeper::AccessGrant'
6
+ has_many :access_tokens, dependent: :destroy, class_name: 'Doorkeeper::AccessToken'
7
7
 
8
- validates :name, :secret, :uid, :presence => true
9
- validates :uid, :uniqueness => true
10
- validates :redirect_uri, :redirect_uri => true
8
+ validates :name, :secret, :uid, presence: true
9
+ validates :uid, uniqueness: true
10
+ validates :redirect_uri, redirect_uri: true
11
11
 
12
-
13
- before_validation :generate_uid, :generate_secret, :on => :create
12
+ before_validation :generate_uid, :generate_secret, on: :create
14
13
 
15
14
  if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
16
15
  attr_accessible :name, :redirect_uri
@@ -21,11 +20,11 @@ module Doorkeeper
21
20
  end
22
21
 
23
22
  def self.authenticate(uid, secret)
24
- self.where(:uid => uid, :secret => secret).first
23
+ self.where(uid: uid, secret: secret).first
25
24
  end
26
25
 
27
26
  def self.by_uid(uid)
28
- self.where(:uid => uid).first
27
+ self.where(uid: uid).first
29
28
  end
30
29
 
31
30
  private
@@ -13,7 +13,7 @@ module Doorkeeper
13
13
  return nil if expires_in.nil?
14
14
  expires = (created_at + expires_in.seconds) - Time.now
15
15
  expires_sec = expires.seconds.round(0)
16
- expires_sec > 0 ? expires_sec : 0
16
+ expires_sec > 0 ? expires_sec : 0
17
17
  end
18
18
  private :expired_time
19
19
  end
@@ -7,7 +7,7 @@ module Doorkeeper
7
7
  safe
8
8
  timestamps!
9
9
 
10
- set_collection_name "oauth_access_grants"
10
+ set_collection_name 'oauth_access_grants'
11
11
 
12
12
  key :resource_owner_id, ObjectId
13
13
  key :application_id, ObjectId
@@ -22,7 +22,7 @@ module Doorkeeper
22
22
  end
23
23
 
24
24
  def self.create_indexes
25
- ensure_index :token, :unique => true
25
+ ensure_index :token, unique: true
26
26
  end
27
27
  end
28
28
  end
@@ -7,7 +7,7 @@ module Doorkeeper
7
7
  safe
8
8
  timestamps!
9
9
 
10
- set_collection_name "oauth_access_tokens"
10
+ set_collection_name 'oauth_access_tokens'
11
11
 
12
12
  key :resource_owner_id, ObjectId
13
13
  key :token, String
@@ -24,18 +24,18 @@ module Doorkeeper
24
24
  end
25
25
 
26
26
  def self.delete_all_for(application_id, resource_owner)
27
- delete_all(:application_id => application_id,
28
- :resource_owner_id => resource_owner.id)
27
+ delete_all(application_id: application_id,
28
+ resource_owner_id: resource_owner.id)
29
29
  end
30
30
  private_class_method :delete_all_for
31
31
 
32
32
  def self.last_authorized_token_for(application, resource_owner_id)
33
- where(:application_id => application.id,
34
- :resource_owner_id => resource_owner_id,
35
- :revoked_at => nil).
36
- sort(:created_at.desc).
37
- limit(1).
38
- first
33
+ where(application_id: application.id,
34
+ resource_owner_id: resource_owner_id,
35
+ revoked_at: nil).
36
+ sort(:created_at.desc).
37
+ limit(1).
38
+ first
39
39
  end
40
40
  private_class_method :last_authorized_token_for
41
41
 
@@ -44,8 +44,8 @@ module Doorkeeper
44
44
  end
45
45
 
46
46
  def self.create_indexes
47
- ensure_index :token, :unique => true
48
- ensure_index [[:refresh_token, 1]], :unique => true, :sparse => true
47
+ ensure_index :token, unique: true
48
+ ensure_index [[:refresh_token, 1]], unique: true, sparse: true
49
49
  end
50
50
  end
51
51
  end
@@ -4,9 +4,9 @@ module Doorkeeper
4
4
  safe
5
5
  timestamps!
6
6
 
7
- set_collection_name "oauth_applications"
7
+ set_collection_name 'oauth_applications'
8
8
 
9
- many :authorized_tokens, :class_name => "Doorkeeper::AccessToken"
9
+ many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
10
10
 
11
11
  key :name, String
12
12
  key :uid, String
@@ -19,12 +19,12 @@ module Doorkeeper
19
19
  end
20
20
 
21
21
  def self.authorized_for(resource_owner)
22
- ids = AccessToken.where(:resource_owner_id => resource_owner.id, :revoked_at => nil).map(&:application_id)
22
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
23
23
  find(ids)
24
24
  end
25
25
 
26
26
  def self.create_indexes
27
- ensure_index :uid, :unique => true
27
+ ensure_index :uid, unique: true
28
28
  end
29
29
  end
30
30
  end
@@ -3,11 +3,11 @@ module Doorkeeper
3
3
  module Mongoid
4
4
  module Version
5
5
  def mongoid3?
6
- ::Mongoid::VERSION.starts_with?("3")
6
+ ::Mongoid::VERSION.starts_with?('3')
7
7
  end
8
8
 
9
9
  def mongoid4?
10
- ::Mongoid::VERSION.starts_with?("4")
10
+ ::Mongoid::VERSION.starts_with?('4')
11
11
  end
12
12
  end
13
13
  end
@@ -10,13 +10,13 @@ module Doorkeeper
10
10
 
11
11
  self.store_in :oauth_access_grants
12
12
 
13
- field :resource_owner_id, :type => Integer
14
- field :application_id, :type => Hash
15
- field :token, :type => String
16
- field :expires_in, :type => Integer
17
- field :redirect_uri, :type => String
18
- field :revoked_at, :type => DateTime
13
+ field :resource_owner_id, type: Integer
14
+ field :application_id, type: Hash
15
+ field :token, type: String
16
+ field :expires_in, type: Integer
17
+ field :redirect_uri, type: String
18
+ field :revoked_at, type: DateTime
19
19
 
20
- index :token, :unique => true
20
+ index :token, unique: true
21
21
  end
22
22
  end
@@ -10,27 +10,27 @@ module Doorkeeper
10
10
 
11
11
  self.store_in :oauth_access_tokens
12
12
 
13
- field :resource_owner_id, :type => Integer
14
- field :token, :type => String
15
- field :expires_in, :type => Integer
16
- field :revoked_at, :type => DateTime
13
+ field :resource_owner_id, type: Integer
14
+ field :token, type: String
15
+ field :expires_in, type: Integer
16
+ field :revoked_at, type: DateTime
17
17
 
18
- index :token, :unique => true
19
- index :refresh_token, :unique => true, :sparse => true
18
+ index :token, unique: true
19
+ index :refresh_token, unique: true, sparse: true
20
20
 
21
21
  def self.delete_all_for(application_id, resource_owner)
22
- where(:application_id => application_id,
23
- :resource_owner_id => resource_owner.id).delete_all
22
+ where(application_id: application_id,
23
+ resource_owner_id: resource_owner.id).delete_all
24
24
  end
25
25
  private_class_method :delete_all_for
26
26
 
27
27
  def self.last_authorized_token_for(application, resource_owner_id)
28
- where(:application_id => application.id,
29
- :resource_owner_id => resource_owner_id,
30
- :revoked_at => nil).
31
- order_by([:created_at, :desc]).
32
- limit(1).
33
- first
28
+ where(application_id: application.id,
29
+ resource_owner_id: resource_owner_id,
30
+ revoked_at: nil).
31
+ order_by([:created_at, :desc]).
32
+ limit(1).
33
+ first
34
34
  end
35
35
  private_class_method :last_authorized_token_for
36
36
 
@@ -5,17 +5,17 @@ module Doorkeeper
5
5
 
6
6
  self.store_in :oauth_applications
7
7
 
8
- field :name, :type => String
9
- field :uid, :type => String
10
- field :secret, :type => String
11
- field :redirect_uri, :type => String
8
+ field :name, type: String
9
+ field :uid, type: String
10
+ field :secret, type: String
11
+ field :redirect_uri, type: String
12
12
 
13
- index :uid, :unique => true
13
+ index :uid, unique: true
14
14
 
15
- has_many :authorized_tokens, :class_name => "Doorkeeper::AccessToken"
15
+ has_many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
16
16
 
17
17
  def self.authorized_for(resource_owner)
18
- ids = AccessToken.where(:resource_owner_id => resource_owner.id, :revoked_at => nil).map(&:application_id)
18
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
19
19
  find(ids)
20
20
  end
21
21
  end