doorkeeper 4.2.6 → 4.3.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/.github/ISSUE_TEMPLATE.md +19 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +17 -0
- data/.gitignore +1 -1
- data/.hound.yml +2 -13
- data/.rubocop.yml +13 -0
- data/.travis.yml +13 -5
- data/Appraisals +6 -2
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +1 -1
- data/NEWS.md +24 -0
- data/README.md +39 -9
- data/SECURITY.md +13 -0
- data/app/controllers/doorkeeper/application_controller.rb +1 -5
- data/app/controllers/doorkeeper/applications_controller.rb +14 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +13 -1
- data/app/helpers/doorkeeper/dashboard_helper.rb +4 -2
- data/app/validators/redirect_uri_validator.rb +12 -2
- data/app/views/doorkeeper/applications/_form.html.erb +1 -1
- data/app/views/doorkeeper/authorized_applications/index.html.erb +0 -1
- data/config/locales/en.yml +3 -5
- data/doorkeeper.gemspec +4 -3
- data/gemfiles/rails_4_2.gemfile +6 -4
- data/gemfiles/rails_5_0.gemfile +4 -4
- data/gemfiles/rails_5_1.gemfile +6 -7
- data/gemfiles/rails_5_2.gemfile +12 -0
- data/gemfiles/rails_master.gemfile +14 -0
- data/lib/doorkeeper.rb +1 -0
- data/lib/doorkeeper/config.rb +55 -55
- data/lib/doorkeeper/engine.rb +3 -3
- data/lib/doorkeeper/grape/helpers.rb +13 -8
- data/lib/doorkeeper/helpers/controller.rb +8 -4
- data/lib/doorkeeper/models/access_token_mixin.rb +14 -7
- data/lib/doorkeeper/models/application_mixin.rb +11 -6
- data/lib/doorkeeper/models/concerns/expirable.rb +7 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +22 -18
- data/lib/doorkeeper/oauth/authorization_code_request.rb +6 -1
- data/lib/doorkeeper/oauth/base_request.rb +5 -5
- data/lib/doorkeeper/oauth/client.rb +2 -2
- data/lib/doorkeeper/oauth/client/credentials.rb +2 -2
- data/lib/doorkeeper/oauth/error.rb +2 -2
- data/lib/doorkeeper/oauth/error_response.rb +1 -2
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -3
- data/lib/doorkeeper/oauth/password_access_token_request.rb +1 -0
- data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -0
- data/lib/doorkeeper/oauth/scopes.rb +18 -8
- data/lib/doorkeeper/oauth/token.rb +1 -1
- data/lib/doorkeeper/oauth/token_introspection.rb +128 -0
- data/lib/doorkeeper/orm/active_record.rb +20 -8
- data/lib/doorkeeper/orm/active_record/access_grant.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_token.rb +1 -23
- data/lib/doorkeeper/orm/active_record/application.rb +1 -1
- data/lib/doorkeeper/orm/active_record/base_record.rb +11 -0
- data/lib/doorkeeper/rails/helpers.rb +5 -6
- data/lib/doorkeeper/rails/routes.rb +9 -7
- data/lib/doorkeeper/request.rb +7 -1
- data/lib/doorkeeper/validations.rb +3 -2
- data/lib/doorkeeper/version.rb +13 -1
- data/lib/generators/doorkeeper/application_owner_generator.rb +11 -2
- data/lib/generators/doorkeeper/migration_generator.rb +13 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -1
- data/lib/generators/doorkeeper/templates/{add_owner_to_application_migration.rb → add_owner_to_application_migration.rb.erb} +1 -1
- data/lib/generators/doorkeeper/templates/{add_previous_refresh_token_to_access_tokens.rb → add_previous_refresh_token_to_access_tokens.rb.erb} +1 -1
- data/lib/generators/doorkeeper/templates/initializer.rb +19 -3
- data/lib/generators/doorkeeper/templates/{migration.rb → migration.rb.erb} +1 -1
- data/spec/controllers/applications_controller_spec.rb +15 -4
- data/spec/controllers/authorizations_controller_spec.rb +5 -5
- data/spec/controllers/protected_resources_controller_spec.rb +28 -19
- data/spec/controllers/token_info_controller_spec.rb +17 -13
- data/spec/controllers/tokens_controller_spec.rb +138 -4
- data/spec/dummy/config/initializers/doorkeeper.rb +1 -1
- data/spec/dummy/config/initializers/{active_record_belongs_to_required_by_default.rb → new_framework_defaults.rb} +1 -1
- data/spec/dummy/config/initializers/secret_token.rb +0 -1
- data/spec/factories.rb +1 -1
- data/spec/generators/application_owner_generator_spec.rb +24 -5
- data/spec/generators/migration_generator_spec.rb +24 -3
- data/spec/generators/previous_refresh_token_generator_spec.rb +57 -0
- data/spec/grape/grape_integration_spec.rb +135 -0
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +115 -12
- data/spec/lib/models/revocable_spec.rb +2 -2
- data/spec/lib/oauth/authorization_code_request_spec.rb +39 -11
- data/spec/lib/oauth/base_request_spec.rb +2 -7
- data/spec/lib/oauth/client_credentials/creator_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials_request_spec.rb +1 -0
- data/spec/lib/oauth/code_request_spec.rb +1 -3
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -0
- data/spec/lib/oauth/invalid_token_response_spec.rb +1 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +9 -3
- data/spec/lib/oauth/refresh_token_request_spec.rb +19 -7
- data/spec/lib/oauth/scopes_spec.rb +28 -1
- data/spec/lib/oauth/token_request_spec.rb +6 -8
- data/spec/lib/server_spec.rb +10 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +1 -1
- data/spec/models/doorkeeper/access_token_spec.rb +72 -48
- data/spec/models/doorkeeper/application_spec.rb +51 -18
- data/spec/requests/applications/applications_request_spec.rb +5 -5
- data/spec/requests/endpoints/token_spec.rb +8 -1
- data/spec/requests/flows/authorization_code_spec.rb +1 -0
- data/spec/requests/flows/client_credentials_spec.rb +1 -1
- data/spec/requests/flows/implicit_grant_errors_spec.rb +2 -2
- data/spec/requests/flows/refresh_token_spec.rb +4 -4
- data/spec/requests/flows/revoke_token_spec.rb +15 -15
- 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 +4 -0
- data/spec/routing/default_routes_spec.rb +5 -1
- data/spec/spec_helper_integration.rb +15 -4
- data/spec/support/dependencies/factory_girl.rb +2 -2
- data/spec/support/helpers/access_token_request_helper.rb +1 -1
- data/spec/support/helpers/model_helper.rb +9 -4
- data/spec/support/helpers/request_spec_helper.rb +7 -3
- data/spec/support/helpers/url_helper.rb +8 -8
- data/spec/support/shared/controllers_shared_context.rb +2 -6
- data/spec/support/shared/models_shared_examples.rb +4 -4
- data/spec/validators/redirect_uri_validator_spec.rb +51 -6
- data/spec/version/version_spec.rb +15 -0
- metadata +42 -13
@@ -11,7 +11,8 @@ class RedirectUriValidator < ActiveModel::EachValidator
|
|
11
11
|
else
|
12
12
|
value.split.each do |val|
|
13
13
|
uri = ::URI.parse(val)
|
14
|
-
|
14
|
+
next if native_redirect_uri?(uri)
|
15
|
+
record.errors.add(attribute, :forbidden_uri) if forbidden_uri?(uri)
|
15
16
|
record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
|
16
17
|
record.errors.add(attribute, :relative_uri) if uri.scheme.nil? || uri.host.nil?
|
17
18
|
record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
|
@@ -27,8 +28,17 @@ class RedirectUriValidator < ActiveModel::EachValidator
|
|
27
28
|
self.class.native_redirect_uri.present? && uri.to_s == self.class.native_redirect_uri.to_s
|
28
29
|
end
|
29
30
|
|
31
|
+
def forbidden_uri?(uri)
|
32
|
+
Doorkeeper.configuration.forbid_redirect_uri.call(uri)
|
33
|
+
end
|
34
|
+
|
30
35
|
def invalid_ssl_uri?(uri)
|
31
36
|
forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
|
32
|
-
|
37
|
+
|
38
|
+
if forces_ssl.respond_to?(:call)
|
39
|
+
forces_ssl.call(uri)
|
40
|
+
else
|
41
|
+
forces_ssl && uri.try(:scheme) == 'http'
|
42
|
+
end
|
33
43
|
end
|
34
44
|
end
|
@@ -41,7 +41,7 @@
|
|
41
41
|
<div class="form-group">
|
42
42
|
<div class="col-sm-offset-2 col-sm-10">
|
43
43
|
<%= f.submit t('doorkeeper.applications.buttons.submit'), class: "btn btn-primary" %>
|
44
|
-
<%= link_to t('doorkeeper.applications.buttons.cancel'), oauth_applications_path, :
|
44
|
+
<%= link_to t('doorkeeper.applications.buttons.cancel'), oauth_applications_path, class: "btn btn-default" %>
|
45
45
|
</div>
|
46
46
|
</div>
|
47
47
|
<% end %>
|
data/config/locales/en.yml
CHANGED
@@ -13,6 +13,7 @@ en:
|
|
13
13
|
invalid_uri: 'must be a valid URI.'
|
14
14
|
relative_uri: 'must be an absolute URI.'
|
15
15
|
secured_uri: 'must be an HTTPS/SSL URI.'
|
16
|
+
forbidden_uri: 'is forbidden by the server.'
|
16
17
|
|
17
18
|
doorkeeper:
|
18
19
|
applications:
|
@@ -28,7 +29,7 @@ en:
|
|
28
29
|
error: 'Whoops! Check your form for possible errors'
|
29
30
|
help:
|
30
31
|
redirect_uri: 'Use one line per URI'
|
31
|
-
native_redirect_uri: 'Use %{native_redirect_uri} for
|
32
|
+
native_redirect_uri: 'Use %{native_redirect_uri} if you want to add localhost URIs for development purposes'
|
32
33
|
scopes: 'Separate scopes with spaces. Leave blank to use the default scopes.'
|
33
34
|
edit:
|
34
35
|
title: 'Edit application'
|
@@ -75,7 +76,7 @@ en:
|
|
75
76
|
messages:
|
76
77
|
# Common error messages
|
77
78
|
invalid_request: 'The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.'
|
78
|
-
invalid_redirect_uri:
|
79
|
+
invalid_redirect_uri: "The requested redirect uri is malformed or doesn't match client redirect URI."
|
79
80
|
unauthorized_client: 'The client is not authorized to perform this request using this method.'
|
80
81
|
access_denied: 'The resource owner or authorization server denied the request.'
|
81
82
|
invalid_scope: 'The requested scope is invalid, unknown, or malformed.'
|
@@ -94,9 +95,6 @@ en:
|
|
94
95
|
invalid_grant: 'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.'
|
95
96
|
unsupported_grant_type: 'The authorization grant type is not supported by the authorization server.'
|
96
97
|
|
97
|
-
# Password Access token errors
|
98
|
-
invalid_resource_owner: 'The provided resource owner credentials are not valid, or resource owner cannot be found'
|
99
|
-
|
100
98
|
invalid_token:
|
101
99
|
revoked: "The access token was revoked"
|
102
100
|
expired: "The access token expired"
|
data/doorkeeper.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "doorkeeper/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "doorkeeper"
|
7
|
-
s.version = Doorkeeper
|
7
|
+
s.version = Doorkeeper.gem_version
|
8
8
|
s.authors = ["Felipe Elias Philipp", "Tute Costa", "Jon Moss"]
|
9
9
|
s.email = %w(me@jonathanmoss.me)
|
10
10
|
s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
|
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_development_dependency "capybara"
|
23
23
|
s.add_development_dependency "coveralls"
|
24
|
-
s.add_development_dependency "
|
25
|
-
s.add_development_dependency "
|
24
|
+
s.add_development_dependency "grape"
|
25
|
+
s.add_development_dependency "database_cleaner", "~> 1.6"
|
26
|
+
s.add_development_dependency "factory_bot", "~> 4.8"
|
26
27
|
s.add_development_dependency "generator_spec", "~> 0.9.3"
|
27
28
|
s.add_development_dependency "rake", ">= 11.3.0"
|
28
29
|
s.add_development_dependency "rspec-rails"
|
data/gemfiles/rails_4_2.gemfile
CHANGED
@@ -4,8 +4,10 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rails", "~> 4.2.0"
|
6
6
|
gem "appraisal"
|
7
|
-
gem "activerecord-jdbcsqlite3-adapter", :
|
8
|
-
gem "sqlite3", :
|
9
|
-
gem "tzinfo-data", :
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
|
9
|
+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
|
10
|
+
# Older Grape requires Ruby >= 2.2.2
|
11
|
+
gem "grape", '~> 0.16', '< 0.19.2'
|
10
12
|
|
11
|
-
gemspec :
|
13
|
+
gemspec path: "../"
|
data/gemfiles/rails_5_0.gemfile
CHANGED
@@ -4,9 +4,9 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rails", "~> 5.0.0"
|
6
6
|
gem "appraisal"
|
7
|
-
gem "activerecord-jdbcsqlite3-adapter", :
|
8
|
-
gem "sqlite3", :
|
9
|
-
gem "tzinfo-data", :
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
8
|
+
gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
|
9
|
+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
|
10
10
|
gem "rspec-rails", "~> 3.5"
|
11
11
|
|
12
|
-
gemspec :
|
12
|
+
gemspec path: "../"
|
data/gemfiles/rails_5_1.gemfile
CHANGED
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails",
|
5
|
+
gem "rails", "~> 5.1.0"
|
6
6
|
gem "appraisal"
|
7
|
-
gem "activerecord-jdbcsqlite3-adapter", :
|
8
|
-
gem "sqlite3", :
|
9
|
-
gem "tzinfo-data", :
|
10
|
-
gem "
|
11
|
-
gem "rspec-rails", "~> 3.5"
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
8
|
+
gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
|
9
|
+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
|
10
|
+
gem "rspec-rails", "~> 3.7"
|
12
11
|
|
13
|
-
gemspec :
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "5.2.0.rc1"
|
6
|
+
gem "appraisal"
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
8
|
+
gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
|
9
|
+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
|
10
|
+
gem "rspec-rails", "~> 3.7"
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", git: 'https://github.com/rails/rails'
|
6
|
+
gem "arel", git: 'https://github.com/rails/arel'
|
7
|
+
|
8
|
+
gem "appraisal"
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
|
10
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
|
11
|
+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
|
12
|
+
gem "rspec-rails", "~> 3.7"
|
13
|
+
|
14
|
+
gemspec path: "../"
|
data/lib/doorkeeper.rb
CHANGED
@@ -30,6 +30,7 @@ require 'doorkeeper/oauth/code_request'
|
|
30
30
|
require 'doorkeeper/oauth/token_request'
|
31
31
|
require 'doorkeeper/oauth/client'
|
32
32
|
require 'doorkeeper/oauth/token'
|
33
|
+
require 'doorkeeper/oauth/token_introspection'
|
33
34
|
require 'doorkeeper/oauth/invalid_token_response'
|
34
35
|
require 'doorkeeper/oauth/forbidden_token_response'
|
35
36
|
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -59,12 +59,12 @@ doorkeeper.
|
|
59
59
|
# @option opts[Boolean] :confirmation (false)
|
60
60
|
# Set confirm_application_owner variable
|
61
61
|
def enable_application_owner(opts = {})
|
62
|
-
@config.instance_variable_set(
|
62
|
+
@config.instance_variable_set(:@enable_application_owner, true)
|
63
63
|
confirm_application_owner if opts[:confirmation].present? && opts[:confirmation]
|
64
64
|
end
|
65
65
|
|
66
66
|
def confirm_application_owner
|
67
|
-
@config.instance_variable_set(
|
67
|
+
@config.instance_variable_set(:@confirm_application_owner, true)
|
68
68
|
end
|
69
69
|
|
70
70
|
# Define default access token scopes for your provider
|
@@ -72,7 +72,7 @@ doorkeeper.
|
|
72
72
|
# @param scopes [Array] Default set of access (OAuth::Scopes.new)
|
73
73
|
# token scopes
|
74
74
|
def default_scopes(*scopes)
|
75
|
-
@config.instance_variable_set(
|
75
|
+
@config.instance_variable_set(:@default_scopes, OAuth::Scopes.from_array(scopes))
|
76
76
|
end
|
77
77
|
|
78
78
|
# Define default access token scopes for your provider
|
@@ -80,7 +80,7 @@ doorkeeper.
|
|
80
80
|
# @param scopes [Array] Optional set of access (OAuth::Scopes.new)
|
81
81
|
# token scopes
|
82
82
|
def optional_scopes(*scopes)
|
83
|
-
@config.instance_variable_set(
|
83
|
+
@config.instance_variable_set(:@optional_scopes, OAuth::Scopes.from_array(scopes))
|
84
84
|
end
|
85
85
|
|
86
86
|
# Change the way client credentials are retrieved from the request object.
|
@@ -90,7 +90,7 @@ doorkeeper.
|
|
90
90
|
#
|
91
91
|
# @param methods [Array] Define client credentials
|
92
92
|
def client_credentials(*methods)
|
93
|
-
@config.instance_variable_set(
|
93
|
+
@config.instance_variable_set(:@client_credentials, methods)
|
94
94
|
end
|
95
95
|
|
96
96
|
# Change the way access token is authenticated from the request object.
|
@@ -100,57 +100,19 @@ doorkeeper.
|
|
100
100
|
#
|
101
101
|
# @param methods [Array] Define access token methods
|
102
102
|
def access_token_methods(*methods)
|
103
|
-
@config.instance_variable_set(
|
103
|
+
@config.instance_variable_set(:@access_token_methods, methods)
|
104
104
|
end
|
105
105
|
|
106
106
|
# Issue access tokens with refresh token (disabled by default)
|
107
107
|
def use_refresh_token
|
108
|
-
@config.instance_variable_set(
|
109
|
-
end
|
110
|
-
|
111
|
-
# WWW-Authenticate Realm (default "Doorkeeper").
|
112
|
-
#
|
113
|
-
# @param realm [String] ("Doorkeeper") Authentication realm
|
114
|
-
def realm(realm)
|
115
|
-
@config.instance_variable_set('@realm', realm)
|
108
|
+
@config.instance_variable_set(:@refresh_token_enabled, true)
|
116
109
|
end
|
117
110
|
|
118
111
|
# Reuse access token for the same resource owner within an application
|
119
112
|
# (disabled by default)
|
120
113
|
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
|
121
114
|
def reuse_access_token
|
122
|
-
@config.instance_variable_set(
|
123
|
-
end
|
124
|
-
|
125
|
-
# Forces the usage of the HTTPS protocol in non-native redirect uris
|
126
|
-
# (enabled by default in non-development environments). OAuth2
|
127
|
-
# delegates security in communication to the HTTPS protocol so it is
|
128
|
-
# wise to keep this enabled.
|
129
|
-
#
|
130
|
-
# @param [Boolean] boolean value for the parameter, true by default in
|
131
|
-
# non-development environment
|
132
|
-
def force_ssl_in_redirect_uri(boolean)
|
133
|
-
@config.instance_variable_set("@force_ssl_in_redirect_uri", boolean)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Use a custom class for generating the access token.
|
137
|
-
# https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
|
138
|
-
#
|
139
|
-
# @param access_token_generator [String]
|
140
|
-
# the name of the access token generator class
|
141
|
-
def access_token_generator(access_token_generator)
|
142
|
-
@config.instance_variable_set(
|
143
|
-
'@access_token_generator', access_token_generator
|
144
|
-
)
|
145
|
-
end
|
146
|
-
|
147
|
-
# The controller Doorkeeper::ApplicationController inherits from.
|
148
|
-
# Defaults to ActionController::Base.
|
149
|
-
# https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
|
150
|
-
#
|
151
|
-
# @param base_controller [String] the name of the base controller
|
152
|
-
def base_controller(base_controller)
|
153
|
-
@config.instance_variable_set('@base_controller', base_controller)
|
115
|
+
@config.instance_variable_set(:@reuse_access_token, true)
|
154
116
|
end
|
155
117
|
end
|
156
118
|
|
@@ -210,10 +172,6 @@ doorkeeper.
|
|
210
172
|
|
211
173
|
public attribute
|
212
174
|
end
|
213
|
-
|
214
|
-
def extended(base)
|
215
|
-
base.send(:private, :option)
|
216
|
-
end
|
217
175
|
end
|
218
176
|
|
219
177
|
extend Option
|
@@ -221,15 +179,17 @@ doorkeeper.
|
|
221
179
|
option :resource_owner_authenticator,
|
222
180
|
as: :authenticate_resource_owner,
|
223
181
|
default: (lambda do |_routes|
|
224
|
-
logger.warn(I18n.
|
182
|
+
::Rails.logger.warn(I18n.t('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))
|
225
183
|
nil
|
226
184
|
end)
|
185
|
+
|
227
186
|
option :admin_authenticator,
|
228
187
|
as: :authenticate_admin,
|
229
188
|
default: ->(_routes) {}
|
189
|
+
|
230
190
|
option :resource_owner_from_credentials,
|
231
191
|
default: (lambda do |_routes|
|
232
|
-
warn(I18n.
|
192
|
+
::Rails.logger.warn(I18n.t('doorkeeper.errors.messages.credential_flow_not_configured'))
|
233
193
|
nil
|
234
194
|
end)
|
235
195
|
|
@@ -240,11 +200,51 @@ doorkeeper.
|
|
240
200
|
option :orm, default: :active_record
|
241
201
|
option :native_redirect_uri, default: 'urn:ietf:wg:oauth:2.0:oob'
|
242
202
|
option :active_record_options, default: {}
|
203
|
+
option :grant_flows, default: %w[authorization_code client_credentials]
|
204
|
+
|
205
|
+
# Allows to forbid specific Application redirect URI's by custom rules.
|
206
|
+
# Doesn't forbid any URI by default.
|
207
|
+
#
|
208
|
+
# @param forbid_redirect_uri [Proc] Block or any object respond to #call
|
209
|
+
#
|
210
|
+
option :forbid_redirect_uri, default: ->(_uri) { false }
|
211
|
+
|
212
|
+
# WWW-Authenticate Realm (default "Doorkeeper").
|
213
|
+
#
|
214
|
+
# @param realm [String] ("Doorkeeper") Authentication realm
|
215
|
+
#
|
243
216
|
option :realm, default: 'Doorkeeper'
|
217
|
+
|
218
|
+
# Forces the usage of the HTTPS protocol in non-native redirect uris
|
219
|
+
# (enabled by default in non-development environments). OAuth2
|
220
|
+
# delegates security in communication to the HTTPS protocol so it is
|
221
|
+
# wise to keep this enabled.
|
222
|
+
#
|
223
|
+
# @param [Boolean] boolean_or_block value for the parameter, true by default in
|
224
|
+
# non-development environment
|
225
|
+
#
|
226
|
+
# @yield [uri] Conditional usage of SSL redirect uris.
|
227
|
+
# @yieldparam [URI] Redirect URI
|
228
|
+
# @yieldreturn [Boolean] Indicates necessity of usage of the HTTPS protocol
|
229
|
+
# in non-native redirect uris
|
230
|
+
#
|
244
231
|
option :force_ssl_in_redirect_uri, default: !Rails.env.development?
|
245
|
-
|
232
|
+
|
233
|
+
|
234
|
+
# Use a custom class for generating the access token.
|
235
|
+
# https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
|
236
|
+
#
|
237
|
+
# @param access_token_generator [String]
|
238
|
+
# the name of the access token generator class
|
239
|
+
#
|
246
240
|
option :access_token_generator,
|
247
241
|
default: 'Doorkeeper::OAuth::Helpers::UniqueToken'
|
242
|
+
|
243
|
+
# The controller Doorkeeper::ApplicationController inherits from.
|
244
|
+
# Defaults to ActionController::Base.
|
245
|
+
# https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
|
246
|
+
#
|
247
|
+
# @param base_controller [String] the name of the base controller
|
248
248
|
option :base_controller,
|
249
249
|
default: 'ActionController::Base'
|
250
250
|
|
@@ -278,11 +278,11 @@ doorkeeper.
|
|
278
278
|
end
|
279
279
|
|
280
280
|
def client_credentials_methods
|
281
|
-
@client_credentials ||= [
|
281
|
+
@client_credentials ||= %i[from_basic from_params]
|
282
282
|
end
|
283
283
|
|
284
284
|
def access_token_methods
|
285
|
-
@access_token_methods ||= [
|
285
|
+
@access_token_methods ||= %i[from_bearer_authorization from_access_token_param from_bearer_param]
|
286
286
|
end
|
287
287
|
|
288
288
|
def authorization_response_types
|
data/lib/doorkeeper/engine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
initializer "doorkeeper.params.filter" do |app|
|
4
|
-
parameters = %w
|
4
|
+
parameters = %w[client_secret code authentication_token access_token refresh_token]
|
5
5
|
app.config.filter_parameters << /^(#{Regexp.union parameters})$/
|
6
6
|
end
|
7
7
|
|
@@ -17,10 +17,10 @@ module Doorkeeper
|
|
17
17
|
|
18
18
|
if defined?(Sprockets) && Sprockets::VERSION.chr.to_i >= 4
|
19
19
|
initializer 'doorkeeper.assets.precompile' do |app|
|
20
|
-
app.config.assets.precompile += %w
|
20
|
+
app.config.assets.precompile += %w[
|
21
21
|
doorkeeper/application.css
|
22
22
|
doorkeeper/admin/application.css
|
23
|
-
|
23
|
+
]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -9,7 +9,7 @@ module Doorkeeper
|
|
9
9
|
|
10
10
|
# endpoint specific scopes > parameter scopes > default scopes
|
11
11
|
def doorkeeper_authorize!(*scopes)
|
12
|
-
endpoint_scopes =
|
12
|
+
endpoint_scopes = endpoint.route_setting(:scopes) || endpoint.options[:route_options][:scopes]
|
13
13
|
scopes = if endpoint_scopes
|
14
14
|
Doorkeeper::OAuth::Scopes.from_array(endpoint_scopes)
|
15
15
|
elsif scopes && !scopes.empty?
|
@@ -20,18 +20,16 @@ module Doorkeeper
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def doorkeeper_render_error_with(error)
|
23
|
-
status_code =
|
24
|
-
when :unauthorized
|
25
|
-
401
|
26
|
-
when :forbidden
|
27
|
-
403
|
28
|
-
end
|
29
|
-
|
23
|
+
status_code = error_status_codes[error.status]
|
30
24
|
error!({ error: error.description }, status_code, error.headers)
|
31
25
|
end
|
32
26
|
|
33
27
|
private
|
34
28
|
|
29
|
+
def endpoint
|
30
|
+
env['api.endpoint']
|
31
|
+
end
|
32
|
+
|
35
33
|
def doorkeeper_token
|
36
34
|
@_doorkeeper_token ||= OAuth::Token.authenticate(
|
37
35
|
decorated_request,
|
@@ -42,6 +40,13 @@ module Doorkeeper
|
|
42
40
|
def decorated_request
|
43
41
|
AuthorizationDecorator.new(request)
|
44
42
|
end
|
43
|
+
|
44
|
+
def error_status_codes
|
45
|
+
{
|
46
|
+
unauthorized: 401,
|
47
|
+
forbidden: 403
|
48
|
+
}
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|