doorkeeper 3.1.0 → 4.2.6
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/.coveralls.yml +1 -0
- data/.gitignore +5 -0
- data/.travis.yml +16 -12
- data/Appraisals +14 -0
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +5 -5
- data/NEWS.md +83 -2
- data/README.md +73 -43
- data/RELEASING.md +5 -12
- data/Rakefile +1 -1
- data/app/controllers/doorkeeper/application_controller.rb +3 -1
- data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
- data/app/controllers/doorkeeper/applications_controller.rb +3 -7
- data/app/controllers/doorkeeper/authorizations_controller.rb +1 -1
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +50 -14
- data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
- data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -2
- data/app/views/doorkeeper/applications/_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
- data/app/views/doorkeeper/authorized_applications/_delete_form.html.erb +1 -2
- data/app/views/layouts/doorkeeper/admin.html.erb +1 -1
- data/config/locales/en.yml +3 -2
- data/doorkeeper.gemspec +12 -10
- data/gemfiles/rails_4_2.gemfile +11 -0
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/gemfiles/rails_5_1.gemfile +13 -0
- data/lib/doorkeeper/config.rb +73 -16
- data/lib/doorkeeper/engine.rb +11 -7
- data/lib/doorkeeper/errors.rb +18 -0
- data/lib/doorkeeper/grape/helpers.rb +2 -1
- data/lib/doorkeeper/helpers/controller.rb +8 -23
- data/lib/doorkeeper/models/access_grant_mixin.rb +21 -5
- data/lib/doorkeeper/models/access_token_mixin.rb +145 -23
- data/lib/doorkeeper/models/application_mixin.rb +21 -9
- data/lib/doorkeeper/models/concerns/accessible.rb +4 -0
- data/lib/doorkeeper/models/concerns/expirable.rb +10 -2
- data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +37 -2
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +20 -18
- data/lib/doorkeeper/oauth/authorization_code_request.rb +1 -4
- data/lib/doorkeeper/oauth/{request_concern.rb → base_request.rb} +3 -1
- data/lib/doorkeeper/oauth/base_response.rb +29 -0
- data/lib/doorkeeper/oauth/client/credentials.rb +17 -6
- data/lib/doorkeeper/oauth/client.rb +0 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +3 -2
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -8
- data/lib/doorkeeper/oauth/code_response.rb +16 -16
- data/lib/doorkeeper/oauth/error_response.rb +9 -8
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -13
- data/lib/doorkeeper/oauth/refresh_token_request.rb +22 -14
- data/lib/doorkeeper/oauth/scopes.rb +2 -2
- data/lib/doorkeeper/oauth/token.rb +20 -21
- data/lib/doorkeeper/oauth/token_request.rb +1 -2
- data/lib/doorkeeper/oauth/token_response.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_token.rb +25 -0
- data/lib/doorkeeper/orm/active_record/application.rb +12 -12
- data/lib/doorkeeper/orm/active_record.rb +0 -16
- data/lib/doorkeeper/rails/helpers.rb +1 -3
- data/lib/doorkeeper/rails/routes/mapper.rb +4 -4
- data/lib/doorkeeper/rails/routes/mapping.rb +1 -1
- data/lib/doorkeeper/rails/routes.rb +4 -4
- data/lib/doorkeeper/request/authorization_code.rb +7 -1
- data/lib/doorkeeper/request/password.rb +11 -1
- data/lib/doorkeeper/request/refresh_token.rb +1 -1
- data/lib/doorkeeper/server.rb +0 -8
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +8 -2
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
- data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +8 -3
- data/lib/generators/doorkeeper/templates/migration.rb +23 -5
- data/spec/controllers/application_metal_controller.rb +10 -0
- data/spec/controllers/authorizations_controller_spec.rb +39 -24
- data/spec/controllers/protected_resources_controller_spec.rb +47 -18
- data/spec/controllers/tokens_controller_spec.rb +1 -1
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -4
- data/spec/dummy/app/controllers/home_controller.rb +1 -1
- data/spec/dummy/app/controllers/metal_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +3 -3
- data/spec/dummy/app/models/user.rb +0 -4
- data/spec/dummy/config/application.rb +2 -36
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/test.rb +4 -15
- data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
- data/spec/dummy/db/migrate/{20130902165751_create_doorkeeper_tables.rb → 20151223192035_create_doorkeeper_tables.rb} +24 -5
- data/spec/dummy/db/migrate/{20130902175349_add_owner_to_application.rb → 20151223200000_add_owner_to_application.rb} +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
- data/spec/dummy/db/schema.rb +23 -22
- data/spec/factories.rb +3 -1
- data/spec/lib/config_spec.rb +19 -2
- data/spec/lib/doorkeeper_spec.rb +135 -13
- data/spec/lib/models/expirable_spec.rb +0 -1
- data/spec/lib/models/revocable_spec.rb +27 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +1 -2
- data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
- data/spec/lib/oauth/base_request_spec.rb +160 -0
- data/spec/lib/oauth/base_response_spec.rb +45 -0
- data/spec/lib/oauth/client/credentials_spec.rb +41 -0
- data/spec/lib/oauth/code_response_spec.rb +34 -0
- data/spec/lib/oauth/error_response_spec.rb +9 -9
- data/spec/lib/oauth/invalid_token_response_spec.rb +36 -8
- data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
- data/spec/lib/oauth/refresh_token_request_spec.rb +34 -3
- data/spec/lib/oauth/scopes_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +12 -5
- data/spec/lib/server_spec.rb +0 -3
- data/spec/models/doorkeeper/access_token_spec.rb +45 -1
- data/spec/models/doorkeeper/application_spec.rb +3 -11
- data/spec/requests/endpoints/authorization_spec.rb +5 -6
- data/spec/requests/flows/authorization_code_errors_spec.rb +11 -1
- data/spec/requests/flows/authorization_code_spec.rb +4 -12
- data/spec/requests/flows/password_spec.rb +26 -5
- data/spec/requests/flows/refresh_token_spec.rb +87 -17
- data/spec/requests/flows/revoke_token_spec.rb +100 -86
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_integration.rb +8 -1
- data/spec/support/helpers/model_helper.rb +27 -5
- data/spec/support/helpers/request_spec_helper.rb +12 -4
- data/spec/support/http_method_shim.rb +38 -0
- data/spec/support/shared/controllers_shared_context.rb +13 -4
- data/spec/support/shared/models_shared_examples.rb +1 -1
- metadata +72 -42
- data/lib/doorkeeper/oauth/client/methods.rb +0 -18
- data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
- data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
- data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +0 -5
- data/spec/lib/oauth/client/methods_spec.rb +0 -54
@@ -22,7 +22,7 @@
|
|
22
22
|
<code><%= uri %></code>
|
23
23
|
</td>
|
24
24
|
<td>
|
25
|
-
<%= link_to t('doorkeeper.applications.buttons.authorize'), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code'), class: 'btn btn-success', target: '_blank' %>
|
25
|
+
<%= link_to t('doorkeeper.applications.buttons.authorize'), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code', scope: @application.scopes), class: 'btn btn-success', target: '_blank' %>
|
26
26
|
</td>
|
27
27
|
</tr>
|
28
28
|
<% end %>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
<main role="main">
|
6
6
|
<p class="h4">
|
7
|
-
<%= raw t('.prompt', client_name:
|
7
|
+
<%= raw t('.prompt', client_name: content_tag(:strong, class: 'text-info') { @pre_auth.client.name }) %>
|
8
8
|
</p>
|
9
9
|
|
10
10
|
<% if @pre_auth.scopes.count > 0 %>
|
@@ -1,5 +1,4 @@
|
|
1
1
|
<%- submit_btn_css ||= 'btn btn-link' %>
|
2
|
-
<%= form_tag oauth_authorized_application_path(application) do %>
|
3
|
-
<input type="hidden" name="_method" value="delete">
|
2
|
+
<%= form_tag oauth_authorized_application_path(application), method: :delete do %>
|
4
3
|
<%= submit_tag t('doorkeeper.authorized_applications.buttons.revoke'), onclick: "return confirm('#{ t('doorkeeper.authorized_applications.confirmations.revoke') }')", class: submit_btn_css %>
|
5
4
|
<% end %>
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<%= link_to t('doorkeeper.layouts.admin.nav.applications'), oauth_applications_path %>
|
20
20
|
<% end %>
|
21
21
|
<%= content_tag :li do %>
|
22
|
-
<%= link_to '
|
22
|
+
<%= link_to t('doorkeeper.layouts.admin.nav.home'), root_path %>
|
23
23
|
<% end %>
|
24
24
|
</ul>
|
25
25
|
</div>
|
data/config/locales/en.yml
CHANGED
@@ -82,9 +82,9 @@ en:
|
|
82
82
|
server_error: 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.'
|
83
83
|
temporarily_unavailable: 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.'
|
84
84
|
|
85
|
-
#
|
85
|
+
# Configuration error messages
|
86
86
|
credential_flow_not_configured: 'Resource Owner Password Credentials flow failed due to Doorkeeper.configure.resource_owner_from_credentials being unconfigured.'
|
87
|
-
resource_owner_authenticator_not_configured: 'Resource Owner find failed due to Doorkeeper.configure.resource_owner_authenticator being
|
87
|
+
resource_owner_authenticator_not_configured: 'Resource Owner find failed due to Doorkeeper.configure.resource_owner_authenticator being unconfigured.'
|
88
88
|
|
89
89
|
# Access grant errors
|
90
90
|
unsupported_response_type: 'The authorization server does not support this response type.'
|
@@ -119,5 +119,6 @@ en:
|
|
119
119
|
nav:
|
120
120
|
oauth2_provider: 'OAuth2 Provider'
|
121
121
|
applications: 'Applications'
|
122
|
+
home: 'Home'
|
122
123
|
application:
|
123
124
|
title: 'OAuth authorization required'
|
data/doorkeeper.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
2
2
|
|
3
3
|
require "doorkeeper/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "doorkeeper"
|
7
7
|
s.version = Doorkeeper::VERSION
|
8
|
-
s.authors = ["Felipe Elias Philipp", "Tute Costa"]
|
9
|
-
s.email = %w(
|
8
|
+
s.authors = ["Felipe Elias Philipp", "Tute Costa", "Jon Moss"]
|
9
|
+
s.email = %w(me@jonathanmoss.me)
|
10
10
|
s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
|
11
11
|
s.summary = "OAuth 2 provider for Rails and Grape"
|
12
12
|
s.description = "Doorkeeper is an OAuth 2 provider for Rails and Grape."
|
@@ -16,12 +16,14 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_dependency "railties", ">=
|
19
|
+
s.add_dependency "railties", ">= 4.2"
|
20
|
+
s.required_ruby_version = ">= 2.1"
|
20
21
|
|
21
|
-
s.add_development_dependency "
|
22
|
-
s.add_development_dependency "
|
23
|
-
s.add_development_dependency "
|
24
|
-
s.add_development_dependency "factory_girl", "~> 4.
|
25
|
-
s.add_development_dependency "
|
26
|
-
s.add_development_dependency "
|
22
|
+
s.add_development_dependency "capybara"
|
23
|
+
s.add_development_dependency "coveralls"
|
24
|
+
s.add_development_dependency "database_cleaner", "~> 1.5.3"
|
25
|
+
s.add_development_dependency "factory_girl", "~> 4.7.0"
|
26
|
+
s.add_development_dependency "generator_spec", "~> 0.9.3"
|
27
|
+
s.add_development_dependency "rake", ">= 11.3.0"
|
28
|
+
s.add_development_dependency "rspec-rails"
|
27
29
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 4.2.0"
|
6
|
+
gem "appraisal"
|
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
|
+
|
11
|
+
gemspec :path => "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.0.0"
|
6
|
+
gem "appraisal"
|
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
|
+
gem "rspec-rails", "~> 3.5"
|
11
|
+
|
12
|
+
gemspec :path => "../"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", :github => "rails/rails"
|
6
|
+
gem "appraisal"
|
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
|
+
gem "arel", :github => "rails/arel"
|
11
|
+
gem "rspec-rails", "~> 3.5"
|
12
|
+
|
13
|
+
gemspec :path => "../"
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class MissingConfiguration < StandardError
|
3
|
+
# Defines a MissingConfiguration error for a missing Doorkeeper
|
4
|
+
# configuration
|
3
5
|
def initialize
|
4
6
|
super('Configuration for doorkeeper missing. Do you have doorkeeper initializer?')
|
5
7
|
end
|
@@ -10,15 +12,10 @@ module Doorkeeper
|
|
10
12
|
setup_orm_adapter
|
11
13
|
setup_orm_models
|
12
14
|
setup_application_owner if @config.enable_application_owner?
|
13
|
-
check_requirements
|
14
15
|
end
|
15
16
|
|
16
17
|
def self.configuration
|
17
|
-
@config || (fail MissingConfiguration
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.check_requirements
|
21
|
-
@orm_adapter.check_requirements!(configuration)
|
18
|
+
@config || (fail MissingConfiguration)
|
22
19
|
end
|
23
20
|
|
24
21
|
def self.setup_orm_adapter
|
@@ -52,6 +49,15 @@ doorkeeper.
|
|
52
49
|
@config
|
53
50
|
end
|
54
51
|
|
52
|
+
# Provide support for an owner to be assigned to each registered
|
53
|
+
# application (disabled by default)
|
54
|
+
# Optional parameter confirmation: true (default false) if you want
|
55
|
+
# to enforce ownership of a registered application
|
56
|
+
#
|
57
|
+
# @param opts [Hash] the options to confirm if an application owner
|
58
|
+
# is present
|
59
|
+
# @option opts[Boolean] :confirmation (false)
|
60
|
+
# Set confirm_application_owner variable
|
55
61
|
def enable_application_owner(opts = {})
|
56
62
|
@config.instance_variable_set('@enable_application_owner', true)
|
57
63
|
confirm_application_owner if opts[:confirmation].present? && opts[:confirmation]
|
@@ -61,43 +67,91 @@ doorkeeper.
|
|
61
67
|
@config.instance_variable_set('@confirm_application_owner', true)
|
62
68
|
end
|
63
69
|
|
70
|
+
# Define default access token scopes for your provider
|
71
|
+
#
|
72
|
+
# @param scopes [Array] Default set of access (OAuth::Scopes.new)
|
73
|
+
# token scopes
|
64
74
|
def default_scopes(*scopes)
|
65
75
|
@config.instance_variable_set('@default_scopes', OAuth::Scopes.from_array(scopes))
|
66
76
|
end
|
67
77
|
|
78
|
+
# Define default access token scopes for your provider
|
79
|
+
#
|
80
|
+
# @param scopes [Array] Optional set of access (OAuth::Scopes.new)
|
81
|
+
# token scopes
|
68
82
|
def optional_scopes(*scopes)
|
69
83
|
@config.instance_variable_set('@optional_scopes', OAuth::Scopes.from_array(scopes))
|
70
84
|
end
|
71
85
|
|
86
|
+
# Change the way client credentials are retrieved from the request object.
|
87
|
+
# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
|
88
|
+
# falls back to the `:client_id` and `:client_secret` params from the
|
89
|
+
# `params` object.
|
90
|
+
#
|
91
|
+
# @param methods [Array] Define client credentials
|
72
92
|
def client_credentials(*methods)
|
73
93
|
@config.instance_variable_set('@client_credentials', methods)
|
74
94
|
end
|
75
95
|
|
96
|
+
# Change the way access token is authenticated from the request object.
|
97
|
+
# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
|
98
|
+
# falls back to the `:access_token` or `:bearer_token` params from the
|
99
|
+
# `params` object.
|
100
|
+
#
|
101
|
+
# @param methods [Array] Define access token methods
|
76
102
|
def access_token_methods(*methods)
|
77
103
|
@config.instance_variable_set('@access_token_methods', methods)
|
78
104
|
end
|
79
105
|
|
106
|
+
# Issue access tokens with refresh token (disabled by default)
|
80
107
|
def use_refresh_token
|
81
108
|
@config.instance_variable_set('@refresh_token_enabled', true)
|
82
109
|
end
|
83
110
|
|
111
|
+
# WWW-Authenticate Realm (default "Doorkeeper").
|
112
|
+
#
|
113
|
+
# @param realm [String] ("Doorkeeper") Authentication realm
|
84
114
|
def realm(realm)
|
85
115
|
@config.instance_variable_set('@realm', realm)
|
86
116
|
end
|
87
117
|
|
118
|
+
# Reuse access token for the same resource owner within an application
|
119
|
+
# (disabled by default)
|
120
|
+
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
|
88
121
|
def reuse_access_token
|
89
122
|
@config.instance_variable_set("@reuse_access_token", true)
|
90
123
|
end
|
91
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
|
92
132
|
def force_ssl_in_redirect_uri(boolean)
|
93
133
|
@config.instance_variable_set("@force_ssl_in_redirect_uri", boolean)
|
94
134
|
end
|
95
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
|
96
141
|
def access_token_generator(access_token_generator)
|
97
142
|
@config.instance_variable_set(
|
98
143
|
'@access_token_generator', access_token_generator
|
99
144
|
)
|
100
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)
|
154
|
+
end
|
101
155
|
end
|
102
156
|
|
103
157
|
module Option
|
@@ -133,19 +187,20 @@ doorkeeper.
|
|
133
187
|
attribute_builder = options[:builder_class]
|
134
188
|
|
135
189
|
Builder.instance_eval do
|
190
|
+
remove_method name if method_defined?(name)
|
136
191
|
define_method name do |*args, &block|
|
137
192
|
# TODO: is builder_class option being used?
|
138
|
-
value =
|
139
|
-
block ? block : args.first
|
140
|
-
else
|
193
|
+
value = if attribute_builder
|
141
194
|
attribute_builder.new(&block).build
|
195
|
+
else
|
196
|
+
block ? block : args.first
|
142
197
|
end
|
143
198
|
|
144
199
|
@config.instance_variable_set(:"@#{attribute}", value)
|
145
200
|
end
|
146
201
|
end
|
147
202
|
|
148
|
-
define_method attribute do |*
|
203
|
+
define_method attribute do |*_args|
|
149
204
|
if instance_variable_defined?(:"@#{attribute}")
|
150
205
|
instance_variable_get(:"@#{attribute}")
|
151
206
|
else
|
@@ -180,7 +235,7 @@ doorkeeper.
|
|
180
235
|
|
181
236
|
option :skip_authorization, default: ->(_routes) {}
|
182
237
|
option :access_token_expires_in, default: 7200
|
183
|
-
option :custom_access_token_expires_in, default:
|
238
|
+
option :custom_access_token_expires_in, default: ->(_app) { nil }
|
184
239
|
option :authorization_code_expires_in, default: 600
|
185
240
|
option :orm, default: :active_record
|
186
241
|
option :native_redirect_uri, default: 'urn:ietf:wg:oauth:2.0:oob'
|
@@ -188,19 +243,25 @@ doorkeeper.
|
|
188
243
|
option :realm, default: 'Doorkeeper'
|
189
244
|
option :force_ssl_in_redirect_uri, default: !Rails.env.development?
|
190
245
|
option :grant_flows, default: %w(authorization_code client_credentials)
|
191
|
-
option :access_token_generator,
|
246
|
+
option :access_token_generator,
|
247
|
+
default: 'Doorkeeper::OAuth::Helpers::UniqueToken'
|
248
|
+
option :base_controller,
|
249
|
+
default: 'ActionController::Base'
|
192
250
|
|
193
251
|
attr_reader :reuse_access_token
|
194
252
|
|
195
253
|
def refresh_token_enabled?
|
254
|
+
@refresh_token_enabled ||= false
|
196
255
|
!!@refresh_token_enabled
|
197
256
|
end
|
198
257
|
|
199
258
|
def enable_application_owner?
|
259
|
+
@enable_application_owner ||= false
|
200
260
|
!!@enable_application_owner
|
201
261
|
end
|
202
262
|
|
203
263
|
def confirm_application_owner?
|
264
|
+
@confirm_application_owner ||= false
|
204
265
|
!!@confirm_application_owner
|
205
266
|
end
|
206
267
|
|
@@ -224,10 +285,6 @@ doorkeeper.
|
|
224
285
|
@access_token_methods ||= [:from_bearer_authorization, :from_access_token_param, :from_bearer_param]
|
225
286
|
end
|
226
287
|
|
227
|
-
def realm
|
228
|
-
@realm ||= 'Doorkeeper'
|
229
|
-
end
|
230
|
-
|
231
288
|
def authorization_response_types
|
232
289
|
@authorization_response_types ||= calculate_authorization_response_types
|
233
290
|
end
|
data/lib/doorkeeper/engine.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
initializer "doorkeeper.params.filter" do |app|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
initializer "doorkeeper.locales" do |app|
|
8
|
-
if app.config.i18n.fallbacks.blank?
|
9
|
-
app.config.i18n.fallbacks = [:en]
|
10
|
-
end
|
4
|
+
parameters = %w(client_secret code authentication_token access_token refresh_token)
|
5
|
+
app.config.filter_parameters << /^(#{Regexp.union parameters})$/
|
11
6
|
end
|
12
7
|
|
13
8
|
initializer "doorkeeper.routes" do
|
@@ -19,5 +14,14 @@ module Doorkeeper
|
|
19
14
|
include Doorkeeper::Rails::Helpers
|
20
15
|
end
|
21
16
|
end
|
17
|
+
|
18
|
+
if defined?(Sprockets) && Sprockets::VERSION.chr.to_i >= 4
|
19
|
+
initializer 'doorkeeper.assets.precompile' do |app|
|
20
|
+
app.config.assets.precompile += %w(
|
21
|
+
doorkeeper/application.css
|
22
|
+
doorkeeper/admin/application.css
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/doorkeeper/errors.rb
CHANGED
@@ -1,21 +1,39 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module Errors
|
3
3
|
class DoorkeeperError < StandardError
|
4
|
+
def type
|
5
|
+
message
|
6
|
+
end
|
4
7
|
end
|
5
8
|
|
6
9
|
class InvalidAuthorizationStrategy < DoorkeeperError
|
10
|
+
def type
|
11
|
+
:unsupported_response_type
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
9
15
|
class InvalidTokenReuse < DoorkeeperError
|
16
|
+
def type
|
17
|
+
:invalid_request
|
18
|
+
end
|
10
19
|
end
|
11
20
|
|
12
21
|
class InvalidGrantReuse < DoorkeeperError
|
22
|
+
def type
|
23
|
+
:invalid_grant
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
class InvalidTokenStrategy < DoorkeeperError
|
28
|
+
def type
|
29
|
+
:unsupported_grant_type
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
33
|
class MissingRequestStrategy < DoorkeeperError
|
34
|
+
def type
|
35
|
+
:invalid_request
|
36
|
+
end
|
19
37
|
end
|
20
38
|
|
21
39
|
class UnableToGenerateToken < DoorkeeperError
|
@@ -3,12 +3,13 @@ require 'doorkeeper/grape/authorization_decorator'
|
|
3
3
|
module Doorkeeper
|
4
4
|
module Grape
|
5
5
|
module Helpers
|
6
|
+
# These helpers are for grape >= 0.10
|
6
7
|
extend ::Grape::API::Helpers
|
7
8
|
include Doorkeeper::Rails::Helpers
|
8
9
|
|
9
10
|
# endpoint specific scopes > parameter scopes > default scopes
|
10
11
|
def doorkeeper_authorize!(*scopes)
|
11
|
-
endpoint_scopes = env[
|
12
|
+
endpoint_scopes = env["api.endpoint"].route_setting(:scopes)
|
12
13
|
scopes = if endpoint_scopes
|
13
14
|
Doorkeeper::OAuth::Scopes.from_array(endpoint_scopes)
|
14
15
|
elsif scopes && !scopes.empty?
|
@@ -1,15 +1,15 @@
|
|
1
|
+
# Define methods that can be called in any controller that inherits from
|
2
|
+
# Doorkeeper::ApplicationMetalController or Doorkeeper::ApplicationController
|
1
3
|
module Doorkeeper
|
2
4
|
module Helpers
|
3
5
|
module Controller
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
6
|
private
|
7
7
|
|
8
|
-
def authenticate_resource_owner!
|
8
|
+
def authenticate_resource_owner! # :doc:
|
9
9
|
current_resource_owner
|
10
10
|
end
|
11
11
|
|
12
|
-
def current_resource_owner
|
12
|
+
def current_resource_owner # :doc:
|
13
13
|
instance_eval(&Doorkeeper.configuration.authenticate_resource_owner)
|
14
14
|
end
|
15
15
|
|
@@ -17,7 +17,7 @@ module Doorkeeper
|
|
17
17
|
instance_eval(&Doorkeeper.configuration.resource_owner_from_credentials)
|
18
18
|
end
|
19
19
|
|
20
|
-
def authenticate_admin!
|
20
|
+
def authenticate_admin! # :doc:
|
21
21
|
instance_eval(&Doorkeeper.configuration.authenticate_admin)
|
22
22
|
end
|
23
23
|
|
@@ -25,7 +25,7 @@ module Doorkeeper
|
|
25
25
|
@server ||= Server.new(self)
|
26
26
|
end
|
27
27
|
|
28
|
-
def doorkeeper_token
|
28
|
+
def doorkeeper_token # :doc:
|
29
29
|
@token ||= OAuth::Token.authenticate request, *config_methods
|
30
30
|
end
|
31
31
|
|
@@ -34,27 +34,12 @@ module Doorkeeper
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def get_error_response_from_exception(exception)
|
37
|
-
|
38
|
-
when Errors::InvalidTokenStrategy
|
39
|
-
:unsupported_grant_type
|
40
|
-
when Errors::InvalidAuthorizationStrategy
|
41
|
-
:unsupported_response_type
|
42
|
-
when Errors::MissingRequestStrategy
|
43
|
-
:invalid_request
|
44
|
-
when Errors::InvalidTokenReuse
|
45
|
-
:invalid_request
|
46
|
-
when Errors::InvalidGrantReuse
|
47
|
-
:invalid_grant
|
48
|
-
when Errors::DoorkeeperError
|
49
|
-
exception.message
|
50
|
-
end
|
51
|
-
|
52
|
-
OAuth::ErrorResponse.new name: error_name, state: params[:state]
|
37
|
+
OAuth::ErrorResponse.new name: exception.type, state: params[:state]
|
53
38
|
end
|
54
39
|
|
55
40
|
def handle_token_exception(exception)
|
56
41
|
error = get_error_response_from_exception exception
|
57
|
-
|
42
|
+
headers.merge! error.headers
|
58
43
|
self.response_body = error.body.to_json
|
59
44
|
self.status = error.status
|
60
45
|
end
|
@@ -10,12 +10,16 @@ module Doorkeeper
|
|
10
10
|
include ActiveModel::MassAssignmentSecurity if defined?(::ProtectedAttributes)
|
11
11
|
|
12
12
|
included do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
belongs_to_options = {
|
14
|
+
class_name: 'Doorkeeper::Application',
|
15
|
+
inverse_of: :access_grants
|
16
|
+
}
|
17
|
+
if defined?(ActiveRecord::Base) && ActiveRecord::VERSION::MAJOR >= 5
|
18
|
+
belongs_to_options[:optional] = true
|
17
19
|
end
|
18
20
|
|
21
|
+
belongs_to :application, belongs_to_options
|
22
|
+
|
19
23
|
validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, presence: true
|
20
24
|
validates :token, uniqueness: true
|
21
25
|
|
@@ -23,13 +27,25 @@ module Doorkeeper
|
|
23
27
|
end
|
24
28
|
|
25
29
|
module ClassMethods
|
30
|
+
# Searches for Doorkeeper::AccessGrant record with the
|
31
|
+
# specific token value.
|
32
|
+
#
|
33
|
+
# @param token [#to_s] token value (any object that responds to `#to_s`)
|
34
|
+
#
|
35
|
+
# @return [Doorkeeper::AccessGrant, nil] AccessGrant object or nil
|
36
|
+
# if there is no record with such token
|
37
|
+
#
|
26
38
|
def by_token(token)
|
27
|
-
|
39
|
+
find_by(token: token.to_s)
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
31
43
|
private
|
32
44
|
|
45
|
+
# Generates token value with UniqueToken class.
|
46
|
+
#
|
47
|
+
# @return [String] token value
|
48
|
+
#
|
33
49
|
def generate_token
|
34
50
|
self.token = UniqueToken.generate
|
35
51
|
end
|