doorkeeper 1.4.2 → 2.0.0.alpha1

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +3 -0
  3. data/CHANGELOG.md +18 -11
  4. data/Gemfile +7 -7
  5. data/README.md +20 -41
  6. data/app/controllers/doorkeeper/application_controller.rb +1 -7
  7. data/app/controllers/doorkeeper/applications_controller.rb +4 -5
  8. data/app/controllers/doorkeeper/tokens_controller.rb +2 -2
  9. data/app/helpers/doorkeeper/{form_errors_helper.rb → dashboard_helper.rb} +5 -1
  10. data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
  11. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  12. data/app/views/doorkeeper/applications/index.html.erb +1 -1
  13. data/config/locales/en.yml +3 -3
  14. data/lib/doorkeeper.rb +15 -6
  15. data/lib/doorkeeper/config.rb +18 -24
  16. data/lib/doorkeeper/engine.rb +1 -6
  17. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
  18. data/lib/{generators/doorkeeper → doorkeeper/generators/doorkeeper/mongo_mapper}/templates/indexes.rb +0 -0
  19. data/lib/doorkeeper/models/access_grant_mixin.rb +36 -0
  20. data/lib/doorkeeper/models/access_token_mixin.rb +121 -0
  21. data/lib/doorkeeper/models/application_mixin.rb +42 -0
  22. data/lib/doorkeeper/models/{accessible.rb → concerns/accessible.rb} +0 -0
  23. data/lib/doorkeeper/models/{expirable.rb → concerns/expirable.rb} +6 -5
  24. data/lib/doorkeeper/models/{ownership.rb → concerns/ownership.rb} +7 -7
  25. data/lib/doorkeeper/models/{revocable.rb → concerns/revocable.rb} +1 -1
  26. data/lib/doorkeeper/models/concerns/scopes.rb +17 -0
  27. data/lib/doorkeeper/oauth/authorization/token.rb +6 -6
  28. data/lib/doorkeeper/oauth/client.rb +1 -1
  29. data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
  30. data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -6
  31. data/lib/doorkeeper/oauth/token.rb +3 -2
  32. data/lib/doorkeeper/orm/active_record.rb +17 -0
  33. data/lib/doorkeeper/orm/active_record/access_grant.rb +7 -0
  34. data/lib/doorkeeper/orm/active_record/access_token.rb +20 -0
  35. data/lib/doorkeeper/{models → orm}/active_record/application.rb +1 -3
  36. data/lib/doorkeeper/orm/mongo_mapper.rb +11 -0
  37. data/lib/doorkeeper/{models → orm}/mongo_mapper/access_grant.rb +4 -5
  38. data/lib/doorkeeper/{models → orm}/mongo_mapper/access_token.rb +5 -8
  39. data/lib/doorkeeper/{models → orm}/mongo_mapper/application.rb +3 -4
  40. data/lib/doorkeeper/orm/mongoid2.rb +11 -0
  41. data/lib/doorkeeper/{models → orm}/mongoid2/access_grant.rb +5 -3
  42. data/lib/doorkeeper/{models → orm}/mongoid2/access_token.rb +10 -13
  43. data/lib/doorkeeper/{models → orm}/mongoid2/application.rb +2 -0
  44. data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
  45. data/lib/doorkeeper/orm/mongoid3.rb +11 -0
  46. data/lib/doorkeeper/orm/mongoid3/access_grant.rb +22 -0
  47. data/lib/doorkeeper/orm/mongoid3/access_token.rb +36 -0
  48. data/lib/doorkeeper/{models/mongoid3_4 → orm/mongoid3}/application.rb +2 -0
  49. data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
  50. data/lib/doorkeeper/orm/mongoid4.rb +11 -0
  51. data/lib/doorkeeper/orm/mongoid4/access_grant.rb +22 -0
  52. data/lib/doorkeeper/orm/mongoid4/access_token.rb +36 -0
  53. data/lib/doorkeeper/orm/mongoid4/application.rb +24 -0
  54. data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
  55. data/lib/doorkeeper/rails/helpers.rb +63 -0
  56. data/lib/doorkeeper/rails/routes.rb +1 -12
  57. data/lib/doorkeeper/request/code.rb +0 -1
  58. data/lib/doorkeeper/request/token.rb +0 -1
  59. data/lib/doorkeeper/server.rb +1 -1
  60. data/lib/doorkeeper/version.rb +1 -1
  61. data/lib/generators/doorkeeper/templates/initializer.rb +2 -1
  62. data/spec/controllers/applications_controller_spec.rb +4 -4
  63. data/spec/controllers/protected_resources_controller_spec.rb +25 -175
  64. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
  65. data/spec/dummy/app/controllers/metal_controller.rb +2 -2
  66. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
  67. data/spec/dummy/config/application.rb +2 -0
  68. data/spec/lib/config_spec.rb +16 -10
  69. data/spec/lib/models/expirable_spec.rb +1 -1
  70. data/spec/lib/models/revocable_spec.rb +8 -3
  71. data/spec/lib/models/scopes_spec.rb +3 -3
  72. data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
  73. data/spec/lib/oauth/token_request_spec.rb +28 -1
  74. data/spec/lib/oauth/token_spec.rb +1 -1
  75. data/spec/models/doorkeeper/application_spec.rb +1 -1
  76. data/spec/requests/applications/applications_request_spec.rb +4 -4
  77. data/spec/requests/endpoints/authorization_spec.rb +0 -23
  78. data/spec/requests/flows/implicit_grant_spec.rb +32 -0
  79. data/spec/support/shared/controllers_shared_context.rb +2 -2
  80. metadata +40 -35
  81. data/lib/doorkeeper/doorkeeper_for.rb +0 -69
  82. data/lib/doorkeeper/helpers/filter.rb +0 -64
  83. data/lib/doorkeeper/models/access_grant.rb +0 -30
  84. data/lib/doorkeeper/models/access_token.rb +0 -106
  85. data/lib/doorkeeper/models/active_record/access_grant.rb +0 -9
  86. data/lib/doorkeeper/models/active_record/access_token.rb +0 -25
  87. data/lib/doorkeeper/models/application.rb +0 -40
  88. data/lib/doorkeeper/models/mongoid/scopes.rb +0 -15
  89. data/lib/doorkeeper/models/mongoid/version.rb +0 -15
  90. data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +0 -27
  91. data/lib/doorkeeper/models/mongoid3_4/access_token.rb +0 -46
  92. data/lib/doorkeeper/models/scopes.rb +0 -21
  93. data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
  94. data/script/rails +0 -5
  95. data/script/run_all +0 -14
