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.

Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +4 -0
  3. data/.travis.yml +9 -7
  4. data/CONTRIBUTING.md +2 -0
  5. data/Gemfile +10 -3
  6. data/NEWS.md +79 -2
  7. data/README.md +56 -51
  8. data/RELEASING.md +2 -2
  9. data/Rakefile +1 -1
  10. data/app/assets/stylesheets/doorkeeper/admin/application.css +1 -5
  11. data/app/controllers/doorkeeper/application_metal_controller.rb +1 -2
  12. data/app/controllers/doorkeeper/applications_controller.rb +2 -2
  13. data/app/controllers/doorkeeper/authorizations_controller.rb +1 -1
  14. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  15. data/app/controllers/doorkeeper/tokens_controller.rb +1 -1
  16. data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
  17. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  18. data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
  19. data/app/views/layouts/doorkeeper/admin.html.erb +5 -2
  20. data/config/locales/en.yml +1 -0
  21. data/doorkeeper.gemspec +7 -7
  22. data/lib/doorkeeper/config.rb +10 -15
  23. data/lib/doorkeeper/engine.rb +11 -7
  24. data/lib/doorkeeper/errors.rb +6 -0
  25. data/lib/doorkeeper/helpers/controller.rb +7 -1
  26. data/lib/doorkeeper/models/access_grant_mixin.rb +9 -5
  27. data/lib/doorkeeper/models/access_token_mixin.rb +28 -22
  28. data/lib/doorkeeper/models/application_mixin.rb +3 -7
  29. data/lib/doorkeeper/models/concerns/expirable.rb +2 -2
  30. data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
  31. data/lib/doorkeeper/models/concerns/revocable.rb +19 -2
  32. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
  33. data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -5
  34. data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
  35. data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -4
  36. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -1
  37. data/lib/doorkeeper/oauth/client_credentials_request.rb +7 -4
  38. data/lib/doorkeeper/oauth/code_response.rb +13 -14
  39. data/lib/doorkeeper/oauth/error.rb +5 -1
  40. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  41. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
  42. data/lib/doorkeeper/oauth/password_access_token_request.rb +6 -10
  43. data/lib/doorkeeper/oauth/refresh_token_request.rb +29 -12
  44. data/lib/doorkeeper/oauth/scopes.rb +2 -2
  45. data/lib/doorkeeper/oauth/token.rb +6 -5
  46. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  47. data/lib/doorkeeper/orm/active_record/access_grant.rb +2 -2
  48. data/lib/doorkeeper/orm/active_record/access_token.rb +10 -2
  49. data/lib/doorkeeper/orm/active_record/application.rb +4 -9
  50. data/lib/doorkeeper/orm/active_record.rb +0 -15
  51. data/lib/doorkeeper/rails/helpers.rb +13 -3
  52. data/lib/doorkeeper/rails/routes/mapper.rb +1 -1
  53. data/lib/doorkeeper/rails/routes.rb +2 -1
  54. data/lib/doorkeeper/request/authorization_code.rb +10 -15
  55. data/lib/doorkeeper/request/client_credentials.rb +9 -15
  56. data/lib/doorkeeper/request/code.rb +7 -13
  57. data/lib/doorkeeper/request/password.rb +18 -13
  58. data/lib/doorkeeper/request/refresh_token.rb +11 -13
  59. data/lib/doorkeeper/request/strategy.rb +17 -0
  60. data/lib/doorkeeper/request/token.rb +7 -13
  61. data/lib/doorkeeper/request.rb +18 -8
  62. data/lib/doorkeeper/server.rb +2 -2
  63. data/lib/doorkeeper/version.rb +1 -1
  64. data/lib/doorkeeper.rb +1 -1
  65. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
  66. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
  67. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
  68. data/lib/generators/doorkeeper/templates/initializer.rb +2 -2
  69. data/lib/generators/doorkeeper/templates/migration.rb +23 -5
  70. data/spec/controllers/authorizations_controller_spec.rb +0 -14
  71. data/spec/controllers/protected_resources_controller_spec.rb +138 -15
  72. data/spec/controllers/tokens_controller_spec.rb +30 -0
  73. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -4
  74. data/spec/dummy/app/controllers/home_controller.rb +1 -1
  75. data/spec/dummy/app/controllers/metal_controller.rb +1 -1
  76. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +3 -3
  77. data/spec/dummy/app/models/user.rb +0 -4
  78. data/spec/dummy/config/application.rb +2 -36
  79. data/spec/dummy/config/environment.rb +1 -1
  80. data/spec/dummy/config/environments/test.rb +4 -15
  81. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
  82. data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
  83. data/spec/dummy/db/migrate/{20130902165751_create_doorkeeper_tables.rb → 20151223192035_create_doorkeeper_tables.rb} +24 -5
  84. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
  85. data/spec/dummy/db/schema.rb +23 -22
  86. data/spec/lib/config_spec.rb +2 -2
  87. data/spec/lib/models/revocable_spec.rb +27 -4
  88. data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
  89. data/spec/lib/oauth/client_credentials/creator_spec.rb +25 -1
  90. data/spec/lib/oauth/code_response_spec.rb +34 -0
  91. data/spec/lib/oauth/error_response_spec.rb +7 -7
  92. data/spec/lib/oauth/error_spec.rb +9 -5
  93. data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
  94. data/spec/lib/oauth/refresh_token_request_spec.rb +34 -3
  95. data/spec/lib/oauth/scopes_spec.rb +1 -2
  96. data/spec/lib/oauth/token_spec.rb +12 -5
  97. data/spec/lib/request/strategy_spec.rb +53 -0
  98. data/spec/lib/server_spec.rb +1 -1
  99. data/spec/models/doorkeeper/access_grant_spec.rb +5 -5
  100. data/spec/models/doorkeeper/access_token_spec.rb +49 -5
  101. data/spec/models/doorkeeper/application_spec.rb +2 -10
  102. data/spec/requests/flows/authorization_code_spec.rb +26 -0
  103. data/spec/requests/flows/password_spec.rb +26 -5
  104. data/spec/requests/flows/refresh_token_spec.rb +95 -17
  105. data/spec/spec_helper_integration.rb +10 -0
  106. data/spec/support/helpers/model_helper.rb +27 -5
  107. data/spec/support/http_method_shim.rb +24 -0
  108. data/spec/support/shared/controllers_shared_context.rb +13 -4
  109. data/spec/support/shared/models_shared_examples.rb +1 -1
  110. metadata +46 -38
  111. data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
  112. data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
  113. data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +0 -5
  114. /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
