doorkeeper 4.0.0.rc3 → 4.0.0.rc4
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/.travis.yml +2 -2
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +4 -0
- data/NEWS.md +11 -1
- data/README.md +14 -20
- data/Rakefile +1 -1
- data/app/controllers/doorkeeper/application_metal_controller.rb +1 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +1 -1
- data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
- data/doorkeeper.gemspec +1 -1
- data/lib/doorkeeper.rb +1 -1
- data/lib/doorkeeper/config.rb +6 -23
- data/lib/doorkeeper/helpers/controller.rb +1 -1
- data/lib/doorkeeper/models/access_grant_mixin.rb +2 -2
- data/lib/doorkeeper/models/access_token_mixin.rb +19 -15
- data/lib/doorkeeper/models/application_mixin.rb +3 -3
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +4 -3
- data/lib/doorkeeper/oauth/code_response.rb +13 -14
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +6 -10
- data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -1
- data/lib/doorkeeper/oauth/scopes.rb +2 -2
- data/lib/doorkeeper/oauth/token.rb +3 -4
- data/lib/doorkeeper/oauth/token_response.rb +1 -1
- data/lib/doorkeeper/orm/active_record.rb +0 -16
- data/lib/doorkeeper/orm/active_record/access_token.rb +8 -0
- data/lib/doorkeeper/orm/active_record/application.rb +2 -7
- data/lib/doorkeeper/rails/helpers.rb +1 -1
- data/lib/doorkeeper/rails/routes.rb +2 -1
- data/lib/doorkeeper/rails/routes/mapper.rb +1 -1
- data/lib/doorkeeper/request/password.rb +11 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
- data/lib/generators/doorkeeper/templates/migration.rb +2 -2
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/home_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/config/environments/test.rb +0 -3
- data/spec/lib/config_spec.rb +1 -1
- data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
- data/spec/lib/oauth/refresh_token_request_spec.rb +14 -8
- data/spec/models/doorkeeper/access_token_spec.rb +18 -1
- data/spec/models/doorkeeper/application_spec.rb +1 -9
- data/spec/requests/flows/password_spec.rb +26 -5
- data/spec/requests/flows/refresh_token_spec.rb +2 -2
- data/spec/spec_helper_integration.rb +3 -0
- data/spec/support/helpers/model_helper.rb +27 -5
- data/spec/support/http_method_shim.rb +24 -0
- data/spec/support/shared/models_shared_examples.rb +1 -1
- metadata +4 -4
- data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
- data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
@@ -12,7 +12,7 @@ module Doorkeeper
|
|
12
12
|
attr_reader :response
|
13
13
|
attr_writer :issuer
|
14
14
|
|
15
|
-
|
15
|
+
alias_method :error_response, :response
|
16
16
|
|
17
17
|
delegate :error, to: :issuer
|
18
18
|
|
@@ -21,8 +21,9 @@ module Doorkeeper
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def initialize(server, client, parameters = {})
|
24
|
-
@client
|
25
|
-
@
|
24
|
+
@client = client
|
25
|
+
@server = server
|
26
|
+
@response = nil
|
26
27
|
@original_scopes = parameters[:scope]
|
27
28
|
end
|
28
29
|
|
@@ -7,7 +7,8 @@ module Doorkeeper
|
|
7
7
|
attr_accessor :pre_auth, :auth, :response_on_fragment
|
8
8
|
|
9
9
|
def initialize(pre_auth, auth, options = {})
|
10
|
-
@pre_auth
|
10
|
+
@pre_auth = pre_auth
|
11
|
+
@auth = auth
|
11
12
|
@response_on_fragment = options[:response_on_fragment]
|
12
13
|
end
|
13
14
|
|
@@ -18,20 +19,18 @@ module Doorkeeper
|
|
18
19
|
def redirect_uri
|
19
20
|
if URIChecker.native_uri? pre_auth.redirect_uri
|
20
21
|
auth.native_redirect
|
22
|
+
elsif response_on_fragment
|
23
|
+
uri_with_fragment(
|
24
|
+
pre_auth.redirect_uri,
|
25
|
+
access_token: auth.token.token,
|
26
|
+
token_type: auth.token.token_type,
|
27
|
+
expires_in: auth.token.expires_in_seconds,
|
28
|
+
state: pre_auth.state
|
29
|
+
)
|
21
30
|
else
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
access_token: auth.token.token,
|
26
|
-
token_type: auth.token.token_type,
|
27
|
-
expires_in: auth.token.expires_in_seconds,
|
28
|
-
state: pre_auth.state
|
29
|
-
)
|
30
|
-
else
|
31
|
-
uri_with_query pre_auth.redirect_uri,
|
32
|
-
code: auth.token.token,
|
33
|
-
state: pre_auth.state
|
34
|
-
end
|
31
|
+
uri_with_query pre_auth.redirect_uri,
|
32
|
+
code: auth.token.token,
|
33
|
+
state: pre_auth.state
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
@@ -9,19 +9,15 @@ module Doorkeeper
|
|
9
9
|
validate :resource_owner, error: :invalid_resource_owner
|
10
10
|
validate :scopes, error: :invalid_scope
|
11
11
|
|
12
|
-
attr_accessor :server, :
|
13
|
-
|
12
|
+
attr_accessor :server, :client, :resource_owner, :parameters,
|
13
|
+
:access_token
|
14
14
|
|
15
|
-
def initialize(server,
|
15
|
+
def initialize(server, client, resource_owner, parameters = {})
|
16
16
|
@server = server
|
17
17
|
@resource_owner = resource_owner
|
18
|
-
@
|
18
|
+
@client = client
|
19
|
+
@parameters = parameters
|
19
20
|
@original_scopes = parameters[:scope]
|
20
|
-
|
21
|
-
if credentials
|
22
|
-
@client = Application.by_uid_and_secret credentials.uid,
|
23
|
-
credentials.secret
|
24
|
-
end
|
25
21
|
end
|
26
22
|
|
27
23
|
private
|
@@ -40,7 +36,7 @@ module Doorkeeper
|
|
40
36
|
end
|
41
37
|
|
42
38
|
def validate_client
|
43
|
-
!
|
39
|
+
!parameters[:client_id] || !!client
|
44
40
|
end
|
45
41
|
end
|
46
42
|
end
|
@@ -46,14 +46,14 @@ module Doorkeeper
|
|
46
46
|
|
47
47
|
def +(other)
|
48
48
|
if other.is_a? Scopes
|
49
|
-
self.class.from_array(
|
49
|
+
self.class.from_array(all + other.all)
|
50
50
|
else
|
51
51
|
super(other)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
def <=>(other)
|
56
|
-
|
56
|
+
map(&:to_s).sort <=> other.map(&:to_s).sort
|
57
57
|
end
|
58
58
|
|
59
59
|
def &(other)
|
@@ -26,12 +26,11 @@ module Doorkeeper
|
|
26
26
|
|
27
27
|
def token_from_basic_header(header, pattern)
|
28
28
|
encoded_header = token_from_header(header, pattern)
|
29
|
-
|
30
|
-
token
|
29
|
+
decode_basic_credentials_token(encoded_header)
|
31
30
|
end
|
32
31
|
|
33
|
-
def
|
34
|
-
Base64.decode64(encoded_header).split(/:/, 2)
|
32
|
+
def decode_basic_credentials_token(encoded_header)
|
33
|
+
Base64.decode64(encoded_header).split(/:/, 2).first
|
35
34
|
end
|
36
35
|
|
37
36
|
def token_from_header(header, pattern)
|
@@ -14,7 +14,7 @@ module Doorkeeper
|
|
14
14
|
'expires_in' => token.expires_in_seconds,
|
15
15
|
'refresh_token' => token.refresh_token,
|
16
16
|
'scope' => token.scopes_string,
|
17
|
-
'created_at' => token.created_at.to_i
|
17
|
+
'created_at' => token.created_at.to_i
|
18
18
|
}.reject { |_, value| value.blank? }
|
19
19
|
end
|
20
20
|
|
@@ -18,22 +18,6 @@ module Doorkeeper
|
|
18
18
|
|
19
19
|
Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
|
20
20
|
end
|
21
|
-
|
22
|
-
def self.check_requirements!(_config)
|
23
|
-
if ::ActiveRecord::Base.connected? &&
|
24
|
-
::ActiveRecord::Base.connection.table_exists?(
|
25
|
-
Doorkeeper::Application.table_name
|
26
|
-
)
|
27
|
-
unless Doorkeeper::Application.new.attributes.include?("scopes")
|
28
|
-
migration_path = '../../../generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb'
|
29
|
-
puts <<-MSG.squish
|
30
|
-
[doorkeeper] Missing column: `oauth_applications.scopes`.
|
31
|
-
Create the following migration and run `rake db:migrate`.
|
32
|
-
MSG
|
33
|
-
puts File.read(File.expand_path(migration_path, __FILE__))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
21
|
end
|
38
22
|
end
|
39
23
|
end
|
@@ -10,10 +10,18 @@ module Doorkeeper
|
|
10
10
|
end
|
11
11
|
private_class_method :delete_all_for
|
12
12
|
|
13
|
+
def self.active_for(resource_owner)
|
14
|
+
where(resource_owner_id: resource_owner.id, revoked_at: nil)
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.order_method
|
14
18
|
:order
|
15
19
|
end
|
16
20
|
|
21
|
+
def self.refresh_token_revoked_on_use?
|
22
|
+
column_names.include?('previous_refresh_token')
|
23
|
+
end
|
24
|
+
|
17
25
|
def self.created_at_desc
|
18
26
|
'created_at desc'
|
19
27
|
end
|
@@ -11,14 +11,9 @@ module Doorkeeper
|
|
11
11
|
end
|
12
12
|
has_many :authorized_applications, through: :authorized_tokens, source: :application
|
13
13
|
|
14
|
-
def self.column_names_with_table
|
15
|
-
self.column_names.map { |c| "#{table_name}.#{c}" }
|
16
|
-
end
|
17
|
-
|
18
14
|
def self.authorized_for(resource_owner)
|
19
|
-
|
20
|
-
|
21
|
-
group(column_names_with_table.join(','))
|
15
|
+
resource_access_tokens = AccessToken.active_for(resource_owner)
|
16
|
+
where(id: resource_access_tokens.select(:application_id).distinct)
|
22
17
|
end
|
23
18
|
end
|
24
19
|
end
|
@@ -8,11 +8,21 @@ module Doorkeeper
|
|
8
8
|
def request
|
9
9
|
@request ||= OAuth::PasswordAccessTokenRequest.new(
|
10
10
|
Doorkeeper.configuration,
|
11
|
-
|
11
|
+
client,
|
12
12
|
resource_owner,
|
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
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
data/lib/doorkeeper/version.rb
CHANGED
@@ -26,7 +26,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
26
26
|
add_foreign_key(
|
27
27
|
:oauth_access_grants,
|
28
28
|
:oauth_applications,
|
29
|
-
column: :application_id
|
29
|
+
column: :application_id
|
30
30
|
)
|
31
31
|
|
32
32
|
create_table :oauth_access_tokens do |t|
|
@@ -62,7 +62,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
62
62
|
add_foreign_key(
|
63
63
|
:oauth_access_tokens,
|
64
64
|
:oauth_applications,
|
65
|
-
column: :application_id
|
65
|
+
column: :application_id
|
66
66
|
)
|
67
67
|
end
|
68
68
|
end
|
@@ -2,11 +2,11 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module ControllerActions
|
4
4
|
def index
|
5
|
-
render
|
5
|
+
render plain: 'index'
|
6
6
|
end
|
7
7
|
|
8
8
|
def show
|
9
|
-
render
|
9
|
+
render plain: 'show'
|
10
10
|
end
|
11
11
|
|
12
12
|
def doorkeeper_unauthorized_render_options(*)
|
@@ -22,7 +22,7 @@ describe 'doorkeeper authorize filter' do
|
|
22
22
|
before_action :doorkeeper_authorize!
|
23
23
|
|
24
24
|
def index
|
25
|
-
render
|
25
|
+
render plain: 'index'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -100,7 +100,7 @@ describe 'doorkeeper authorize filter' do
|
|
100
100
|
|
101
101
|
context 'defined with scopes' do
|
102
102
|
controller do
|
103
|
-
|
103
|
+
before_action -> { doorkeeper_authorize! :write }
|
104
104
|
|
105
105
|
include ControllerActions
|
106
106
|
end
|
@@ -137,7 +137,7 @@ describe 'doorkeeper authorize filter' do
|
|
137
137
|
|
138
138
|
context 'when custom unauthorized render options are configured' do
|
139
139
|
controller do
|
140
|
-
|
140
|
+
before_action :doorkeeper_authorize!
|
141
141
|
|
142
142
|
include ControllerActions
|
143
143
|
end
|
@@ -175,7 +175,7 @@ describe 'doorkeeper authorize filter' do
|
|
175
175
|
module ControllerActions
|
176
176
|
remove_method :doorkeeper_unauthorized_render_options
|
177
177
|
def doorkeeper_unauthorized_render_options(error: nil)
|
178
|
-
{
|
178
|
+
{ plain: 'Unauthorized' }
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
@@ -190,7 +190,7 @@ describe 'doorkeeper authorize filter' do
|
|
190
190
|
it 'it renders a custom text response', token: :invalid do
|
191
191
|
get :index, access_token: token_string
|
192
192
|
expect(response.status).to eq 401
|
193
|
-
expect(response.content_type).to eq('text/
|
193
|
+
expect(response.content_type).to eq('text/plain')
|
194
194
|
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
195
195
|
expect(response.body).to eq('Unauthorized')
|
196
196
|
end
|
@@ -212,7 +212,7 @@ describe 'doorkeeper authorize filter' do
|
|
212
212
|
end
|
213
213
|
|
214
214
|
controller do
|
215
|
-
|
215
|
+
before_action -> { doorkeeper_authorize! :write }
|
216
216
|
|
217
217
|
include ControllerActions
|
218
218
|
end
|
@@ -268,7 +268,7 @@ describe 'doorkeeper authorize filter' do
|
|
268
268
|
module ControllerActions
|
269
269
|
remove_method :doorkeeper_forbidden_render_options
|
270
270
|
def doorkeeper_forbidden_render_options(*)
|
271
|
-
{
|
271
|
+
{ plain: 'Forbidden' }
|
272
272
|
end
|
273
273
|
end
|
274
274
|
end
|
@@ -286,7 +286,7 @@ describe 'doorkeeper authorize filter' do
|
|
286
286
|
module ControllerActions
|
287
287
|
remove_method :doorkeeper_forbidden_render_options
|
288
288
|
def doorkeeper_forbidden_render_options(*)
|
289
|
-
{ respond_not_found_when_forbidden: true,
|
289
|
+
{ respond_not_found_when_forbidden: true, plain: 'Not Found' }
|
290
290
|
end
|
291
291
|
end
|
292
292
|
end
|
@@ -3,10 +3,10 @@ class FullProtectedResourcesController < ApplicationController
|
|
3
3
|
before_action :doorkeeper_authorize!, only: :index
|
4
4
|
|
5
5
|
def index
|
6
|
-
render
|
6
|
+
render plain: 'index'
|
7
7
|
end
|
8
8
|
|
9
9
|
def show
|
10
|
-
render
|
10
|
+
render plain: 'show'
|
11
11
|
end
|
12
12
|
end
|
@@ -2,10 +2,10 @@ class SemiProtectedResourcesController < ApplicationController
|
|
2
2
|
before_action :doorkeeper_authorize!, only: :index
|
3
3
|
|
4
4
|
def index
|
5
|
-
render
|
5
|
+
render plain: 'protected index'
|
6
6
|
end
|
7
7
|
|
8
8
|
def show
|
9
|
-
render
|
9
|
+
render plain: 'non protected show'
|
10
10
|
end
|
11
11
|
end
|