doorkeeper-mongodb 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +59 -0
  4. data/Rakefile +23 -0
  5. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
  6. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/templates/indexes.rb +3 -0
  7. data/lib/doorkeeper/orm/mongo_mapper/access_grant.rb +28 -0
  8. data/lib/doorkeeper/orm/mongo_mapper/access_token.rb +47 -0
  9. data/lib/doorkeeper/orm/mongo_mapper/application.rb +32 -0
  10. data/lib/doorkeeper/orm/mongo_mapper.rb +19 -0
  11. data/lib/doorkeeper/orm/mongoid2/access_grant.rb +24 -0
  12. data/lib/doorkeeper/orm/mongoid2/access_token.rb +39 -0
  13. data/lib/doorkeeper/orm/mongoid2/application.rb +25 -0
  14. data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
  15. data/lib/doorkeeper/orm/mongoid2.rb +19 -0
  16. data/lib/doorkeeper/orm/mongoid3/access_grant.rb +24 -0
  17. data/lib/doorkeeper/orm/mongoid3/access_token.rb +39 -0
  18. data/lib/doorkeeper/orm/mongoid3/application.rb +25 -0
  19. data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
  20. data/lib/doorkeeper/orm/mongoid3.rb +19 -0
  21. data/lib/doorkeeper/orm/mongoid4/access_grant.rb +24 -0
  22. data/lib/doorkeeper/orm/mongoid4/access_token.rb +43 -0
  23. data/lib/doorkeeper/orm/mongoid4/application.rb +25 -0
  24. data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
  25. data/lib/doorkeeper/orm/mongoid4.rb +19 -0
  26. data/lib/doorkeeper/orm/mongoid5/access_grant.rb +24 -0
  27. data/lib/doorkeeper/orm/mongoid5/access_token.rb +43 -0
  28. data/lib/doorkeeper/orm/mongoid5/application.rb +25 -0
  29. data/lib/doorkeeper/orm/mongoid5/concerns/scopes.rb +17 -0
  30. data/lib/doorkeeper/orm/mongoid5.rb +19 -0
  31. data/lib/doorkeeper-mongodb/compatible.rb +20 -0
  32. data/lib/doorkeeper-mongodb/version.rb +3 -0
  33. data/lib/doorkeeper-mongodb.rb +12 -0
  34. data/spec/dummy/app/models/user.rb +28 -0
  35. data/spec/dummy/config/mongo.yml +11 -0
  36. data/spec/dummy/config/mongoid2.yml +9 -0
  37. data/spec/dummy/config/mongoid3.yml +18 -0
  38. data/spec/dummy/config/mongoid4.yml +19 -0
  39. data/spec/dummy/config/mongoid5.yml +19 -0
  40. data/spec/support/orm/mongo_mapper.rb +10 -0
  41. data/spec/support/orm/mongoid.rb +10 -0
  42. data/spec/support/orm/mongoid2.rb +1 -0
  43. data/spec/support/orm/mongoid3.rb +1 -0
  44. data/spec/support/orm/mongoid4.rb +1 -0
  45. data/spec/support/orm/mongoid5.rb +4 -0
  46. metadata +212 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0653c7a5c66cda01f16607d64ed329c0dc1482e6