@@ -0,0 +1,11 @@
1
+ module Doorkeeper
2
+ module Orm
3
+ module MongoMapper
4
+ def self.initialize_models!
5
+ require 'doorkeeper/orm/mongo_mapper/access_grant'
6
+ require 'doorkeeper/orm/mongo_mapper/access_token'
7
+ require 'doorkeeper/orm/mongo_mapper/application'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,9 @@
1
1
  module Doorkeeper
2
2
  class AccessGrant
3
3
  include MongoMapper::Document
4
+
5
+ include AccessGrantMixin
6
+
4
7
  safe
5
8
  timestamps!
6
9
 
@@ -9,14 +12,10 @@ module Doorkeeper
9
12
  key :resource_owner_id, ObjectId
10
13
  key :application_id, ObjectId
11
14
  key :token, String
15
+ key :scopes, String
12
16
  key :expires_in, Integer
13
17
  key :redirect_uri, String
14
18
  key :revoked_at, DateTime
15
- key :scopes, String
16
-
17
- def scopes=(value)
18
- write_attribute :scopes, value if value.present?
19
- end
20
19
 
21
20
  def self.create_indexes
22
21
  ensure_index :token, unique: true
@@ -1,21 +1,22 @@
1
1
  module Doorkeeper
2
2
  class AccessToken
