doorkeeper 1.4.1 → 2.0.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.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/.travis.yml +38 -10
- data/CHANGELOG.md +43 -1
- data/CONTRIBUTING.md +35 -0
- data/Gemfile +4 -26
- data/README.md +21 -55
- data/Rakefile +3 -1
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/applications_controller.rb +4 -5
- data/app/controllers/doorkeeper/authorizations_controller.rb +4 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -2
- data/app/helpers/doorkeeper/{form_errors_helper.rb → dashboard_helper.rb} +5 -1
- data/app/validators/redirect_uri_validator.rb +6 -0
- data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/index.html.erb +1 -1
- data/config/locales/en.yml +6 -3
- data/doorkeeper.gemspec +3 -3
- data/gemfiles/Gemfile.common.rb +11 -0
- data/gemfiles/Gemfile.mongo_mapper.rb +5 -0
- data/gemfiles/Gemfile.mongoid2.rb +5 -0
- data/gemfiles/Gemfile.mongoid3.rb +4 -0
- data/gemfiles/Gemfile.mongoid4.rb +5 -0
- data/lib/doorkeeper/config.rb +34 -24
- data/lib/doorkeeper/engine.rb +1 -2
- data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
- data/lib/doorkeeper/models/access_grant_mixin.rb +36 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +122 -0
- data/lib/doorkeeper/models/application_mixin.rb +60 -0
- data/lib/doorkeeper/models/{expirable.rb → concerns/expirable.rb} +6 -5
- data/lib/doorkeeper/models/{ownership.rb → concerns/ownership.rb} +7 -7
- data/lib/doorkeeper/models/{revocable.rb → concerns/revocable.rb} +1 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +6 -6
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
- data/lib/doorkeeper/oauth/pre_authorization.rb +5 -1
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -6
- data/lib/doorkeeper/oauth/scopes.rb +6 -1
- data/lib/doorkeeper/oauth/token.rb +3 -2
- data/lib/doorkeeper/orm/active_record/access_grant.rb +7 -0
- data/lib/doorkeeper/orm/active_record/access_token.rb +21 -0
- data/lib/doorkeeper/{models → orm}/active_record/application.rb +1 -3
- data/lib/doorkeeper/orm/active_record.rb +17 -0
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_grant.rb +4 -5
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_token.rb +12 -17
- data/lib/doorkeeper/{models → orm}/mongo_mapper/application.rb +3 -4
- data/lib/doorkeeper/orm/mongo_mapper.rb +11 -0
- data/lib/doorkeeper/{models → orm}/mongoid2/access_grant.rb +5 -3
- data/lib/doorkeeper/{models → orm}/mongoid2/access_token.rb +10 -12
- data/lib/doorkeeper/{models → orm}/mongoid2/application.rb +3 -0
- data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid2.rb +11 -0
- data/lib/doorkeeper/orm/mongoid3/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid3/access_token.rb +37 -0
- data/lib/doorkeeper/{models/mongoid3_4 → orm/mongoid3}/application.rb +3 -0
- data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid3.rb +11 -0
- data/lib/doorkeeper/orm/mongoid4/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid4/access_token.rb +37 -0
- data/lib/doorkeeper/orm/mongoid4/application.rb +25 -0
- data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/orm/mongoid4.rb +11 -0
- data/lib/doorkeeper/rails/helpers.rb +63 -0
- data/lib/doorkeeper/rails/routes.rb +1 -12
- data/lib/doorkeeper/request/code.rb +0 -1
- data/lib/doorkeeper/request/token.rb +0 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +15 -6
- data/lib/generators/doorkeeper/application_owner_generator.rb +4 -1
- data/lib/generators/doorkeeper/application_scopes_generator.rb +34 -0
- data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +5 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +8 -1
- data/lib/generators/doorkeeper/templates/migration.rb +1 -0
- data/lib/generators/doorkeeper/views_generator.rb +4 -5
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/protected_resources_controller_spec.rb +25 -175
- data/spec/controllers/tokens_controller_spec.rb +15 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/metal_controller.rb +2 -2
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +5 -5
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/config/boot.rb +4 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +5 -0
- data/spec/dummy/db/schema.rb +41 -40
- data/spec/factories.rb +24 -0
- data/spec/lib/config_spec.rb +30 -10
- data/spec/lib/models/expirable_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +8 -3
- data/spec/lib/models/scopes_spec.rb +3 -3
- data/spec/lib/oauth/client_spec.rb +1 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
- data/spec/lib/oauth/pre_authorization_spec.rb +43 -9
- data/spec/lib/oauth/token_request_spec.rb +28 -1
- data/spec/lib/oauth/token_spec.rb +1 -1
- data/spec/models/doorkeeper/application_spec.rb +16 -1
- data/spec/requests/applications/applications_request_spec.rb +6 -4
- data/spec/requests/flows/implicit_grant_spec.rb +32 -0
- data/spec/requests/flows/refresh_token_spec.rb +12 -3
- data/spec/spec_helper_integration.rb +8 -2
- data/spec/support/shared/controllers_shared_context.rb +2 -2
- data/spec/validators/redirect_uri_validator_spec.rb +30 -3
- metadata +52 -39
- data/lib/doorkeeper/doorkeeper_for.rb +0 -69
- data/lib/doorkeeper/helpers/filter.rb +0 -64
- data/lib/doorkeeper/models/access_grant.rb +0 -30
- data/lib/doorkeeper/models/access_token.rb +0 -106
- data/lib/doorkeeper/models/active_record/access_grant.rb +0 -9
- data/lib/doorkeeper/models/active_record/access_token.rb +0 -25
- data/lib/doorkeeper/models/application.rb +0 -40
- data/lib/doorkeeper/models/mongoid/scopes.rb +0 -15
- data/lib/doorkeeper/models/mongoid/version.rb +0 -15
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +0 -27
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +0 -46
- data/lib/doorkeeper/models/scopes.rb +0 -21
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
- data/script/rails +0 -5
- data/script/run_all +0 -14
- data/spec/factories/access_grant.rb +0 -9
- data/spec/factories/access_token.rb +0 -11
- data/spec/factories/application.rb +0 -6
- /data/lib/{generators/doorkeeper → doorkeeper/generators/doorkeeper/mongo_mapper}/templates/indexes.rb +0 -0
- /data/lib/doorkeeper/models/{accessible.rb → concerns/accessible.rb} +0 -0
@@ -1,69 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class InvalidSyntax < StandardError; end
|
3
|
-
class DoorkeeperFor
|
4
|
-
attr_reader :scopes
|
5
|
-
|
6
|
-
def initialize(options)
|
7
|
-
options ||= {}
|
8
|
-
fail InvalidSyntax unless options.is_a? Hash
|
9
|
-
@filter_options = {}
|
10
|
-
|
11
|
-
options.each do |k, v|
|
12
|
-
send("#{k}=", v)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def filter_options
|
17
|
-
@filter_options
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def scopes=(scopes)
|
23
|
-
@scopes = scopes.map(&:to_s)
|
24
|
-
end
|
25
|
-
|
26
|
-
def if=(if_block)
|
27
|
-
@filter_options[:if] = if_block
|
28
|
-
end
|
29
|
-
|
30
|
-
def unless=(unless_block)
|
31
|
-
@filter_options[:unless] = unless_block
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class AllDoorkeeperFor < DoorkeeperFor
|
36
|
-
private
|
37
|
-
|
38
|
-
def except=(actions)
|
39
|
-
@filter_options[:except] = actions
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class SelectedDoorkeeperFor < DoorkeeperFor
|
44
|
-
def initialize(*args)
|
45
|
-
options = args.pop if args.last.is_a? Hash
|
46
|
-
super(options)
|
47
|
-
only(args)
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def only(actions)
|
53
|
-
@filter_options[:only] = actions
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class DoorkeeperForBuilder
|
58
|
-
def self.create_doorkeeper_for(*args)
|
59
|
-
case args.first
|
60
|
-
when :all
|
61
|
-
AllDoorkeeperFor.new(args[1] || {})
|
62
|
-
when Hash, nil
|
63
|
-
fail InvalidSyntax
|
64
|
-
else
|
65
|
-
SelectedDoorkeeperFor.new(*args)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
module Helpers
|
3
|
-
module Filter
|
4
|
-
module ClassMethods
|
5
|
-
def doorkeeper_for(*args)
|
6
|
-
doorkeeper_for = DoorkeeperForBuilder.create_doorkeeper_for(*args)
|
7
|
-
|
8
|
-
before_filter doorkeeper_for.filter_options do
|
9
|
-
unless valid_token?(doorkeeper_for.scopes)
|
10
|
-
if !doorkeeper_token || !doorkeeper_token.accessible?
|
11
|
-
@error = OAuth::InvalidTokenResponse.from_access_token(doorkeeper_token)
|
12
|
-
error_status = :unauthorized
|
13
|
-
options = doorkeeper_unauthorized_render_options
|
14
|
-
else
|
15
|
-
@error = OAuth::ForbiddenTokenResponse.from_scopes(doorkeeper_for.scopes)
|
16
|
-
error_status = :forbidden
|
17
|
-
options = doorkeeper_forbidden_render_options
|
18
|
-
end
|
19
|
-
headers.merge!(@error.headers.reject { |k, v| ['Content-Type'].include? k })
|
20
|
-
render_error(error_status, options)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.included(base)
|
27
|
-
base.extend ClassMethods
|
28
|
-
base.send :private, :doorkeeper_token, :doorkeeper_unauthorized_render_options
|
29
|
-
end
|
30
|
-
|
31
|
-
def doorkeeper_token
|
32
|
-
@token ||= OAuth::Token.authenticate request, *config_methods
|
33
|
-
end
|
34
|
-
|
35
|
-
def config_methods
|
36
|
-
@methods ||= Doorkeeper.configuration.access_token_methods
|
37
|
-
end
|
38
|
-
|
39
|
-
def doorkeeper_unauthorized_render_options
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
def doorkeeper_forbidden_render_options
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def valid_token?(scopes)
|
50
|
-
doorkeeper_token && doorkeeper_token.acceptable?(scopes)
|
51
|
-
end
|
52
|
-
|
53
|
-
def render_error(error, options)
|
54
|
-
if options.blank?
|
55
|
-
head error
|
56
|
-
else
|
57
|
-
options[:status] = error
|
58
|
-
options[:layout] = false if options[:layout].nil?
|
59
|
-
render options
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class AccessGrant
|
3
|
-
include OAuth::Helpers
|
4
|
-
include Models::Expirable
|
5
|
-
include Models::Revocable
|
6
|
-
include Models::Accessible
|
7
|
-
include Models::Scopes
|
8
|
-
|
9
|
-
belongs_to :application, class_name: 'Doorkeeper::Application', inverse_of: :access_grants
|
10
|
-
|
11
|
-
if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
|
12
|
-
attr_accessible :resource_owner_id, :application_id, :expires_in, :redirect_uri, :scopes
|
13
|
-
end
|
14
|
-
|
15
|
-
validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, presence: true
|
16
|
-
validates :token, uniqueness: true
|
17
|
-
|
18
|
-
before_validation :generate_token, on: :create
|
19
|
-
|
20
|
-
def self.authenticate(token)
|
21
|
-
where(token: token).first
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def generate_token
|
27
|
-
self.token = UniqueToken.generate
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class AccessToken
|
3
|
-
include OAuth::Helpers
|
4
|
-
include Models::Expirable
|
5
|
-
include Models::Revocable
|
6
|
-
include Models::Accessible
|
7
|
-
include Models::Scopes
|
8
|
-
|
9
|
-
belongs_to :application,
|
10
|
-
class_name: 'Doorkeeper::Application',
|
11
|
-
inverse_of: :access_tokens
|
12
|
-
|
13
|
-
validates :token, presence: true
|
14
|
-
validates :token, uniqueness: true
|
15
|
-
validates :refresh_token, uniqueness: true, if: :use_refresh_token?
|
16
|
-
|
17
|
-
attr_accessor :use_refresh_token
|
18
|
-
if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
|
19
|
-
attr_accessible :application_id, :resource_owner_id, :expires_in,
|
20
|
-
:scopes, :use_refresh_token
|
21
|
-
end
|
22
|
-
|
23
|
-
before_validation :generate_token, on: :create
|
24
|
-
before_validation :generate_refresh_token,
|
25
|
-
on: :create,
|
26
|
-
if: :use_refresh_token?
|
27
|
-
|
28
|
-
def self.authenticate(token)
|
29
|
-
where(token: token).first
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.by_refresh_token(refresh_token)
|
33
|
-
where(refresh_token: refresh_token).first
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.revoke_all_for(application_id, resource_owner)
|
37
|
-
where(application_id: application_id,
|
38
|
-
resource_owner_id: resource_owner.id,
|
39
|
-
revoked_at: nil)
|
40
|
-
.map(&:revoke)
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.matching_token_for(application, resource_owner_or_id, scopes)
|
44
|
-
resource_owner_id = if resource_owner_or_id.respond_to?(:to_key)
|
45
|
-
resource_owner_or_id.id
|
46
|
-
else
|
47
|
-
resource_owner_or_id
|
48
|
-
end
|
49
|
-
token = last_authorized_token_for(application.try(:id), resource_owner_id)
|
50
|
-
token if token && ScopeChecker.matches?(token.scopes, scopes)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.find_or_create_for(application, resource_owner_id, scopes, expires_in, use_refresh_token)
|
54
|
-
if Doorkeeper.configuration.reuse_access_token
|
55
|
-
access_token = matching_token_for(application, resource_owner_id, scopes)
|
56
|
-
if access_token && !access_token.expired?
|
57
|
-
return access_token
|
58
|
-
end
|
59
|
-
end
|
60
|
-
create!(
|
61
|
-
application_id: application.try(:id),
|
62
|
-
resource_owner_id: resource_owner_id,
|
63
|
-
scopes: scopes.to_s,
|
64
|
-
expires_in: expires_in,
|
65
|
-
use_refresh_token: use_refresh_token
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
def token_type
|
70
|
-
'bearer'
|
71
|
-
end
|
72
|
-
|
73
|
-
def use_refresh_token?
|
74
|
-
use_refresh_token
|
75
|
-
end
|
76
|
-
|
77
|
-
def as_json(options = {})
|
78
|
-
{
|
79
|
-
resource_owner_id: resource_owner_id,
|
80
|
-
scopes: scopes,
|
81
|
-
expires_in_seconds: expires_in_seconds,
|
82
|
-
application: { uid: application.try(:uid) }
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
# It indicates whether the tokens have the same credential
|
87
|
-
def same_credential?(access_token)
|
88
|
-
application_id == access_token.application_id &&
|
89
|
-
resource_owner_id == access_token.resource_owner_id
|
90
|
-
end
|
91
|
-
|
92
|
-
def acceptable?(scopes)
|
93
|
-
accessible? && includes_scope?(scopes)
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def generate_refresh_token
|
99
|
-
write_attribute :refresh_token, UniqueToken.generate
|
100
|
-
end
|
101
|
-
|
102
|
-
def generate_token
|
103
|
-
self.token = UniqueToken.generate
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class AccessGrant < ActiveRecord::Base
|
3
|
-
if Doorkeeper.configuration.active_record_options[:establish_connection]
|
4
|
-
establish_connection Doorkeeper.configuration.active_record_options[:establish_connection]
|
5
|
-
end
|
6
|
-
|
7
|
-
self.table_name = "#{table_name_prefix}oauth_access_grants#{table_name_suffix}".to_sym
|
8
|
-
end
|
9
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class AccessToken < ActiveRecord::Base
|
3
|
-
if Doorkeeper.configuration.active_record_options[:establish_connection]
|
4
|
-
establish_connection Doorkeeper.configuration.active_record_options[:establish_connection]
|
5
|
-
end
|
6
|
-
|
7
|
-
self.table_name = "#{table_name_prefix}oauth_access_tokens#{table_name_suffix}".to_sym
|
8
|
-
|
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
|
12
|
-
end
|
13
|
-
private_class_method :delete_all_for
|
14
|
-
|
15
|
-
def self.last_authorized_token_for(application_id, 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
|
22
|
-
end
|
23
|
-
private_class_method :last_authorized_token_for
|
24
|
-
end
|
25
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
class Application
|
3
|
-
include OAuth::Helpers
|
4
|
-
|
5
|
-
has_many :access_grants, dependent: :destroy, class_name: 'Doorkeeper::AccessGrant'
|
6
|
-
has_many :access_tokens, dependent: :destroy, class_name: 'Doorkeeper::AccessToken'
|
7
|
-
|
8
|
-
validates :name, :secret, :uid, presence: true
|
9
|
-
validates :uid, uniqueness: true
|
10
|
-
validates :redirect_uri, redirect_uri: true
|
11
|
-
|
12
|
-
before_validation :generate_uid, :generate_secret, on: :create
|
13
|
-
|
14
|
-
if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
|
15
|
-
attr_accessible :name, :redirect_uri
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.model_name
|
19
|
-
ActiveModel::Name.new(self, Doorkeeper, 'Application')
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.authenticate(uid, secret)
|
23
|
-
self.where(uid: uid, secret: secret).first
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.by_uid(uid)
|
27
|
-
self.where(uid: uid).first
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def generate_uid
|
33
|
-
self.uid ||= UniqueToken.generate
|
34
|
-
end
|
35
|
-
|
36
|
-
def generate_secret
|
37
|
-
self.secret ||= UniqueToken.generate
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'doorkeeper/models/mongoid/scopes'
|
2
|
-
require 'doorkeeper/models/mongoid/version'
|
3
|
-
|
4
|
-
module Doorkeeper
|
5
|
-
class AccessGrant
|
6
|
-
include Mongoid::Document
|
7
|
-
include Mongoid::Timestamps
|
8
|
-
include Models::Mongoid::Scopes
|
9
|
-
extend Models::Mongoid::Version
|
10
|
-
|
11
|
-
self.store_in collection: :oauth_access_grants
|
12
|
-
|
13
|
-
if defined?(Moped::BSON)
|
14
|
-
field :resource_owner_id, type: Moped::BSON::ObjectId
|
15
|
-
else
|
16
|
-
field :resource_owner_id, type: BSON::ObjectId
|
17
|
-
end
|
18
|
-
|
19
|
-
field :application_id, type: Hash
|
20
|
-
field :token, type: String
|
21
|
-
field :expires_in, type: Integer
|
22
|
-
field :redirect_uri, type: String
|
23
|
-
field :revoked_at, type: DateTime
|
24
|
-
|
25
|
-
index({ token: 1 }, { unique: true })
|
26
|
-
end
|
27
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'doorkeeper/models/mongoid/scopes'
|
2
|
-
require 'doorkeeper/models/mongoid/version'
|
3
|
-
|
4
|
-
module Doorkeeper
|
5
|
-
class AccessToken
|
6
|
-
include Mongoid::Document
|
7
|
-
include Mongoid::Timestamps
|
8
|
-
include Models::Mongoid::Scopes
|
9
|
-
extend Models::Mongoid::Version
|
10
|
-
|
11
|
-
self.store_in collection: :oauth_access_tokens
|
12
|
-
|
13
|
-
if defined?(Moped::BSON)
|
14
|
-
field :resource_owner_id, type: Moped::BSON::ObjectId
|
15
|
-
else
|
16
|
-
field :resource_owner_id, type: BSON::ObjectId
|
17
|
-
end
|
18
|
-
|
19
|
-
field :token, type: String
|
20
|
-
field :expires_in, type: Integer
|
21
|
-
field :revoked_at, type: DateTime
|
22
|
-
|
23
|
-
index({ token: 1 }, { unique: true })
|
24
|
-
index({ refresh_token: 1 }, { unique: true, sparse: true })
|
25
|
-
|
26
|
-
def self.delete_all_for(application_id, resource_owner)
|
27
|
-
where(application_id: application_id,
|
28
|
-
resource_owner_id: resource_owner.id).delete_all
|
29
|
-
end
|
30
|
-
private_class_method :delete_all_for
|
31
|
-
|
32
|
-
def self.last_authorized_token_for(application_id, resource_owner_id)
|
33
|
-
where(application_id: application_id,
|
34
|
-
resource_owner_id: resource_owner_id,
|
35
|
-
revoked_at: nil).
|
36
|
-
order_by([:created_at, :desc]).
|
37
|
-
limit(1).
|
38
|
-
first
|
39
|
-
end
|
40
|
-
private_class_method :last_authorized_token_for
|
41
|
-
|
42
|
-
def refresh_token
|
43
|
-
self[:refresh_token]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Doorkeeper
|
2
|
-
module Models
|
3
|
-
module Scopes
|
4
|
-
def self.included(base)
|
5
|
-
base.class_eval do
|
6
|
-
define_method :scopes do
|
7
|
-
OAuth::Scopes.from_string(self[:scopes])
|
8
|
-
end
|
9
|
-
|
10
|
-
define_method :scopes_string do
|
11
|
-
OAuth::Scopes.from_string(self[:scopes]).to_s
|
12
|
-
end
|
13
|
-
|
14
|
-
define_method :includes_scope? do |required_scopes|
|
15
|
-
required_scopes.blank? || required_scopes.any? { |s| scopes.exists?(s) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,12 +0,0 @@
|
|
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
|
data/script/rails
DELETED
data/script/run_all
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -e
|
3
|
-
|
4
|
-
rails=3.2.8 orm=active_record bundle install --quiet
|
5
|
-
rails=3.2.8 orm=active_record bundle exec rake
|
6
|
-
|
7
|
-
rails=3.2.8 orm=mongoid2 bundle install --quiet
|
8
|
-
rails=3.2.8 orm=mongoid2 bundle exec rake
|
9
|
-
|
10
|
-
rails=3.2.8 orm=mongoid3 bundle install --quiet
|
11
|
-
rails=3.2.8 orm=mongoid3 bundle exec rake
|
12
|
-
|
13
|
-
rails=3.2.8 orm=mongo_mapper bundle install --quiet
|
14
|
-
rails=3.2.8 orm=mongo_mapper bundle exec rake
|
File without changes
|
File without changes
|