4
+ data.tar.gz: f991560b9f7225891dac3b7ae0d19ca50a7c0af6
5
+ SHA512:
6
+ metadata.gz: 9f4c220c1e65edb96fa5194fcbd9d5ba6e9e53c0368d164d9def8d90ae49e04a9bdb61768fbfe4e2d5b2bc95f5dc390a70c4220787e5dab2ebf54e6cde83e57b
7
+ data.tar.gz: bf33001a0d46ebc5693a28e797d5326bbe6dfa1057f241607c52c117edfaffe64cb2c28f4967984b1a85b5b4b9477d29d8dc3f6d1b9769907edca87350cb6173
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Jasl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # doorkeeper-mongodb extension
2
+
3
+ ## Installation
4
+
5
+ doorkeeper-mongodb provides doorkeeper support to MongoMapper, Mongoid 2, 3, 4 and 5.
6
+ To start using it, add to your Gemfile:
7
+
8
+ ``` ruby
9
+ gem "doorkeeper-mongodb", github: "doorkeeper-gem/doorkeeper-mongodb"
10
+ ```
11
+
12
+ Run [doorkeeper’s installation generator]:
13
+
14
+ rails generate doorkeeper:install
15
+
16
+ [doorkeeper’s installation generator]: https://github.com/doorkeeper-gem/doorkeeper#installation
17
+
18
+ This will install the doorkeeper initializer into
19
+ `config/initializers/doorkeeper.rb`.
20
+
21
+ Set the ORM configuration:
22
+
23
+ ``` ruby
24
+ Doorkeeper.configure do
25
+ orm :mongoid2 # or :mongoid3, :mongoid4, :mongoid5, :mongo_mapper
26
+ end
27
+ ```
28
+
29
+ ### Mongoid indexes
30
+
31
+ Make sure you create indexes for doorkeeper models. You can do this either by
32
+ running `rake db:mongoid:create_indexes` or (if you're using Mongoid 2) by
33
+ adding `autocreate_indexes: true` to your `config/mongoid.yml`
34
+
35
+
36
+ ### MongoMapper indexes
37
+
38
+ Generate the `db/indexes.rb` file and create indexes for the doorkeeper models:
39
+
40
+ rails generate doorkeeper:mongo_mapper:indexes
41
+ rake db:index
42
+
43
+
44
+ ## Tests
45
+
46
+ To run tests, clone this repository and run `rake`. It will copy and run
47
+ doorkeeper’s original test suite, after configuring the ORM according to the
48
+ variables defined in `.travis.yml` file.
49
+
50
+ To run locally, you need to choose a gemfile, with a command similar to:
51
+
52
+ ```
53
+ $ export BUNDLE_GEMFILE=$PWD/gemfiles/Gemfile.mongoid4.rb
54
+ ```
55
+
56
+ ---
57
+
58
+ Please refer to https://github.com/doorkeeper-gem/doorkeeper for instructions on
59
+ doorkeeper’s project.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/setup'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :load_doorkeeper do
5
+ `rm -rf spec/`
6
+ `git checkout spec`
7
+ `git submodule init`
8
+ `git submodule update`
9
+ `cp -r -n doorkeeper/spec .`
10
+ `bundle exec rspec`
11
+ end
12
+
13
+ desc 'Default: run specs.'
14
+ task default: :spec
15
+
16
+ desc 'Clone down doorkeeper specs'
17
+ task spec: :load_doorkeeper
18
+
19
+ RSpec::Core::RakeTask.new(:spec) do |config|
20
+ config.verbose = false
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,12 @@
1
+ module Doorkeeper
2
+ module MongoMapper
3
+ class IndexesGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('templates', __FILE__)
5
+ desc "'Creates an indexes file for use with MongoMapper's rake db:index'"
6
+
7
+ def install
8
+ template 'indexes.rb', 'db/indexes.rb'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ Doorkeeper::Application.create_indexes
2
+ Doorkeeper::AccessGrant.create_indexes
3
+ Doorkeeper::AccessToken.create_indexes
@@ -0,0 +1,28 @@
1
+ require 'doorkeeper-mongodb/compatible'
2
+
3
+ module Doorkeeper
4
+ class AccessGrant
5
+ include DoorkeeperMongodb::Compatible
6
+
7
+ include MongoMapper::Document
8
+
9
+ include AccessGrantMixin
10
+
11
+ safe
12
+ timestamps!
13
+
14
+ set_collection_name 'oauth_access_grants'
15
+
16
+ key :resource_owner_id, ObjectId
17
+ key :application_id, ObjectId
18
+ key :token, String
19
+ key :scopes, String
20
+ key :expires_in, Integer
21
+ key :redirect_uri, String
22
+ key :revoked_at, DateTime
23
+
24
+ def self.create_indexes
25
+ ensure_index :token, unique: true
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ require 'doorkeeper-mongodb/compatible'
2
+
3
+ module Doorkeeper
4
+ class AccessToken
5
+ include DoorkeeperMongodb::Compatible
6
+
7
+ include MongoMapper::Document
8
+
9
+ include AccessTokenMixin
10
+
11
+ safe
12
+ timestamps!
13
+
14
+ set_collection_name 'oauth_access_tokens'
15
+
16
+ key :resource_owner_id, ObjectId
17
+ key :application_id, ObjectId
18
+ key :token, String
19
+ key :refresh_token, String
20
+ key :expires_in, Integer
21
+ key :revoked_at, DateTime
22
+ key :scopes, String
23
+
24
+ def self.last
25
+ self.sort(:created_at).last
26
+ end
27
+
28
+ def self.delete_all_for(application_id, resource_owner)
29
+ delete_all(application_id: application_id,
30
+ resource_owner_id: resource_owner.id)
31
+ end
32
+ private_class_method :delete_all_for
33
+
34
+ def self.create_indexes
35
+ ensure_index :token, unique: true
36
+ ensure_index [[:refresh_token, 1]], unique: true, sparse: true
37
+ end
38
+
39
+ def self.order_method
40
+ :sort
41
+ end
42
+
43
+ def self.created_at_desc
44
+ :created_at.desc
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,32 @@
1
+ module Doorkeeper
2
+ class Application
3
+ include MongoMapper::Document
4
+
5
+ include ApplicationMixin
6
+
7
+ safe
8
+ timestamps!
9
+
10
+ set_collection_name 'oauth_applications'
11
+
12
+ many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
13
+
14
+ key :name, String
15
+ key :uid, String
16
+ key :secret, String
17
+ key :redirect_uri, String
18
+ key :scopes, String
19
+
20
+ def self.authorized_for(resource_owner)
21
+ ids = AccessToken.where(
22
+ resource_owner_id: resource_owner.id,
23
+ revoked_at: nil
24
+ ).map(&:application_id)
25
+ find(ids)
26
+ end
27
+
28
+ def self.create_indexes
29
+ ensure_index :uid, unique: true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
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
+
10
+ def self.initialize_application_owner!
11
+ require 'doorkeeper/models/concerns/ownership'
12
+
13
+ Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
14
+ end
15
+
16
+ def self.check_requirements!(_config); end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'doorkeeper/orm/mongoid2/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessGrant
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessGrantMixin
12
+ include Models::Mongoid2::Scopes
13
+
14
+ self.store_in :oauth_access_grants
15
+
16
+ field :resource_owner_id, type: Integer
17
+ field :token, type: String
18
+ field :expires_in, type: Integer
19
+ field :redirect_uri, type: String
20
+ field :revoked_at, type: DateTime
21
+
22
+ index :token, unique: true
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'doorkeeper/orm/mongoid2/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessToken
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessTokenMixin
12
+ include Models::Mongoid2::Scopes
13
+
14
+ self.store_in :oauth_access_tokens
15
+
16
+ field :resource_owner_id, type: Integer
17
+ field :token, type: String
18
+ field :refresh_token, type: String
19
+ field :expires_in, type: Integer
20
+ field :revoked_at, type: DateTime
21
+
22
+ index :token, unique: true
23
+ index :refresh_token, unique: true, sparse: true
24
+
25
+ def self.delete_all_for(application_id, resource_owner)
26
+ where(application_id: application_id,
27
+ resource_owner_id: resource_owner.id).delete_all
28
+ end
29
+ private_class_method :delete_all_for
30
+
31
+ def self.order_method
32
+ :order_by
33
+ end
34
+
35
+ def self.created_at_desc
36
+ [:created_at, :desc]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ module Doorkeeper
2
+ class Application
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Models::Mongoid2::Scopes
6
+
7
+ include ApplicationMixin
8
+
9
+ self.store_in :oauth_applications
10
+
11
+ field :name, type: String
12
+ field :uid, type: String
13
+ field :secret, type: String
14
+ field :redirect_uri, type: String
15
+
16
+ index :uid, unique: true
17
+
18
+ has_many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
19
+
20
+ def self.authorized_for(resource_owner)
21
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
22
+ find(ids)
23
+ end
24
+ end
25
+ end
@@ -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
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
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
+
10
+ def self.initialize_application_owner!
11
+ require 'doorkeeper/models/concerns/ownership'
12
+
13
+ Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
14
+ end
15
+
16
+ def self.check_requirements!(_config); end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'doorkeeper/orm/mongoid3/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessGrant
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessGrantMixin
12
+ include Models::Mongoid3::Scopes
13
+
14
+ self.store_in collection: :oauth_access_grants
15
+
16
+ field :resource_owner_id, type: Moped::BSON::ObjectId
17
+ field :token, type: String
18
+ field :expires_in, type: Integer
19
+ field :redirect_uri, type: String
20
+ field :revoked_at, type: DateTime
21
+
22
+ index({ token: 1 }, { unique: true })
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'doorkeeper/orm/mongoid3/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessToken
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessTokenMixin
12
+ include Models::Mongoid3::Scopes
13
+
14
+ self.store_in collection: :oauth_access_tokens
15
+
16
+ field :resource_owner_id, type: Moped::BSON::ObjectId
17
+ field :token, type: String
18
+ field :refresh_token, type: String
19
+ field :expires_in, type: Integer
20
+ field :revoked_at, type: DateTime
21
+
22
+ index({ token: 1 }, { unique: true })
23
+ index({ refresh_token: 1 }, { unique: true, sparse: true })
24
+
25
+ def self.delete_all_for(application_id, resource_owner)
26
+ where(application_id: application_id,
27
+ resource_owner_id: resource_owner.id).delete_all
28
+ end
29
+ private_class_method :delete_all_for
30
+
31
+ def self.order_method
32
+ :order_by
33
+ end
34
+
35
+ def self.created_at_desc
36
+ [:created_at, :desc]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ module Doorkeeper
2
+ class Application
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Models::Mongoid3::Scopes
6
+
7
+ include ApplicationMixin
8
+
9
+ self.store_in collection: :oauth_applications
10
+
11
+ field :name, type: String
12
+ field :uid, type: String
13
+ field :secret, type: String
14
+ field :redirect_uri, type: String
15
+
16
+ index({ uid: 1 }, { unique: true })
17
+
18
+ has_many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
19
+
20
+ def self.authorized_for(resource_owner)
21
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
22
+ find(ids)
23
+ end
24
+ end
25
+ end
@@ -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
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
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
+
10
+ def self.initialize_application_owner!
11
+ require 'doorkeeper/models/concerns/ownership'
12
+
13
+ Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
14
+ end
15
+
16
+ def self.check_requirements!(_config); end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'doorkeeper/orm/mongoid4/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessGrant
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessGrantMixin
12
+ include Models::Mongoid4::Scopes
13
+
14
+ self.store_in collection: :oauth_access_grants
15
+
16
+ field :resource_owner_id, type: BSON::ObjectId
17
+ field :token, type: String
18
+ field :expires_in, type: Integer
19
+ field :redirect_uri, type: String
20
+ field :revoked_at, type: DateTime
21
+
22
+ index({ token: 1 }, { unique: true })
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ require 'doorkeeper/orm/mongoid4/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessToken
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessTokenMixin
12
+ include Models::Mongoid4::Scopes
13
+
14
+ self.store_in collection: :oauth_access_tokens
15
+
16
+ field :resource_owner_id, type: BSON::ObjectId
17
+ field :token, type: String
18
+ field :refresh_token, type: String
19
+ field :expires_in, type: Integer
20
+ field :revoked_at, type: DateTime
21
+
22
+ index({ token: 1 }, { unique: true })
23
+ index({ refresh_token: 1 }, { unique: true, sparse: true })
24
+
25
+ def self.delete_all_for(application_id, resource_owner)
26
+ where(application_id: application_id,
27
+ resource_owner_id: resource_owner.id).delete_all
28
+ end
29
+ private_class_method :delete_all_for
30
+
31
+ def self.order_method
32
+ :order_by
33
+ end
34
+
35
+ def self.refresh_token_revoked_on_use?
36
+ fields.collect { |field| field[0] }.include?('previous_refresh_token')
37
+ end
38
+
39
+ def self.created_at_desc
40
+ [:created_at, :desc]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ module Doorkeeper
2
+ class Application
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Models::Mongoid4::Scopes
6
+
7
+ include ApplicationMixin
8
+
9
+ self.store_in collection: :oauth_applications
10
+
11
+ field :name, type: String
12
+ field :uid, type: String
13
+ field :secret, type: String
14
+ field :redirect_uri, type: String
15
+
16
+ index({ uid: 1 }, { unique: true })
17
+
18
+ has_many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
19
+
20
+ def self.authorized_for(resource_owner)
21
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
22
+ find(ids)
23
+ end
24
+ end
25
+ 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
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
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
+
10
+ def self.initialize_application_owner!
11
+ require 'doorkeeper/models/concerns/ownership'
12
+
13
+ Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
14
+ end
15
+
16
+ def self.check_requirements!(_config); end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'doorkeeper/orm/mongoid5/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessGrant
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessGrantMixin
12
+ include Models::Mongoid5::Scopes
13
+
14
+ self.store_in collection: :oauth_access_grants
15
+
16
+ field :resource_owner_id, type: BSON::ObjectId
17
+ field :token, type: String
18
+ field :expires_in, type: Integer
19
+ field :redirect_uri, type: String
20
+ field :revoked_at, type: DateTime
21
+
22
+ index({ token: 1 }, { unique: true })
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ require 'doorkeeper/orm/mongoid5/concerns/scopes'
2
+ require 'doorkeeper-mongodb/compatible'
3
+
4
+ module Doorkeeper
5
+ class AccessToken
6
+ include DoorkeeperMongodb::Compatible
7
+
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+
11
+ include AccessTokenMixin
12
+ include Models::Mongoid5::Scopes
13
+
14
+ self.store_in collection: :oauth_access_tokens
15
+
16
+ field :resource_owner_id, type: BSON::ObjectId
17
+ field :token, type: String
18
+ field :refresh_token, type: String
19
+ field :expires_in, type: Integer
20
+ field :revoked_at, type: DateTime
21
+
22
+ index({ token: 1 }, { unique: true })
23
+ index({ refresh_token: 1 }, { unique: true, sparse: true })
24
+
25
+ def self.delete_all_for(application_id, resource_owner)
26
+ where(application_id: application_id,
27
+ resource_owner_id: resource_owner.id).delete_all
28
+ end
29
+ private_class_method :delete_all_for
30
+
31
+ def self.order_method
32
+ :order_by
33
+ end
34
+
35
+ def self.refresh_token_revoked_on_use?
36
+ self.fields.collect {|field| field[0]}.include?('previous_refresh_token')
37
+ end
38
+
39
+ def self.created_at_desc
40
+ [:created_at, :desc]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ module Doorkeeper
2
+ class Application
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ include Models::Mongoid5::Scopes
6
+
7
+ include ApplicationMixin
8
+
9
+ self.store_in collection: :oauth_applications
10
+
11
+ field :name, type: String
12
+ field :uid, type: String
13
+ field :secret, type: String
14
+ field :redirect_uri, type: String
15
+
16
+ index({ uid: 1 }, { unique: true })
17
+
18
+ has_many :authorized_tokens, class_name: 'Doorkeeper::AccessToken'
19
+
20
+ def self.authorized_for(resource_owner)
21
+ ids = AccessToken.where(resource_owner_id: resource_owner.id, revoked_at: nil).map(&:application_id)
22
+ find(ids)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module Doorkeeper
2
+ module Models
3
+ module Mongoid5
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
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Doorkeeper
2
+ module Orm
3
+ module Mongoid5
4
+ def self.initialize_models!
5
+ require 'doorkeeper/orm/mongoid5/access_grant'
6
+ require 'doorkeeper/orm/mongoid5/access_token'
7
+ require 'doorkeeper/orm/mongoid5/application'
8
+ end
9
+
10
+ def self.initialize_application_owner!
11
+ require 'doorkeeper/models/concerns/ownership'
12
+
13
+ Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
14
+ end
15
+
16
+ def self.check_requirements!(_config); end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module DoorkeeperMongodb
2
+ module Compatible
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def transaction(_ = {}, &block)
7
+ yield
8
+ end
9
+ end
10
+
11
+ def transaction(options = {}, &block)
12
+ self.class.transaction(options, &block)
13
+ end
14
+
15
+ def lock!(_ = true)
16
+ reload if persisted?
17
+ self
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module DoorkeeperMongodb
2
+ VERSION = "3.0.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'doorkeeper-mongodb/version'
2
+
3
+ require 'doorkeeper'
4
+
5
+ require 'doorkeeper/orm/mongoid2'
6
+ require 'doorkeeper/orm/mongoid3'
7
+ require 'doorkeeper/orm/mongoid4'
8
+ require 'doorkeeper/orm/mongoid5'
9
+ require 'doorkeeper/orm/mongo_mapper'
10
+
11
+ module DoorkeeperMongodb
12
+ end
@@ -0,0 +1,28 @@
1
+ case DOORKEEPER_ORM.to_s
2
+ when /mongoid/
3
+ class User
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :name, type: String
8
+ field :password, type: String
9
+ end
10
+ when "mongo_mapper"
11
+ class User
12
+ include MongoMapper::Document
13
+ timestamps!
14
+
15
+ key :name, String
16
+ key :password, String
17
+ end
18
+ end
19
+
20
+ class User
21
+ if ::Rails.version.to_i < 4 || defined?(::ProtectedAttributes)
22
+ attr_accessible :name, :password
23
+ end
24
+
25
+ def self.authenticate!(name, password)
26
+ User.where(name: name, password: password).first
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ defaults: &defaults
2
+ host: 127.0.0.1
3
+ port: 27017
4
+
5
+ development:
6
+ <<: *defaults
7
+ database: doorkeeper-mongomapper-development
8
+
9
+ test:
10
+ <<: *defaults
11
+ database: doorkeeper-mongomapper-test-suite
@@ -0,0 +1,9 @@
1
+ development:
2
+ database: doorkeeper-development
3
+ persist_in_safe_mode: true
4
+ autocreate_indexes: true
5
+
6
+ test:
7
+ database: doorkeeper-mongoid2-test
8
+ persist_in_safe_mode: true
9
+ autocreate_indexes: true
@@ -0,0 +1,18 @@
1
+ development:
2
+ sessions:
3
+ default:
4
+ database: doorkeeper-mongoid3-development
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ consistency: :strong
9
+ safe: true
10
+ test:
11
+ sessions:
12
+ default:
13
+ database: doorkeeper-mongoid3-test
14
+ hosts:
15
+ - localhost:27017
16
+ options:
17
+ consistency: :strong
18
+ safe: true
@@ -0,0 +1,19 @@
1
+ development:
2
+ sessions:
3
+ default:
4
+ database: doorkeeper-mongoid4-development
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ write:
9
+ w: 1
10
+
11
+ test:
12
+ sessions:
13
+ default:
14
+ database: doorkeeper-mongoid4-test
15
+ hosts:
16
+ - localhost:27017
17
+ options:
18
+ write:
19
+ w: 1
@@ -0,0 +1,19 @@
1
+ development:
2
+ clients:
3
+ default:
4
+ database: doorkeeper-mongoid5-development
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ write:
9
+ w: 1
10
+
11
+ test:
12
+ clients:
13
+ default:
14
+ database: doorkeeper-mongoid5-test
15
+ hosts:
16
+ - localhost:27017
17
+ options:
18
+ write:
19
+ w: 1
@@ -0,0 +1,10 @@
1
+ DatabaseCleaner[:mongo_mapper].strategy = :truncation
2
+ DatabaseCleaner[:mongo_mapper].clean_with :truncation
3
+
4
+ RSpec.configure do |config|
5
+ config.before :suite do
6
+ Doorkeeper::Application.create_indexes
7
+ Doorkeeper::AccessGrant.create_indexes
8
+ Doorkeeper::AccessToken.create_indexes
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ DatabaseCleaner[:mongoid].strategy = :truncation
2
+ DatabaseCleaner[:mongoid].clean_with :truncation
3
+
4
+ RSpec.configure do |config|
5
+ config.before do
6
+ Doorkeeper::Application.create_indexes
7
+ Doorkeeper::AccessGrant.create_indexes
8
+ Doorkeeper::AccessToken.create_indexes
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require_relative "mongoid.rb"
@@ -0,0 +1 @@
1
+ require_relative "mongoid.rb"
@@ -0,0 +1 @@
1
+ require_relative "mongoid.rb"
@@ -0,0 +1,4 @@
1
+ require_relative "mongoid.rb"
2
+
3
+ Mongoid.logger.level = Logger::ERROR
4
+ Mongo::Logger.logger.level = Logger::ERROR
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doorkeeper-mongodb
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - jasl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: doorkeeper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.5
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: generator_spec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.5.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: database_cleaner
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.5.0
125
+ description: Doorkeeper mongoid 2, 3, 4 and mongo_mapper ORMs
126
+ email:
127
+ - jasl9187@hotmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - MIT-LICENSE
133
+ - README.md
134
+ - Rakefile
135
+ - lib/doorkeeper-mongodb.rb
136
+ - lib/doorkeeper-mongodb/compatible.rb
137
+ - lib/doorkeeper-mongodb/version.rb
138
+ - lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb
139
+ - lib/doorkeeper/generators/doorkeeper/mongo_mapper/templates/indexes.rb
140
+ - lib/doorkeeper/orm/mongo_mapper.rb
141
+ - lib/doorkeeper/orm/mongo_mapper/access_grant.rb
142
+ - lib/doorkeeper/orm/mongo_mapper/access_token.rb
143
+ - lib/doorkeeper/orm/mongo_mapper/application.rb
144
+ - lib/doorkeeper/orm/mongoid2.rb
145
+ - lib/doorkeeper/orm/mongoid2/access_grant.rb
146
+ - lib/doorkeeper/orm/mongoid2/access_token.rb
147
+ - lib/doorkeeper/orm/mongoid2/application.rb
148
+ - lib/doorkeeper/orm/mongoid2/concerns/scopes.rb
149
+ - lib/doorkeeper/orm/mongoid3.rb
150
+ - lib/doorkeeper/orm/mongoid3/access_grant.rb
151
+ - lib/doorkeeper/orm/mongoid3/access_token.rb
152
+ - lib/doorkeeper/orm/mongoid3/application.rb
153
+ - lib/doorkeeper/orm/mongoid3/concerns/scopes.rb
154
+ - lib/doorkeeper/orm/mongoid4.rb
155
+ - lib/doorkeeper/orm/mongoid4/access_grant.rb
156
+ - lib/doorkeeper/orm/mongoid4/access_token.rb
157
+ - lib/doorkeeper/orm/mongoid4/application.rb
158
+ - lib/doorkeeper/orm/mongoid4/concerns/scopes.rb
159
+ - lib/doorkeeper/orm/mongoid5.rb
160
+ - lib/doorkeeper/orm/mongoid5/access_grant.rb
161
+ - lib/doorkeeper/orm/mongoid5/access_token.rb
162
+ - lib/doorkeeper/orm/mongoid5/application.rb
163
+ - lib/doorkeeper/orm/mongoid5/concerns/scopes.rb
164
+ - spec/dummy/app/models/user.rb
165
+ - spec/dummy/config/mongo.yml
166
+ - spec/dummy/config/mongoid2.yml
167
+ - spec/dummy/config/mongoid3.yml
168
+ - spec/dummy/config/mongoid4.yml
169
+ - spec/dummy/config/mongoid5.yml
170
+ - spec/support/orm/mongo_mapper.rb
171
+ - spec/support/orm/mongoid.rb
172
+ - spec/support/orm/mongoid2.rb
173
+ - spec/support/orm/mongoid3.rb
174
+ - spec/support/orm/mongoid4.rb
175
+ - spec/support/orm/mongoid5.rb
176
+ homepage: http://github.com/doorkeeper-gem/doorkeeper-mongodb
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.5.1
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Doorkeeper mongoid 2, 3, 4 and mongo_mapper ORMs
200
+ test_files:
201
+ - spec/dummy/app/models/user.rb
202
+ - spec/dummy/config/mongo.yml
203
+ - spec/dummy/config/mongoid2.yml
204
+ - spec/dummy/config/mongoid3.yml
205
+ - spec/dummy/config/mongoid4.yml
206
+ - spec/dummy/config/mongoid5.yml
207
+ - spec/support/orm/mongo_mapper.rb
208
+ - spec/support/orm/mongoid.rb
209
+ - spec/support/orm/mongoid2.rb
210
+ - spec/support/orm/mongoid3.rb
211
+ - spec/support/orm/mongoid4.rb
212
+ - spec/support/orm/mongoid5.rb