3
3
  include MongoMapper::Document
4
+
5
+ include AccessTokenMixin
6
+
4
7
  safe
5
8
  timestamps!
6
9
 
7
10
  set_collection_name 'oauth_access_tokens'
8
11
 
9
12
  key :resource_owner_id, ObjectId
13
+ key :application_id, ObjectId
10
14
  key :token, String
15
+ key :refresh_token, String
11
16
  key :expires_in, Integer
12
17
  key :revoked_at, DateTime
13
18
  key :scopes, String
14
19
 
15
- def scopes=(value)
16
- write_attribute :scopes, value if value.present?
17
- end
18
-
19
20
  def self.last
20
21
  self.sort(:created_at).last
21
22
  end
@@ -36,10 +37,6 @@ module Doorkeeper
36
37
  end
37
38
  private_class_method :last_authorized_token_for
38
39
 
39
- def refresh_token
40
- self[:refresh_token]
41
- end
42
-
43
40
  def self.create_indexes
44
41
  ensure_index :token, unique: true
45
42
  ensure_index [[:refresh_token, 1]], unique: true, sparse: true
@@ -1,6 +1,9 @@
1
1
  module Doorkeeper
2
2
  class Application
3
3
  include MongoMapper::Document
4
+
5
+ include ApplicationMixin
6
+
4
7
  safe
5
8
  timestamps!
6
9
 
@@ -14,10 +17,6 @@ module Doorkeeper
14
17
  key :redirect_uri, String
15
18
  key :scopes, String
16
19
 
17
- def scopes=(value)
18
- write_attribute :scopes, value if value.present?
19
- end
20
-
21
20
  def self.authorized_for(resource_owner)
22
21
  ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
23
22
  find(ids)
@@ -0,0 +1,11 @@
1
+ module Doorkeeper
2
+ module Orm
3
+ module Mongoid2
4
+ def self.initialize_models!
5
+ require 'doorkeeper/orm/mongoid2/access_grant'
6
+ require 'doorkeeper/orm/mongoid2/access_token'
7
+ require 'doorkeeper/orm/mongoid2/application'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,15 +1,17 @@
1
- require 'doorkeeper/models/mongoid/scopes'
1
+ require 'doorkeeper/orm/mongoid2/concerns/scopes'
2
2
 
3
3
  module Doorkeeper
4
4
  class AccessGrant
5
5
  include Mongoid::Document
6
6
  include Mongoid::Timestamps
7
- include Models::Mongoid::Scopes
7
+
8
+ include AccessGrantMixin
9
+ include Models::Mongoid2::Scopes
8
10
 
9
11
  self.store_in :oauth_access_grants
10
12
 
11
13
  field :resource_owner_id, type: Integer
12
- field :application_id, type: Hash
14
+ field :application_id, type: BSON::ObjectId
13
15
  field :token, type: String
14
16
  field :expires_in, type: Integer
15
17
  field :redirect_uri, type: String
@@ -1,15 +1,19 @@
1
- require 'doorkeeper/models/mongoid/scopes'
1
+ require 'doorkeeper/orm/mongoid2/concerns/scopes'
2
2
 
3
3
  module Doorkeeper
4
4
  class AccessToken
5
5
  include Mongoid::Document
6
6
  include Mongoid::Timestamps
7
- include Models::Mongoid::Scopes
7
+
8
+ include AccessTokenMixin
9
+ include Models::Mongoid2::Scopes
8
10
 
9
11
  self.store_in :oauth_access_tokens
10
12
 
11
13
  field :resource_owner_id, type: Integer
14
+ field :application_id, type: BSON::ObjectId
12
15
  field :token, type: String
16
+ field :refresh_token, type: String
13
17
  field :expires_in, type: Integer
14
18
  field :revoked_at, type: DateTime
15
19
 
@@ -22,18 +26,11 @@ module Doorkeeper
22
26
  end
