doorkeeper 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.hound.yml +4 -0
- data/.travis.yml +9 -7
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +10 -3
- data/NEWS.md +79 -2
- data/README.md +56 -51
- data/RELEASING.md +2 -2
- data/Rakefile +1 -1
- data/app/assets/stylesheets/doorkeeper/admin/application.css +1 -5
- data/app/controllers/doorkeeper/application_metal_controller.rb +1 -2
- data/app/controllers/doorkeeper/applications_controller.rb +2 -2
- 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 +1 -1
- data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +5 -2
- data/config/locales/en.yml +1 -0
- data/doorkeeper.gemspec +7 -7
- data/lib/doorkeeper/config.rb +10 -15
- data/lib/doorkeeper/engine.rb +11 -7
- data/lib/doorkeeper/errors.rb +6 -0
- data/lib/doorkeeper/helpers/controller.rb +7 -1
- data/lib/doorkeeper/models/access_grant_mixin.rb +9 -5
- data/lib/doorkeeper/models/access_token_mixin.rb +28 -22
- data/lib/doorkeeper/models/application_mixin.rb +3 -7
- data/lib/doorkeeper/models/concerns/expirable.rb +2 -2
- data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +19 -2
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -5
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -4
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +7 -4
- data/lib/doorkeeper/oauth/code_response.rb +13 -14
- data/lib/doorkeeper/oauth/error.rb +5 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- 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 +29 -12
- data/lib/doorkeeper/oauth/scopes.rb +2 -2
- data/lib/doorkeeper/oauth/token.rb +6 -5
- data/lib/doorkeeper/oauth/token_response.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_grant.rb +2 -2
- data/lib/doorkeeper/orm/active_record/access_token.rb +10 -2
- data/lib/doorkeeper/orm/active_record/application.rb +4 -9
- data/lib/doorkeeper/orm/active_record.rb +0 -15
- data/lib/doorkeeper/rails/helpers.rb +13 -3
- data/lib/doorkeeper/rails/routes/mapper.rb +1 -1
- data/lib/doorkeeper/rails/routes.rb +2 -1
- data/lib/doorkeeper/request/authorization_code.rb +10 -15
- data/lib/doorkeeper/request/client_credentials.rb +9 -15
- data/lib/doorkeeper/request/code.rb +7 -13
- data/lib/doorkeeper/request/password.rb +18 -13
- data/lib/doorkeeper/request/refresh_token.rb +11 -13
- data/lib/doorkeeper/request/strategy.rb +17 -0
- data/lib/doorkeeper/request/token.rb +7 -13
- data/lib/doorkeeper/request.rb +18 -8
- data/lib/doorkeeper/server.rb +2 -2
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +1 -1
- 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 +2 -2
- data/lib/generators/doorkeeper/templates/migration.rb +23 -5
- data/spec/controllers/authorizations_controller_spec.rb +0 -14
- data/spec/controllers/protected_resources_controller_spec.rb +138 -15
- data/spec/controllers/tokens_controller_spec.rb +30 -0
- 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/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
- data/spec/dummy/db/schema.rb +23 -22
- data/spec/lib/config_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +27 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials/creator_spec.rb +25 -1
- data/spec/lib/oauth/code_response_spec.rb +34 -0
- data/spec/lib/oauth/error_response_spec.rb +7 -7
- data/spec/lib/oauth/error_spec.rb +9 -5
- 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 +1 -2
- data/spec/lib/oauth/token_spec.rb +12 -5
- data/spec/lib/request/strategy_spec.rb +53 -0
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +5 -5
- data/spec/models/doorkeeper/access_token_spec.rb +49 -5
- data/spec/models/doorkeeper/application_spec.rb +2 -10
- data/spec/requests/flows/authorization_code_spec.rb +26 -0
- data/spec/requests/flows/password_spec.rb +26 -5
- data/spec/requests/flows/refresh_token_spec.rb +95 -17
- data/spec/spec_helper_integration.rb +10 -0
- data/spec/support/helpers/model_helper.rb +27 -5
- data/spec/support/http_method_shim.rb +24 -0
- data/spec/support/shared/controllers_shared_context.rb +13 -4
- data/spec/support/shared/models_shared_examples.rb +1 -1
- metadata +46 -38
- 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/dummy/db/migrate/{20130902175349_add_owner_to_application.rb → 20151223200000_add_owner_to_application.rb} +0 -0
@@ -1,19 +1,27 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class AccessToken < ActiveRecord::Base
|
3
|
-
include AccessTokenMixin
|
4
|
-
|
5
3
|
self.table_name = "#{table_name_prefix}oauth_access_tokens#{table_name_suffix}".to_sym
|
6
4
|
|
5
|
+
include AccessTokenMixin
|
6
|
+
|
7
7
|
def self.delete_all_for(application_id, resource_owner)
|
8
8
|
where(application_id: application_id,
|
9
9
|
resource_owner_id: resource_owner.id).delete_all
|
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
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class Application < ActiveRecord::Base
|
3
|
-
include ApplicationMixin
|
4
|
-
|
5
3
|
self.table_name = "#{table_name_prefix}oauth_applications#{table_name_suffix}".to_sym
|
6
4
|
|
5
|
+
include ApplicationMixin
|
6
|
+
|
7
7
|
if ActiveRecord::VERSION::MAJOR >= 4
|
8
8
|
has_many :authorized_tokens, -> { where(revoked_at: nil) }, class_name: 'AccessToken'
|
9
9
|
else
|
@@ -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
|
@@ -18,21 +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
|
-
fail <<-MSG.squish
|
29
|
-
[doorkeeper] Missing column: `oauth_applications.scopes`.
|
30
|
-
Run `rails generate doorkeeper:application_scopes
|
31
|
-
&& rake db:migrate` to add it.
|
32
|
-
MSG
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
21
|
end
|
37
22
|
end
|
38
23
|
end
|
@@ -6,7 +6,7 @@ module Doorkeeper
|
|
6
6
|
def doorkeeper_authorize!(*scopes)
|
7
7
|
@_doorkeeper_scopes = scopes.presence || Doorkeeper.configuration.default_scopes
|
8
8
|
|
9
|
-
|
9
|
+
unless valid_doorkeeper_token?
|
10
10
|
doorkeeper_render_error
|
11
11
|
end
|
12
12
|
end
|
@@ -31,10 +31,12 @@ module Doorkeeper
|
|
31
31
|
|
32
32
|
def doorkeeper_render_error_with(error)
|
33
33
|
options = doorkeeper_render_options(error) || {}
|
34
|
+
status = doorkeeper_status_for_error(
|
35
|
+
error, options.delete(:respond_not_found_when_forbidden))
|
34
36
|
if options.blank?
|
35
|
-
head
|
37
|
+
head status
|
36
38
|
else
|
37
|
-
options[:status] =
|
39
|
+
options[:status] = status
|
38
40
|
options[:layout] = false if options[:layout].nil?
|
39
41
|
render options
|
40
42
|
end
|
@@ -56,6 +58,14 @@ module Doorkeeper
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
61
|
+
def doorkeeper_status_for_error(error, respond_not_found_when_forbidden)
|
62
|
+
if respond_not_found_when_forbidden && error.status == :forbidden
|
63
|
+
:not_found
|
64
|
+
else
|
65
|
+
error.status
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
59
69
|
def doorkeeper_invalid_token_response?
|
60
70
|
!doorkeeper_token || !doorkeeper_token.accessible?
|
61
71
|
end
|
@@ -1,22 +1,17 @@
|
|
1
|
+
require 'doorkeeper/request/strategy'
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Request
|
3
|
-
class AuthorizationCode
|
4
|
-
|
5
|
-
new(server.grant, server.client, server)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :grant, :client, :server
|
9
|
-
|
10
|
-
def initialize(grant, client, server)
|
11
|
-
@grant, @client, @server = grant, client, server
|
12
|
-
end
|
5
|
+
class AuthorizationCode < Strategy
|
6
|
+
delegate :grant, :client, :parameters, to: :server
|
13
7
|
|
14
8
|
def request
|
15
|
-
@request ||= OAuth::AuthorizationCodeRequest.new(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
@request ||= OAuth::AuthorizationCodeRequest.new(
|
10
|
+
Doorkeeper.configuration,
|
11
|
+
grant,
|
12
|
+
client,
|
13
|
+
parameters
|
14
|
+
)
|
20
15
|
end
|
21
16
|
end
|
22
17
|
end
|
@@ -1,22 +1,16 @@
|
|
1
|
+
require 'doorkeeper/request/strategy'
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Request
|
3
|
-
class ClientCredentials
|
4
|
-
|
5
|
-
new(server.client, server)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :client, :server
|
9
|
-
|
10
|
-
def initialize(client, server)
|
11
|
-
@client, @server = client, server
|
12
|
-
end
|
5
|
+
class ClientCredentials < Strategy
|
6
|
+
delegate :client, :parameters, to: :server
|
13
7
|
|
14
8
|
def request
|
15
|
-
@request ||= OAuth::ClientCredentialsRequest.new(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
@request ||= OAuth::ClientCredentialsRequest.new(
|
10
|
+
Doorkeeper.configuration,
|
11
|
+
client,
|
12
|
+
parameters
|
13
|
+
)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
@@ -1,22 +1,16 @@
|
|
1
|
+
require 'doorkeeper/request/strategy'
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Request
|
3
|
-
class Code
|
4
|
-
|
5
|
-
new(server.context.send(:pre_auth), server)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :pre_auth, :server
|
5
|
+
class Code < Strategy
|
6
|
+
delegate :current_resource_owner, to: :server
|
9
7
|
|
10
|
-
def
|
11
|
-
|
8
|
+
def pre_auth
|
9
|
+
server.context.send(:pre_auth)
|
12
10
|
end
|
13
11
|
|
14
12
|
def request
|
15
|
-
@request ||= OAuth::CodeRequest.new(pre_auth,
|
16
|
-
end
|
17
|
-
|
18
|
-
def authorize
|
19
|
-
request.authorize
|
13
|
+
@request ||= OAuth::CodeRequest.new(pre_auth, current_resource_owner)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
@@ -1,22 +1,27 @@
|
|
1
|
+
require 'doorkeeper/request/strategy'
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Request
|
3
|
-
class Password
|
4
|
-
|
5
|
-
new(server.credentials, server.resource_owner, server)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :credentials, :resource_owner, :server
|
9
|
-
|
10
|
-
def initialize(credentials, resource_owner, server)
|
11
|
-
@credentials, @resource_owner, @server = credentials, resource_owner, server
|
12
|
-
end
|
5
|
+
class Password < Strategy
|
6
|
+
delegate :credentials, :resource_owner, :parameters, to: :server
|
13
7
|
|
14
8
|
def request
|
15
|
-
@request ||= OAuth::PasswordAccessTokenRequest.new(
|
9
|
+
@request ||= OAuth::PasswordAccessTokenRequest.new(
|
10
|
+
Doorkeeper.configuration,
|
11
|
+
client,
|
12
|
+
resource_owner,
|
13
|
+
parameters
|
14
|
+
)
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
private
|
18
|
+
|
19
|
+
def client
|
20
|
+
if credentials
|
21
|
+
server.client
|
22
|
+
elsif parameters[:client_id]
|
23
|
+
server.client_via_uid
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -1,22 +1,20 @@
|
|
1
|
+
require 'doorkeeper/request/strategy'
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Request
|
3
|
-
class RefreshToken
|
4
|
-
|
5
|
-
new(server.current_refresh_token, server.credentials, server)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :refresh_token, :credentials, :server
|
5
|
+
class RefreshToken < Strategy
|
6
|
+
delegate :credentials, :parameters, to: :server
|
9
7
|
|
10
|
-
def
|
11
|
-
|
8
|
+
def refresh_token
|
9
|
+
server.current_refresh_token
|
12
10
|
end
|
13
11
|
|
14
12
|
def request
|
15
|
-
@request ||= OAuth::RefreshTokenRequest.new(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
@request ||= OAuth::RefreshTokenRequest.new(
|
14
|
+
Doorkeeper.configuration,
|
15
|
+
refresh_token, credentials,
|
16
|
+
parameters
|
17
|
+
)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
module Request
|
3
|
+
class Strategy
|
4
|
+
attr_accessor :server
|
5
|
+
|
6
|
+
delegate :authorize, to: :request
|
7
|
+
|
8
|
+
def initialize(server)
|
9
|
+
self.server = server
|
10
|
+
end
|
11
|
+
|
12
|
+
def request
|
13
|
+
raise NotImplementedError, "request strategies must define #request"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,22 +1,16 @@
|
|
1
|
+
require 'doorkeeper/request/strategy'
|
2
|
+
|
1
3
|
module Doorkeeper
|
2
4
|
module Request
|
3
|
-
class Token
|
4
|
-
|
5
|
-
new(server.context.send(:pre_auth), server)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :pre_auth, :server
|
5
|
+
class Token < Strategy
|
6
|
+
delegate :current_resource_owner, to: :server
|
9
7
|
|
10
|
-
def
|
11
|
-
|
8
|
+
def pre_auth
|
9
|
+
server.context.send(:pre_auth)
|
12
10
|
end
|
13
11
|
|
14
12
|
def request
|
15
|
-
@request ||= OAuth::TokenRequest.new(pre_auth,
|
16
|
-
end
|
17
|
-
|
18
|
-
def authorize
|
19
|
-
request.authorize
|
13
|
+
@request ||= OAuth::TokenRequest.new(pre_auth, current_resource_owner)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
@@ -9,22 +9,32 @@ module Doorkeeper
|
|
9
9
|
module Request
|
10
10
|
module_function
|
11
11
|
|
12
|
-
def authorization_strategy(
|
13
|
-
get_strategy
|
12
|
+
def authorization_strategy(response_type)
|
13
|
+
get_strategy response_type, authorization_response_types
|
14
14
|
rescue NameError
|
15
15
|
raise Errors::InvalidAuthorizationStrategy
|
16
16
|
end
|
17
17
|
|
18
|
-
def token_strategy(
|
19
|
-
get_strategy
|
18
|
+
def token_strategy(grant_type)
|
19
|
+
get_strategy grant_type, token_grant_types
|
20
20
|
rescue NameError
|
21
21
|
raise Errors::InvalidTokenStrategy
|
22
22
|
end
|
23
23
|
|
24
|
-
def get_strategy(
|
25
|
-
fail Errors::MissingRequestStrategy unless
|
26
|
-
fail NameError unless available.include?(
|
27
|
-
"Doorkeeper::Request::#{
|
24
|
+
def get_strategy(grant_or_request_type, available)
|
25
|
+
fail Errors::MissingRequestStrategy unless grant_or_request_type.present?
|
26
|
+
fail NameError unless available.include?(grant_or_request_type.to_s)
|
27
|
+
"Doorkeeper::Request::#{grant_or_request_type.to_s.camelize}".constantize
|
28
28
|
end
|
29
|
+
|
30
|
+
def authorization_response_types
|
31
|
+
Doorkeeper.configuration.authorization_response_types
|
32
|
+
end
|
33
|
+
private_class_method :authorization_response_types
|
34
|
+
|
35
|
+
def token_grant_types
|
36
|
+
Doorkeeper.configuration.token_grant_types
|
37
|
+
end
|
38
|
+
private_class_method :token_grant_types
|
29
39
|
end
|
30
40
|
end
|
data/lib/doorkeeper/server.rb
CHANGED
@@ -8,12 +8,12 @@ module Doorkeeper
|
|
8
8
|
|
9
9
|
def authorization_request(strategy)
|
10
10
|
klass = Request.authorization_strategy strategy
|
11
|
-
klass.
|
11
|
+
klass.new self
|
12
12
|
end
|
13
13
|
|
14
14
|
def token_request(strategy)
|
15
15
|
klass = Request.token_strategy strategy
|
16
|
-
klass.
|
16
|
+
klass.new self
|
17
17
|
end
|
18
18
|
|
19
19
|
# TODO: context should be the request
|
data/lib/doorkeeper/version.rb
CHANGED
data/lib/doorkeeper.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class Doorkeeper::PreviousRefreshTokenGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
desc 'Support revoke refresh token on access token use'
|
7
|
+
|
8
|
+
def self.next_migration_number(path)
|
9
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def previous_refresh_token
|
13
|
+
if no_previous_refresh_token_column?
|
14
|
+
migration_template(
|
15
|
+
'add_previous_refresh_token_to_access_tokens.rb',
|
16
|
+
'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def no_previous_refresh_token_column?
|
24
|
+
!ActiveRecord::Base.connection.column_exists?(
|
25
|
+
:oauth_access_tokens,
|
26
|
+
:previous_refresh_token
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
@@ -41,10 +41,10 @@ Doorkeeper.configure do
|
|
41
41
|
# use_refresh_token
|
42
42
|
|
43
43
|
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
44
|
-
# Optional parameter :
|
44
|
+
# Optional parameter confirmation: true (default false) if you want to enforce ownership of
|
45
45
|
# a registered application
|
46
46
|
# Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
|
47
|
-
# enable_application_owner :
|
47
|
+
# enable_application_owner confirmation: false
|
48
48
|
|
49
49
|
# Define access token scopes for your provider
|
50
50
|
# For more information go to
|
@@ -6,14 +6,14 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
6
6
|
t.string :secret, null: false
|
7
7
|
t.text :redirect_uri, null: false
|
8
8
|
t.string :scopes, null: false, default: ''
|
9
|
-
t.timestamps
|
9
|
+
t.timestamps null: false
|
10
10
|
end
|
11
11
|
|
12
12
|
add_index :oauth_applications, :uid, unique: true
|
13
13
|
|
14
14
|
create_table :oauth_access_grants do |t|
|
15
15
|
t.integer :resource_owner_id, null: false
|
16
|
-
t.
|
16
|
+
t.references :application, null: false
|
17
17
|
t.string :token, null: false
|
18
18
|
t.integer :expires_in, null: false
|
19
19
|
t.text :redirect_uri, null: false
|
@@ -23,10 +23,15 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
23
23
|
end
|
24
24
|
|
25
25
|
add_index :oauth_access_grants, :token, unique: true
|
26
|
+
add_foreign_key(
|
27
|
+
:oauth_access_grants,
|
28
|
+
:oauth_applications,
|
29
|
+
column: :application_id
|
30
|
+
)
|
26
31
|
|
27
32
|
create_table :oauth_access_tokens do |t|
|
28
33
|
t.integer :resource_owner_id
|
29
|
-
t.
|
34
|
+
t.references :application
|
30
35
|
|
31
36
|
# If you use a custom token generator you may need to change this column
|
32
37
|
# from string to text, so that it accepts tokens larger than 255
|
@@ -34,17 +39,30 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
34
39
|
# https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
|
35
40
|
#
|
36
41
|
# t.text :token, null: false
|
37
|
-
t.string :token,
|
42
|
+
t.string :token, null: false
|
38
43
|
|
39
44
|
t.string :refresh_token
|
40
45
|
t.integer :expires_in
|
41
46
|
t.datetime :revoked_at
|
42
|
-
t.datetime :created_at,
|
47
|
+
t.datetime :created_at, null: false
|
43
48
|
t.string :scopes
|
49
|
+
|
50
|
+
# If there is a previous_refresh_token column,
|
51
|
+
# refresh tokens will be revoked after a related access token is used.
|
52
|
+
# If there is no previous_refresh_token column,
|
53
|
+
# previous tokens are revoked as soon as a new access token is created.
|
54
|
+
# Comment out this line if you'd rather have refresh tokens
|
55
|
+
# instantly revoked.
|
56
|
+
t.string :previous_refresh_token, null: false, default: ""
|
44
57
|
end
|
45
58
|
|
46
59
|
add_index :oauth_access_tokens, :token, unique: true
|
47
60
|
add_index :oauth_access_tokens, :resource_owner_id
|
48
61
|
add_index :oauth_access_tokens, :refresh_token, unique: true
|
62
|
+
add_foreign_key(
|
63
|
+
:oauth_access_tokens,
|
64
|
+
:oauth_applications,
|
65
|
+
column: :application_id
|
66
|
+
)
|
49
67
|
end
|
50
68
|
end
|
@@ -89,16 +89,6 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
|
|
89
89
|
it 'returns the existing access token in a fragment'
|
90
90
|
end
|
91
91
|
|
92
|
-
describe 'GET #new' do
|
93
|
-
before do
|
94
|
-
get :new, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'renders new template' do
|
98
|
-
expect(response).to render_template(:new)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
92
|
describe 'GET #new token request with native url and skip_authorization true' do
|
103
93
|
before do
|
104
94
|
allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
|
@@ -191,10 +181,6 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
|
|
191
181
|
expect(response).to_not be_redirect
|
192
182
|
end
|
193
183
|
|
194
|
-
it 'renders error template' do
|
195
|
-
expect(response).to render_template(:error)
|
196
|
-
end
|
197
|
-
|
198
184
|
it 'does not issue any token' do
|
199
185
|
expect(Doorkeeper::AccessGrant.count).to eq 0
|
200
186
|
expect(Doorkeeper::AccessToken.count).to eq 0
|