- joins(:authorized_applications).
20
- where(AccessToken.table_name => { resource_owner_id: resource_owner.id, revoked_at: nil }).
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
- if !valid_doorkeeper_token?
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 error.status
37
+ head status
36
38
  else
37
- options[:status] = error.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
@@ -7,7 +7,7 @@ module Doorkeeper
7
7
  end
8
8
 
9
9
  def map(&block)
10
- self.instance_eval(&block) if block
10
+ instance_eval(&block) if block
11
11
  @mapping
12
12
  end
13
13
 
@@ -18,7 +18,8 @@ module Doorkeeper
18
18
  attr_accessor :routes
19
19
 
20
20
  def initialize(routes, &block)
21
- @routes, @block = routes, block
21
+ @routes = routes
22
+ @block = block
22
23
  end
23
24
 
24
25
  def generate_routes!(options)
@@ -1,22 +1,17 @@
1
+ require 'doorkeeper/request/strategy'
2
+
1
3
  module Doorkeeper
2
4
  module Request
3
- class AuthorizationCode
4
- def self.build(server)
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(Doorkeeper.configuration, grant, client, server.parameters)
16
- end
17
-
18
- def authorize
19
- request.authorize
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
- def self.build(server)
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(Doorkeeper.configuration, client, server.parameters)
16
- end
17
-
18
- def authorize
19
- request.authorize
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
- def self.build(server)
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 initialize(pre_auth, server)
11
- @pre_auth, @server = pre_auth, server
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, server.current_resource_owner)
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
- def self.build(server)
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(Doorkeeper.configuration, credentials, resource_owner, server.parameters)
9
+ @request ||= OAuth::PasswordAccessTokenRequest.new(
10
+ Doorkeeper.configuration,
11
+ client,
12
+ resource_owner,
13
+ parameters
14
+ )
16
15
  end
17
16
 
18
- def authorize
19
- request.authorize
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
- def self.build(server)
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 initialize(refresh_token, credentials, server)
11
- @refresh_token, @credentials, @server = refresh_token, credentials, server
8
+ def refresh_token
9
+ server.current_refresh_token
12
10
  end
13
11
 
14
12
  def request
15
- @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, server.parameters)
16
- end
17
-
18
- def authorize
19
- request.authorize
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
- def self.build(server)
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 initialize(pre_auth, server)
11
- @pre_auth, @server = pre_auth, server
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, server.current_resource_owner)
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
@@ -9,22 +9,32 @@ module Doorkeeper
9
9
  module Request
10
10
  module_function
11
11
 
12
- def authorization_strategy(strategy)
13
- get_strategy strategy, Doorkeeper.configuration.authorization_response_types
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(strategy)
19
- get_strategy strategy, Doorkeeper.configuration.token_grant_types
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(strategy, available)
25
- fail Errors::MissingRequestStrategy unless strategy.present?
26
- fail NameError unless available.include?(strategy.to_s)
27
- "Doorkeeper::Request::#{strategy.to_s.camelize}".constantize
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
@@ -8,12 +8,12 @@ module Doorkeeper
8
8
 
9
9
  def authorization_request(strategy)
10
10
  klass = Request.authorization_strategy strategy
11
- klass.build self
11
+ klass.new self
12
12
  end
13
13
 
14
14
  def token_request(strategy)
15
15
  klass = Request.token_strategy strategy
16
- klass.build self
16
+ klass.new self
17
17
  end
18
18
 
19
19
  # TODO: context should be the request
@@ -1,3 +1,3 @@
1
1
  module Doorkeeper
2
- VERSION = '3.0.0'
2
+ VERSION = "4.0.0".freeze
3
3
  end
data/lib/doorkeeper.rb CHANGED
@@ -54,7 +54,7 @@ module Doorkeeper
54
54
  end
55
55
 
56
56
  def self.database_installed?
57
- [AccessToken, AccessGrant, Application].all? { |model| model.table_exists? }
57
+ [AccessToken, AccessGrant, Application].all?(&:table_exists?)
58
58
  end
59
59
 
60
60
  def self.installed?
@@ -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
@@ -4,4 +4,4 @@ class AddOwnerToApplication < ActiveRecord::Migration
4
4
  add_column :oauth_applications, :owner_type, :string, null: true
5
5
  add_index :oauth_applications, [:owner_id, :owner_type]
6
6
  end
7
- end
7
+ end
@@ -0,0 +1,11 @@
1
+ class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration
2
+ def change
3
+ add_column(
4
+ :oauth_access_tokens,
5
+ :previous_refresh_token,
6
+ :string,
7
+ default: "",
8
+ null: false
9
+ )
10
+ end
11
+ 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 :confirmation => true (default false) if you want to enforce ownership of
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 :confirmation => false
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.integer :application_id, null: false
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.integer :application_id
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, null: false
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, null: false
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