doorkeeper 4.3.2 → 5.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +2 -0
- data/Appraisals +2 -2
- data/Gemfile +1 -1
- data/NEWS.md +36 -0
- data/README.md +85 -3
- data/Rakefile +6 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +4 -3
- data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
- data/app/controllers/doorkeeper/applications_controller.rb +43 -22
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +15 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
- data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
- data/app/validators/redirect_uri_validator.rb +3 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +31 -19
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +18 -6
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +8 -5
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +15 -1
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/lib/doorkeeper/config.rb +60 -23
- data/lib/doorkeeper/engine.rb +4 -0
- data/lib/doorkeeper/errors.rb +2 -5
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +7 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +56 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +37 -20
- data/lib/doorkeeper/models/application_mixin.rb +8 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +23 -6
- data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
- data/lib/doorkeeper/oauth/base_request.rb +18 -8
- data/lib/doorkeeper/oauth/client/credentials.rb +4 -2
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -2
- data/lib/doorkeeper/oauth/error_response.rb +11 -3
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +45 -13
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
- data/lib/doorkeeper/oauth/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/token.rb +5 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
- data/lib/doorkeeper/oauth/token_response.rb +4 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/application.rb +14 -0
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +2 -0
- data/lib/doorkeeper/rails/helpers.rb +2 -4
- data/lib/doorkeeper/rails/routes.rb +13 -1
- data/lib/doorkeeper/rake/db.rake +40 -0
- data/lib/doorkeeper/rake/setup.rake +6 -0
- data/lib/doorkeeper/rake.rb +14 -0
- data/lib/doorkeeper/request/password.rb +1 -11
- data/lib/doorkeeper/request.rb +28 -28
- data/lib/doorkeeper/version.rb +5 -4
- data/lib/doorkeeper.rb +4 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
- data/lib/generators/doorkeeper/install_generator.rb +17 -9
- data/lib/generators/doorkeeper/migration_generator.rb +23 -18
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +60 -9
- data/lib/generators/doorkeeper/templates/migration.rb.erb +1 -0
- data/lib/generators/doorkeeper/views_generator.rb +3 -1
- data/spec/controllers/application_metal_controller_spec.rb +50 -0
- data/spec/controllers/applications_controller_spec.rb +126 -13
- data/spec/controllers/authorizations_controller_spec.rb +250 -15
- data/spec/controllers/protected_resources_controller_spec.rb +16 -16
- data/spec/controllers/token_info_controller_spec.rb +4 -12
- data/spec/controllers/tokens_controller_spec.rb +12 -14
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/config/environments/test.rb +4 -5
- data/spec/dummy/config/initializers/doorkeeper.rb +6 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -1
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +3 -1
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +3 -1
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +13 -0
- data/spec/dummy/db/schema.rb +38 -37
- data/spec/generators/application_owner_generator_spec.rb +1 -1
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/migration_generator_spec.rb +1 -1
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
- data/spec/generators/views_generator_spec.rb +1 -1
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +59 -14
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -3
- data/spec/lib/models/revocable_spec.rb +0 -2
- data/spec/lib/models/scopes_spec.rb +0 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +24 -2
- data/spec/lib/oauth/base_request_spec.rb +16 -2
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
- data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +4 -2
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +0 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -2
- data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
- data/spec/lib/oauth/pre_authorization_spec.rb +40 -6
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
- data/spec/lib/oauth/scopes_spec.rb +0 -3
- data/spec/lib/oauth/token_request_spec.rb +4 -5
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +37 -14
- data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +1 -1
- data/spec/models/doorkeeper/access_token_spec.rb +50 -16
- data/spec/models/doorkeeper/application_spec.rb +51 -6
- data/spec/requests/applications/applications_request_spec.rb +89 -1
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +7 -5
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +197 -1
- data/spec/requests/flows/client_credentials_spec.rb +46 -6
- data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
- data/spec/requests/flows/implicit_grant_spec.rb +38 -11
- data/spec/requests/flows/password_spec.rb +120 -23
- data/spec/requests/flows/refresh_token_spec.rb +2 -2
- data/spec/requests/flows/revoke_token_spec.rb +11 -11
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +1 -1
- data/spec/routing/custom_controller_routes_spec.rb +59 -7
- data/spec/routing/default_routes_spec.rb +2 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -74
- data/spec/support/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/request_spec_helper.rb +2 -2
- data/spec/support/helpers/url_helper.rb +7 -3
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/validators/redirect_uri_validator_spec.rb +7 -1
- data/spec/version/version_spec.rb +3 -3
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +32 -8
- data/spec/controllers/application_metal_controller.rb +0 -10
- /data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
|
@@ -3,7 +3,7 @@ module Doorkeeper
|
|
|
3
3
|
class Token
|
|
4
4
|
class << self
|
|
5
5
|
def from_request(request, *methods)
|
|
6
|
-
methods.inject(nil) do |
|
|
6
|
+
methods.inject(nil) do |_, method|
|
|
7
7
|
method = self.method(method) if method.is_a?(Symbol)
|
|
8
8
|
credentials = method.call(request)
|
|
9
9
|
break credentials unless credentials.blank?
|
|
@@ -13,7 +13,10 @@ module Doorkeeper
|
|
|
13
13
|
def authenticate(request, *methods)
|
|
14
14
|
if (token = from_request(request, *methods))
|
|
15
15
|
access_token = AccessToken.by_token(token)
|
|
16
|
-
|
|
16
|
+
refresh_token_enabled = Doorkeeper.configuration.refresh_token_enabled?
|
|
17
|
+
if access_token.present? && refresh_token_enabled
|
|
18
|
+
access_token.revoke_previous_refresh_token!
|
|
19
|
+
end
|
|
17
20
|
access_token
|
|
18
21
|
end
|
|
19
22
|
end
|
|
@@ -47,12 +47,12 @@ module Doorkeeper
|
|
|
47
47
|
|
|
48
48
|
# Client Authentication
|
|
49
49
|
def authorized_client
|
|
50
|
-
@
|
|
50
|
+
@authorized_client ||= server.credentials && server.client
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# Bearer Token Authentication
|
|
54
54
|
def authorized_token
|
|
55
|
-
@
|
|
55
|
+
@authorized_token ||=
|
|
56
56
|
OAuth::Token.authenticate(server.context.request, :from_bearer_authorization)
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -23,9 +23,11 @@ module Doorkeeper
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def headers
|
|
26
|
-
{
|
|
26
|
+
{
|
|
27
|
+
'Cache-Control' => 'no-store',
|
|
27
28
|
'Pragma' => 'no-cache',
|
|
28
|
-
'Content-Type' => 'application/json; charset=utf-8'
|
|
29
|
+
'Content-Type' => 'application/json; charset=utf-8'
|
|
30
|
+
}
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module OAuth
|
|
5
|
+
GRANT_TYPES = [
|
|
6
|
+
AUTHORIZATION_CODE = 'authorization_code'.freeze,
|
|
7
|
+
IMPLICIT = 'implicit'.freeze,
|
|
8
|
+
PASSWORD = 'password'.freeze,
|
|
9
|
+
CLIENT_CREDENTIALS = 'client_credentials'.freeze,
|
|
10
|
+
REFRESH_TOKEN = 'refresh_token'.freeze
|
|
11
|
+
].freeze
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -11,6 +11,9 @@ module Doorkeeper
|
|
|
11
11
|
validates :name, :secret, :uid, presence: true
|
|
12
12
|
validates :uid, uniqueness: true
|
|
13
13
|
validates :redirect_uri, redirect_uri: true
|
|
14
|
+
validates :confidential, inclusion: { in: [true, false] }
|
|
15
|
+
|
|
16
|
+
validate :scopes_match_configured, if: :enforce_scopes?
|
|
14
17
|
|
|
15
18
|
before_validation :generate_uid, :generate_secret, on: :create
|
|
16
19
|
|
|
@@ -40,5 +43,16 @@ module Doorkeeper
|
|
|
40
43
|
def generate_secret
|
|
41
44
|
self.secret = UniqueToken.generate if secret.blank?
|
|
42
45
|
end
|
|
46
|
+
|
|
47
|
+
def scopes_match_configured
|
|
48
|
+
if scopes.present? &&
|
|
49
|
+
!ScopeChecker.valid?(scopes.to_s, Doorkeeper.configuration.scopes)
|
|
50
|
+
errors.add(:scopes, :not_match_configured)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def enforce_scopes?
|
|
55
|
+
Doorkeeper.configuration.enforce_configured_scopes?
|
|
56
|
+
end
|
|
43
57
|
end
|
|
44
58
|
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module Orm
|
|
5
|
+
module ActiveRecord
|
|
6
|
+
class StaleRecordsCleaner
|
|
7
|
+
def initialize(base_scope)
|
|
8
|
+
@base_scope = base_scope
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def clean_revoked
|
|
12
|
+
table = @base_scope.arel_table
|
|
13
|
+
@base_scope.where.not(revoked_at: nil)
|
|
14
|
+
.where(table[:revoked_at].lt(Time.current))
|
|
15
|
+
.delete_all
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def clean_expired(ttl)
|
|
19
|
+
table = @base_scope.arel_table
|
|
20
|
+
@base_scope.where(table[:created_at].lt(Time.current - ttl))
|
|
21
|
+
.delete_all
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -4,9 +4,7 @@ module Doorkeeper
|
|
|
4
4
|
def doorkeeper_authorize!(*scopes)
|
|
5
5
|
@_doorkeeper_scopes = scopes.presence || Doorkeeper.configuration.default_scopes
|
|
6
6
|
|
|
7
|
-
unless valid_doorkeeper_token?
|
|
8
|
-
doorkeeper_render_error
|
|
9
|
-
end
|
|
7
|
+
doorkeeper_render_error unless valid_doorkeeper_token?
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
def doorkeeper_unauthorized_render_options(**); end
|
|
@@ -68,7 +66,7 @@ module Doorkeeper
|
|
|
68
66
|
end
|
|
69
67
|
|
|
70
68
|
def doorkeeper_token
|
|
71
|
-
@
|
|
69
|
+
@doorkeeper_token ||= OAuth::Token.authenticate(
|
|
72
70
|
request,
|
|
73
71
|
*Doorkeeper.configuration.access_token_methods
|
|
74
72
|
)
|
|
@@ -4,6 +4,10 @@ require 'doorkeeper/rails/routes/mapper'
|
|
|
4
4
|
module Doorkeeper
|
|
5
5
|
module Rails
|
|
6
6
|
class Routes # :nodoc:
|
|
7
|
+
mattr_reader :mapping do
|
|
8
|
+
{}
|
|
9
|
+
end
|
|
10
|
+
|
|
7
11
|
module Helper
|
|
8
12
|
def use_doorkeeper(options = {}, &block)
|
|
9
13
|
Doorkeeper::Rails::Routes.new(self, &block).generate_routes!(options)
|
|
@@ -19,6 +23,10 @@ module Doorkeeper
|
|
|
19
23
|
def initialize(routes, &block)
|
|
20
24
|
@routes = routes
|
|
21
25
|
@mapping = Mapper.new.map(&block)
|
|
26
|
+
|
|
27
|
+
if Doorkeeper.configuration.api_only
|
|
28
|
+
@mapping.skips.push(:applications, :authorized_applications)
|
|
29
|
+
end
|
|
22
30
|
end
|
|
23
31
|
|
|
24
32
|
def generate_routes!(options)
|
|
@@ -36,7 +44,11 @@ module Doorkeeper
|
|
|
36
44
|
private
|
|
37
45
|
|
|
38
46
|
def map_route(name, method)
|
|
39
|
-
|
|
47
|
+
unless @mapping.skipped?(name)
|
|
48
|
+
send(method, @mapping[name])
|
|
49
|
+
|
|
50
|
+
mapping[name] = @mapping[name]
|
|
51
|
+
end
|
|
40
52
|
end
|
|
41
53
|
|
|
42
54
|
def authorization_routes(mapping)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :doorkeeper do
|
|
4
|
+
namespace :db do
|
|
5
|
+
desc 'Removes stale data from doorkeeper related database tables'
|
|
6
|
+
task cleanup: [
|
|
7
|
+
'doorkeeper:db:cleanup:revoked_tokens',
|
|
8
|
+
'doorkeeper:db:cleanup:expired_tokens',
|
|
9
|
+
'doorkeeper:db:cleanup:revoked_grants',
|
|
10
|
+
'doorkeeper:db:cleanup:expired_grants'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
namespace :cleanup do
|
|
14
|
+
desc 'Removes stale access tokens'
|
|
15
|
+
task revoked_tokens: 'doorkeeper:setup' do
|
|
16
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessToken)
|
|
17
|
+
cleaner.clean_revoked
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc 'Removes expired (TTL passed) access tokens'
|
|
21
|
+
task expired_tokens: 'doorkeeper:setup' do
|
|
22
|
+
expirable_tokens = Doorkeeper::AccessToken.where(refresh_token: nil)
|
|
23
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(expirable_tokens)
|
|
24
|
+
cleaner.clean_expired(Doorkeeper.configuration.access_token_expires_in)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc 'Removes stale access grants'
|
|
28
|
+
task revoked_grants: 'doorkeeper:setup' do
|
|
29
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
|
|
30
|
+
cleaner.clean_revoked
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc 'Removes expired (TTL passed) access grants'
|
|
34
|
+
task expired_grants: 'doorkeeper:setup' do
|
|
35
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
|
|
36
|
+
cleaner.clean_expired(Doorkeeper.configuration.authorization_code_expires_in)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -3,7 +3,7 @@ require 'doorkeeper/request/strategy'
|
|
|
3
3
|
module Doorkeeper
|
|
4
4
|
module Request
|
|
5
5
|
class Password < Strategy
|
|
6
|
-
delegate :credentials, :resource_owner, :parameters, to: :server
|
|
6
|
+
delegate :credentials, :resource_owner, :parameters, :client, to: :server
|
|
7
7
|
|
|
8
8
|
def request
|
|
9
9
|
@request ||= OAuth::PasswordAccessTokenRequest.new(
|
|
@@ -13,16 +13,6 @@ module Doorkeeper
|
|
|
13
13
|
parameters
|
|
14
14
|
)
|
|
15
15
|
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def client
|
|
20
|
-
if credentials
|
|
21
|
-
server.client
|
|
22
|
-
elsif parameters[:client_id]
|
|
23
|
-
server.client_via_uid
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
16
|
end
|
|
27
17
|
end
|
|
28
18
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
|
@@ -7,40 +7,40 @@ require 'doorkeeper/request/token'
|
|
|
7
7
|
|
|
8
8
|
module Doorkeeper
|
|
9
9
|
module Request
|
|
10
|
-
|
|
10
|
+
class << self
|
|
11
|
+
def authorization_strategy(response_type)
|
|
12
|
+
get_strategy(response_type, authorization_response_types)
|
|
13
|
+
rescue NameError
|
|
14
|
+
raise Errors::InvalidAuthorizationStrategy
|
|
15
|
+
end
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
def token_strategy(grant_type)
|
|
18
|
+
get_strategy(grant_type, token_grant_types)
|
|
19
|
+
rescue NameError
|
|
20
|
+
raise Errors::InvalidTokenStrategy
|
|
21
|
+
end
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
raise Errors::InvalidTokenStrategy
|
|
22
|
-
end
|
|
23
|
+
def get_strategy(grant_or_request_type, available)
|
|
24
|
+
raise Errors::MissingRequestStrategy if grant_or_request_type.blank?
|
|
25
|
+
raise NameError unless available.include?(grant_or_request_type.to_s)
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
fail NameError unless available.include?(grant_or_request_type.to_s)
|
|
27
|
-
strategy_class(grant_or_request_type)
|
|
28
|
-
end
|
|
27
|
+
build_strategy_class(grant_or_request_type)
|
|
28
|
+
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
Doorkeeper.configuration.authorization_response_types
|
|
32
|
-
end
|
|
33
|
-
private_class_method :authorization_response_types
|
|
30
|
+
private
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
def authorization_response_types
|
|
33
|
+
Doorkeeper.configuration.authorization_response_types
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def token_grant_types
|
|
37
|
+
Doorkeeper.configuration.token_grant_types
|
|
38
|
+
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
def build_strategy_class(grant_or_request_type)
|
|
41
|
+
strategy_class_name = grant_or_request_type.to_s.tr(' ', '_').camelize
|
|
42
|
+
"Doorkeeper::Request::#{strategy_class_name}".constantize
|
|
43
|
+
end
|
|
43
44
|
end
|
|
44
|
-
private_class_method :strategy_class
|
|
45
45
|
end
|
|
46
46
|
end
|
data/lib/doorkeeper/version.rb
CHANGED
|
@@ -5,11 +5,12 @@ module Doorkeeper
|
|
|
5
5
|
|
|
6
6
|
module VERSION
|
|
7
7
|
# Semantic versioning
|
|
8
|
-
MAJOR =
|
|
9
|
-
MINOR =
|
|
10
|
-
TINY =
|
|
8
|
+
MAJOR = 5
|
|
9
|
+
MINOR = 0
|
|
10
|
+
TINY = 0
|
|
11
|
+
PRE = 'rc1'
|
|
11
12
|
|
|
12
13
|
# Full version number
|
|
13
|
-
STRING = [MAJOR, MINOR, TINY].compact.join('.')
|
|
14
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
|
14
15
|
end
|
|
15
16
|
end
|
data/lib/doorkeeper.rb
CHANGED
|
@@ -8,12 +8,14 @@ require 'doorkeeper/request'
|
|
|
8
8
|
require 'doorkeeper/validations'
|
|
9
9
|
|
|
10
10
|
require 'doorkeeper/oauth/authorization/code'
|
|
11
|
+
require 'doorkeeper/oauth/authorization/context'
|
|
11
12
|
require 'doorkeeper/oauth/authorization/token'
|
|
12
13
|
require 'doorkeeper/oauth/authorization/uri_builder'
|
|
13
14
|
require 'doorkeeper/oauth/helpers/scope_checker'
|
|
14
15
|
require 'doorkeeper/oauth/helpers/uri_checker'
|
|
15
16
|
require 'doorkeeper/oauth/helpers/unique_token'
|
|
16
17
|
|
|
18
|
+
require 'doorkeeper/oauth'
|
|
17
19
|
require 'doorkeeper/oauth/scopes'
|
|
18
20
|
require 'doorkeeper/oauth/error'
|
|
19
21
|
require 'doorkeeper/oauth/base_response'
|
|
@@ -49,26 +51,11 @@ require 'doorkeeper/helpers/controller'
|
|
|
49
51
|
require 'doorkeeper/rails/routes'
|
|
50
52
|
require 'doorkeeper/rails/helpers'
|
|
51
53
|
|
|
52
|
-
require 'doorkeeper/
|
|
54
|
+
require 'doorkeeper/rake'
|
|
53
55
|
|
|
54
|
-
require '
|
|
56
|
+
require 'doorkeeper/orm/active_record'
|
|
55
57
|
|
|
56
58
|
module Doorkeeper
|
|
57
|
-
def self.configured?
|
|
58
|
-
ActiveSupport::Deprecation.warn "Method `Doorkeeper#configured?` has been deprecated without replacement."
|
|
59
|
-
@config.present?
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def self.database_installed?
|
|
63
|
-
ActiveSupport::Deprecation.warn "Method `Doorkeeper#database_installed?` has been deprecated without replacement."
|
|
64
|
-
[AccessToken, AccessGrant, Application].all?(&:table_exists?)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def self.installed?
|
|
68
|
-
ActiveSupport::Deprecation.warn "Method `Doorkeeper#installed?` has been deprecated without replacement."
|
|
69
|
-
configured? && database_installed?
|
|
70
|
-
end
|
|
71
|
-
|
|
72
59
|
def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
|
|
73
60
|
OAuth::Token.authenticate(request, *methods)
|
|
74
61
|
end
|
|
@@ -1,27 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
1
4
|
require 'rails/generators/active_record'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class ApplicationOwnerGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Provide support for client application ownership.'
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
def application_owner
|
|
13
|
+
migration_template(
|
|
14
|
+
'add_owner_to_application_migration.rb.erb',
|
|
15
|
+
'db/migrate/add_owner_to_application.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
private
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
25
30
|
end
|
|
26
31
|
end
|
|
27
32
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/active_record'
|
|
5
|
+
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class ConfidentialApplicationsGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Add confidential column to Doorkeeper applications'
|
|
11
|
+
|
|
12
|
+
def pkce
|
|
13
|
+
migration_template(
|
|
14
|
+
'add_confidential_to_applications.rb.erb',
|
|
15
|
+
'db/migrate/add_confidential_to_applications.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
include Rails::Generators::Migration
|
|
3
|
-
source_root File.expand_path('../templates', __FILE__)
|
|
4
|
-
desc 'Installs Doorkeeper.'
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/active_record'
|
|
5
|
+
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Installs Doorkeeper.'
|
|
11
|
+
|
|
12
|
+
def install
|
|
13
|
+
template 'initializer.rb', 'config/initializers/doorkeeper.rb'
|
|
14
|
+
copy_file File.expand_path('../../../config/locales/en.yml', __dir__),
|
|
15
|
+
'config/locales/doorkeeper.en.yml'
|
|
16
|
+
route 'use_doorkeeper'
|
|
17
|
+
readme 'README'
|
|
18
|
+
end
|
|
11
19
|
end
|
|
12
20
|
end
|
|
@@ -1,27 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
1
4
|
require 'rails/generators/active_record'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class MigrationGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Installs Doorkeeper migration file.'
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
def install
|
|
13
|
+
migration_template(
|
|
14
|
+
'migration.rb.erb',
|
|
15
|
+
'db/migrate/create_doorkeeper_tables.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
private
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
25
30
|
end
|
|
26
31
|
end
|
|
27
32
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/active_record'
|
|
5
|
+
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class PkceGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Provide support for PKCE.'
|
|
11
|
+
|
|
12
|
+
def pkce
|
|
13
|
+
migration_template(
|
|
14
|
+
'enable_pkce_migration.rb.erb',
|
|
15
|
+
'db/migrate/enable_pkce.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|