23
27
  private_class_method :delete_all_for
24
28
 
25
- def self.last_authorized_token_for(application_id, resource_owner_id)
26
- where(application_id: application_id,
27
- resource_owner_id: resource_owner_id,
28
- revoked_at: nil).
29
- order_by([:created_at, :desc]).
30
- limit(1).
31
- first
29
+ def self.order_method
30
+ :order_by
32
31
  end
33
- private_class_method :last_authorized_token_for
34
-
35
- def refresh_token
36
- self[:refresh_token]
32
+ def self.created_at_desc
33
+ [:created_at, :desc]
37
34
  end
38
35
  end
39
36
  end
@@ -3,6 +3,8 @@ module Doorkeeper
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps
5
5
 
6
+ include ApplicationMixin
7
+
6
8
  self.store_in :oauth_applications
7
9
 
8
10
  field :name, type: String
@@ -0,0 +1,30 @@
1
+ module Doorkeeper
2
+ module Models
3
+ module Mongoid2
4
+ module Scopes
5
+ extend ActiveSupport::Concern
6
+
7
+ # It's strange that if not define these after included will raise error
8
+ # in Mongoid 2 and 3, but 4 works well see:
9
+ # https://travis-ci.org/jasl/doorkeeper/builds/31586902
10
+ included do
11
+ def scopes
12
+ OAuth::Scopes.from_string(self[:scopes])
13
+ end
14
+
15
+ def scopes_string
16
+ self[:scopes]
17
+ end
18
+
19
+ def includes_scope?(*required_scopes)
20
+ required_scopes.blank? || required_scopes.any? { |s| scopes.exists?(s.to_s) }
21
+ end
22
+
23
+ def scopes=(value)
24
+ write_attribute :scopes, value if value.present?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ module Doorkeeper
2
+ module Orm
3
+ module Mongoid3
4
+ def self.initialize_models!
5
+ require 'doorkeeper/orm/mongoid3/access_grant'
6
+ require 'doorkeeper/orm/mongoid3/access_token'
7
+ require 'doorkeeper/orm/mongoid3/application'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'doorkeeper/orm/mongoid3/concerns/scopes'
2
+
3
+ module Doorkeeper
4
+ class AccessGrant
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ include AccessGrantMixin
9
+ include Models::Mongoid3::Scopes
10
+
11
+ self.store_in collection: :oauth_access_grants
12
+
13
+ field :resource_owner_id, type: Moped::BSON::ObjectId
14
+ field :application_id, type: Moped::BSON::ObjectId
15
+ field :token, type: String
16
+ field :expires_in, type: Integer
17
+ field :redirect_uri, type: String
18
+ field :revoked_at, type: DateTime
19
+
20
+ index({ token: 1 }, { unique: true })
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require 'doorkeeper/orm/mongoid3/concerns/scopes'
2
+
3
+ module Doorkeeper
4
+ class AccessToken
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ include AccessTokenMixin
9
+ include Models::Mongoid3::Scopes
10
+
11
+ self.store_in collection: :oauth_access_tokens
12
+
13
+ field :resource_owner_id, type: Moped::BSON::ObjectId
14
+ field :application_id, type: Moped::BSON::ObjectId
15
+ field :token, type: String
16
+ field :refresh_token, type: String
17
+ field :expires_in, type: Integer
18
+ field :revoked_at, type: DateTime
19
+
20
+ index({ token: 1 }, { unique: true })
21
+ index({ refresh_token: 1 }, { unique: true, sparse: true })
22
+
23
+ def self.delete_all_for(application_id, resource_owner)
24
+ where(application_id: application_id,
25
+ resource_owner_id: resource_owner.id).delete_all
26
+ end
27
+ private_class_method :delete_all_for
28
+
29
+ def self.order_method
30
+ :order_by
31
+ end
32
+ def self.created_at_desc
33
+ [:created_at, :desc]
34
+ end
35
+ end
36
+ end
@@ -3,6 +3,8 @@ module Doorkeeper
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps
5
5
 
6
+ include ApplicationMixin
7
+
6
8
  self.store_in collection: :oauth_applications
7
9
 
8
10
  field :name, type: String
@@ -0,0 +1,30 @@
1
+ module Doorkeeper
2
+ module Models
3
+ module Mongoid3
4
+ module Scopes
5
+ extend ActiveSupport::Concern
6
+
7
+ # It's strange that if not define these after included will raise error
8
+ # in Mongoid 2 and 3, but 4 works well see:
9
+ # https://travis-ci.org/jasl/doorkeeper/builds/31586902
10
+ included do
11
+ def scopes
12
+ OAuth::Scopes.from_string(self[:scopes])
13
+ end
14
+
15
+ def scopes_string
16
+ self[:scopes]
17
+ end
18
+
19
+ def includes_scope?(*required_scopes)
20
+ required_scopes.blank? || required_scopes.any? { |s| scopes.exists?(s.to_s) }
21
+ end
22
+
23
+ def scopes=(value)
24
+ write_attribute :scopes, value if value.present?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ module Doorkeeper
2
+ module Orm
3
+ module Mongoid4
4
+ def self.initialize_models!
5
+ require 'doorkeeper/orm/mongoid4/access_grant'
6
+ require 'doorkeeper/orm/mongoid4/access_token'
7
+ require 'doorkeeper/orm/mongoid4/application'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'doorkeeper/orm/mongoid4/concerns/scopes'
2
+
3
+ module Doorkeeper
4
+ class AccessGrant
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ include AccessGrantMixin
9
+ include Models::Mongoid4::Scopes
10
+
11
+ self.store_in collection: :oauth_access_grants
12
+
13
+ field :resource_owner_id, type: BSON::ObjectId
14
+ field :application_id, type: BSON::ObjectId
15
+ field :token, type: String
16
+ field :expires_in, type: Integer
17
+ field :redirect_uri, type: String
18
+ field :revoked_at, type: DateTime
19
+
20
+ index({ token: 1 }, { unique: true })
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require 'doorkeeper/orm/mongoid4/concerns/scopes'
2
+
3
+ module Doorkeeper
4
+ class AccessToken
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ include AccessTokenMixin
9
+ include Models::Mongoid4::Scopes
10
+
11
+ self.store_in collection: :oauth_access_tokens
12
+
13
+ field :resource_owner_id, type: BSON::ObjectId
14
+ field :application_id, type: BSON::ObjectId
15
+ field :token, type: String
16
+ field :refresh_token, type: String
17
+ field :expires_in, type: Integer
18
+ field :revoked_at, type: DateTime
19
+
20
+ index({ token: 1 }, { unique: true })
21
+ index({ refresh_token: 1 }, { unique: true, sparse: true })
22
+
23
+ def self.delete_all_for(application_id, resource_owner)
24
+ where(application_id: application_id,
25
+ resource_owner_id: resource_owner.id).delete_all
26
+ end
27
+ private_class_method :delete_all_for
28
+
29
+ def self.order_method
30
+ :order_by
31
+ end
32
+ def self.created_at_desc
33
+ [:created_at, :desc]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ module Doorkeeper
2
+ class Application
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ include ApplicationMixin
7
+
8
+ self.store_in collection: :oauth_applications
9
+
10
+ field :name, type: String
11
+ field :uid, type: String
12
+ field :secret, type: String
13
+ field :redirect_uri, type: String
14
+
15
+ index({ uid: 1 }, { unique: true })
16
+
17
+ has_many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
18
+
19
+ def self.authorized_for(resource_owner)
20
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
21
+ find(ids)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module Doorkeeper
2
+ module Models
3
+ module Mongoid4
4
+ module Scopes
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ field :scopes, type: String
9
+ end
10
+
11
+ def scopes=(value)
12
+ write_attribute :scopes, value if value.present?
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end