doorkeeper 4.0.0.rc2 → 4.0.0.rc3
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 +3 -3
- data/Gemfile +0 -4
- data/NEWS.md +20 -1
- data/README.md +23 -25
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/doorkeeper.gemspec +4 -3
- data/lib/doorkeeper/config.rb +16 -4
- data/lib/doorkeeper/engine.rb +2 -7
- data/lib/doorkeeper/models/access_grant_mixin.rb +0 -4
- data/lib/doorkeeper/models/access_token_mixin.rb +1 -5
- data/lib/doorkeeper/models/application_mixin.rb +0 -4
- data/lib/doorkeeper/models/concerns/expirable.rb +2 -2
- data/lib/doorkeeper/models/concerns/revocable.rb +19 -2
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +3 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- data/lib/doorkeeper/oauth/refresh_token_request.rb +23 -11
- data/lib/doorkeeper/oauth/token.rb +3 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
- 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 +10 -2
- data/spec/controllers/protected_resources_controller_spec.rb +35 -6
- data/spec/dummy/app/models/user.rb +0 -4
- data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
- data/spec/dummy/db/schema.rb +4 -3
- data/spec/lib/config_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +27 -4
- data/spec/lib/oauth/refresh_token_request_spec.rb +30 -5
- data/spec/lib/oauth/scopes_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +12 -5
- data/spec/models/doorkeeper/access_token_spec.rb +22 -1
- data/spec/models/doorkeeper/application_spec.rb +1 -1
- data/spec/requests/flows/refresh_token_spec.rb +87 -17
- data/spec/support/shared/controllers_shared_context.rb +13 -4
- metadata +40 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7970dc66221f5d0ae37df19896a059af6583c3b4
|
4
|
+
data.tar.gz: 9946ccd3e46137c0ed1e51430848ed0ea6e42c9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf56405349f6d0c3e1402a57b962ba25c17dbd78116cb20045088bdf0981f2a2b7539f96d57afff02b00cf62273457b50b388f9fa45aad9cc38e6fd4e5a13b1f
|
7
|
+
data.tar.gz: 6fccbea56797d79ebc29e33e9fc13139308e92a5e09f48f70b12a5f97088c9e9f4ded86e12bc7fa595c7517dad3b4ab76dbed4e0aa6d7306c437db114eb2b74a
|
data/.travis.yml
CHANGED
@@ -6,7 +6,9 @@ rvm:
|
|
6
6
|
- 2.1
|
7
7
|
- 2.2.4
|
8
8
|
- 2.3.0
|
9
|
-
|
9
|
+
|
10
|
+
before_install:
|
11
|
+
- gem install bundler -v '~> 1.10'
|
10
12
|
|
11
13
|
env:
|
12
14
|
- rails=4.2.0
|
@@ -16,5 +18,3 @@ matrix:
|
|
16
18
|
exclude:
|
17
19
|
- env: rails=5.0.0.beta3
|
18
20
|
rvm: 2.1
|
19
|
-
- env: rails=5.0.0.beta3
|
20
|
-
rvm: jruby-head
|
data/Gemfile
CHANGED
@@ -4,10 +4,6 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gem "rails", "~> #{ENV["rails"]}"
|
6
6
|
|
7
|
-
if ENV["rails"] == "5.0.0.beta1"
|
8
|
-
gem "capybara", github: "jnicklas/capybara"
|
9
|
-
end
|
10
|
-
|
11
7
|
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
|
12
8
|
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
13
9
|
|
data/NEWS.md
CHANGED
@@ -4,9 +4,28 @@ User-visible changes worth mentioning.
|
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
+
## 4.0.0.rc3
|
8
|
+
|
9
|
+
- [#769] Revoke refresh token on access token use. To make use of the new config
|
10
|
+
add `previous_refresh_token` column to `oauth_access_tokens`:
|
11
|
+
|
12
|
+
```
|
13
|
+
rails generate doorkeeper:previous_refresh_token
|
14
|
+
```
|
15
|
+
- [#811] Toughen parameters filter with exact match
|
16
|
+
- [#813] Applications admin bugfix
|
17
|
+
- [#799] Fix Ruby Warnings
|
18
|
+
- Drop `attr_accessible` from models
|
19
|
+
|
20
|
+
### Backward incompatible changes
|
21
|
+
|
22
|
+
- [#730] Force all timezones to use UTC to prevent comparison issues.
|
23
|
+
- [#802] Remove `config.i18n.fallbacks` from engine
|
24
|
+
|
7
25
|
## 4.0.0.rc2
|
8
26
|
|
9
27
|
- Fix optional belongs_to for Rails 5
|
28
|
+
- Fix Ruby warnings
|
10
29
|
|
11
30
|
## 4.0.0.rc1
|
12
31
|
|
@@ -87,7 +106,7 @@ User-visible changes worth mentioning.
|
|
87
106
|
- Remove `applications.scopes` upgrade notice.
|
88
107
|
|
89
108
|
|
90
|
-
## 2.2.2
|
109
|
+
## 2.2.2
|
91
110
|
|
92
111
|
- [#541] Fixed `undefined method attr_accessible` problem on Rails 4
|
93
112
|
(happens only when ProtectedAttributes gem is used) in #599
|
data/README.md
CHANGED
@@ -16,43 +16,41 @@ functionality to your Rails or Grape application.
|
|
16
16
|
Please check the documentation for the version of doorkeeper you are using in:
|
17
17
|
https://github.com/doorkeeper-gem/doorkeeper/releases
|
18
18
|
|
19
|
+
- See the [wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
|
20
|
+
- For general questions, please post in [Stack Overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
|
21
|
+
|
19
22
|
## Table of Contents
|
20
23
|
|
21
24
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
22
25
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
23
|
-
|
26
|
+
|
24
27
|
- [Installation](#installation)
|
25
28
|
- [Configuration](#configuration)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
- [Active Record](#active-record)
|
30
|
+
- [Other ORMs](#other-orms)
|
31
|
+
- [Routes](#routes)
|
32
|
+
- [Authenticating](#authenticating)
|
33
|
+
- [Internationalization (I18n)](#internationalization-i18n)
|
31
34
|
- [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
- [Protect your API with OAuth when using Grape](#protect-your-api-with-oauth-when-using-grape)
|
36
|
+
- [Route Constraints and other integrations](#route-constraints-and-other-integrations)
|
37
|
+
- [Access Token Scopes](#access-token-scopes)
|
38
|
+
- [Custom Access Token Generator](#custom-access-token-generator)
|
39
|
+
- [Authenticated resource owner](#authenticated-resource-owner)
|
40
|
+
- [Applications list](#applications-list)
|
38
41
|
- [Other customizations](#other-customizations)
|
39
42
|
- [Upgrading](#upgrading)
|
40
43
|
- [Development](#development)
|
41
44
|
- [Contributing](#contributing)
|
42
45
|
- [Other resources](#other-resources)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
46
|
+
- [Wiki](#wiki)
|
47
|
+
- [Screencast](#screencast)
|
48
|
+
- [Client applications](#client-applications)
|
49
|
+
- [Contributors](#contributors)
|
50
|
+
- [IETF Standards](#ietf-standards)
|
51
|
+
- [License](#license)
|
50
52
|
|
51
|
-
|
52
|
-
## Useful links
|
53
|
-
|
54
|
-
- For documentation, please check out our [wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
|
55
|
-
- For general questions, please post it in [stack overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
|
53
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
56
54
|
|
57
55
|
## Installation
|
58
56
|
|
@@ -78,7 +76,7 @@ to generate the migration tables:
|
|
78
76
|
rails generate doorkeeper:migration
|
79
77
|
|
80
78
|
You may want to add foreign keys to your migration. For example, if you plan on
|
81
|
-
using
|
79
|
+
using `User` as the resource owner, change the line in the migration
|
82
80
|
file:
|
83
81
|
|
84
82
|
```ruby
|
@@ -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 %>
|
data/doorkeeper.gemspec
CHANGED
@@ -18,10 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_dependency "railties", ">= 4.2"
|
20
20
|
|
21
|
-
s.add_development_dependency "rspec-rails"
|
22
21
|
s.add_development_dependency "capybara"
|
23
|
-
s.add_development_dependency "
|
22
|
+
s.add_development_dependency "database_cleaner", "~> 1.3.0"
|
24
23
|
s.add_development_dependency "factory_girl", "~> 4.5.0"
|
24
|
+
s.add_development_dependency "generator_spec", "~> 0.9.0"
|
25
|
+
s.add_development_dependency "rake", "> 10.5.0"
|
26
|
+
s.add_development_dependency "rspec-rails"
|
25
27
|
s.add_development_dependency "timecop", "~> 0.7.0"
|
26
|
-
s.add_development_dependency "database_cleaner", "~> 1.3.0"
|
27
28
|
end
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -133,6 +133,7 @@ doorkeeper.
|
|
133
133
|
attribute_builder = options[:builder_class]
|
134
134
|
|
135
135
|
Builder.instance_eval do
|
136
|
+
remove_method name if method_defined?(name)
|
136
137
|
define_method name do |*args, &block|
|
137
138
|
# TODO: is builder_class option being used?
|
138
139
|
value = unless attribute_builder
|
@@ -193,14 +194,17 @@ doorkeeper.
|
|
193
194
|
attr_reader :reuse_access_token
|
194
195
|
|
195
196
|
def refresh_token_enabled?
|
197
|
+
@refresh_token_enabled ||= false
|
196
198
|
!!@refresh_token_enabled
|
197
199
|
end
|
198
200
|
|
199
201
|
def enable_application_owner?
|
202
|
+
@enable_application_owner ||= false
|
200
203
|
!!@enable_application_owner
|
201
204
|
end
|
202
205
|
|
203
206
|
def confirm_application_owner?
|
207
|
+
@confirm_application_owner ||= false
|
204
208
|
!!@confirm_application_owner
|
205
209
|
end
|
206
210
|
|
@@ -224,10 +228,6 @@ doorkeeper.
|
|
224
228
|
@access_token_methods ||= [:from_bearer_authorization, :from_access_token_param, :from_bearer_param]
|
225
229
|
end
|
226
230
|
|
227
|
-
def realm
|
228
|
-
@realm ||= 'Doorkeeper'
|
229
|
-
end
|
230
|
-
|
231
231
|
def authorization_response_types
|
232
232
|
@authorization_response_types ||= calculate_authorization_response_types
|
233
233
|
end
|
@@ -236,6 +236,18 @@ doorkeeper.
|
|
236
236
|
@token_grant_types ||= calculate_token_grant_types
|
237
237
|
end
|
238
238
|
|
239
|
+
def refresh_token_revoked_on_use?
|
240
|
+
unless @refresh_token_revoked_on_use.nil?
|
241
|
+
return @refresh_token_revoked_on_use
|
242
|
+
end
|
243
|
+
|
244
|
+
@refresh_token_revoked_on_use =
|
245
|
+
ActiveRecord::Base.connection.column_exists?(
|
246
|
+
:oauth_access_tokens,
|
247
|
+
:previous_refresh_token
|
248
|
+
)
|
249
|
+
end
|
250
|
+
|
239
251
|
private
|
240
252
|
|
241
253
|
# Determines what values are acceptable for 'response_type' param in
|
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
|
@@ -20,10 +20,6 @@ module Doorkeeper
|
|
20
20
|
|
21
21
|
belongs_to :application, belongs_to_options
|
22
22
|
|
23
|
-
if respond_to?(:attr_accessible)
|
24
|
-
attr_accessible :resource_owner_id, :application_id, :expires_in, :redirect_uri, :scopes
|
25
|
-
end
|
26
|
-
|
27
23
|
validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, presence: true
|
28
24
|
validates :token, uniqueness: true
|
29
25
|
|
@@ -25,11 +25,6 @@ module Doorkeeper
|
|
25
25
|
|
26
26
|
attr_writer :use_refresh_token
|
27
27
|
|
28
|
-
if respond_to?(:attr_accessible)
|
29
|
-
attr_accessible :application_id, :resource_owner_id, :expires_in,
|
30
|
-
:scopes, :use_refresh_token
|
31
|
-
end
|
32
|
-
|
33
28
|
before_validation :generate_token, on: :create
|
34
29
|
before_validation :generate_refresh_token,
|
35
30
|
on: :create,
|
@@ -105,6 +100,7 @@ module Doorkeeper
|
|
105
100
|
end
|
106
101
|
|
107
102
|
def use_refresh_token?
|
103
|
+
@use_refresh_token ||= false
|
108
104
|
!!@use_refresh_token
|
109
105
|
end
|
110
106
|
|
@@ -15,10 +15,6 @@ module Doorkeeper
|
|
15
15
|
validates :redirect_uri, redirect_uri: true
|
16
16
|
|
17
17
|
before_validation :generate_uid, :generate_secret, on: :create
|
18
|
-
|
19
|
-
if respond_to?(:attr_accessible)
|
20
|
-
attr_accessible :name, :redirect_uri, :scopes
|
21
|
-
end
|
22
18
|
end
|
23
19
|
|
24
20
|
module ClassMethods
|
@@ -2,12 +2,12 @@ module Doorkeeper
|
|
2
2
|
module Models
|
3
3
|
module Expirable
|
4
4
|
def expired?
|
5
|
-
expires_in && Time.now > expired_time
|
5
|
+
expires_in && Time.now.utc > expired_time
|
6
6
|
end
|
7
7
|
|
8
8
|
def expires_in_seconds
|
9
9
|
return nil if expires_in.nil?
|
10
|
-
expires = (created_at + expires_in.seconds) - Time.now
|
10
|
+
expires = (created_at + expires_in.seconds) - Time.now.utc
|
11
11
|
expires_sec = expires.seconds.round(0)
|
12
12
|
expires_sec > 0 ? expires_sec : 0
|
13
13
|
end
|
@@ -2,11 +2,28 @@ module Doorkeeper
|
|
2
2
|
module Models
|
3
3
|
module Revocable
|
4
4
|
def revoke(clock = Time)
|
5
|
-
update_attribute :revoked_at, clock.now
|
5
|
+
update_attribute :revoked_at, clock.now.utc
|
6
6
|
end
|
7
7
|
|
8
8
|
def revoked?
|
9
|
-
!!(revoked_at && revoked_at <= Time.now)
|
9
|
+
!!(revoked_at && revoked_at <= Time.now.utc)
|
10
|
+
end
|
11
|
+
|
12
|
+
def revoke_previous_refresh_token!
|
13
|
+
return unless refresh_token_revoked_on_use?
|
14
|
+
old_refresh_token.revoke if old_refresh_token
|
15
|
+
update_attribute :previous_refresh_token, ""
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def old_refresh_token
|
21
|
+
@old_refresh_token ||=
|
22
|
+
AccessToken.by_refresh_token(previous_refresh_token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def refresh_token_revoked_on_use?
|
26
|
+
Doorkeeper.configuration.refresh_token_revoked_on_use?
|
10
27
|
end
|
11
28
|
end
|
12
29
|
end
|
@@ -7,7 +7,7 @@ module Doorkeeper
|
|
7
7
|
def self.from_request(request, *credentials_methods)
|
8
8
|
credentials_methods.inject(nil) do |credentials, method|
|
9
9
|
method = self.method(method) if method.is_a?(Symbol)
|
10
|
-
credentials = Credentials.new
|
10
|
+
credentials = Credentials.new(*method.call(request))
|
11
11
|
break credentials unless credentials.blank?
|
12
12
|
end
|
13
13
|
end
|
@@ -8,8 +8,10 @@ module Doorkeeper
|
|
8
8
|
include Validations
|
9
9
|
include OAuth::RequestConcern
|
10
10
|
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :server, :client, :original_scopes
|
12
12
|
attr_reader :response
|
13
|
+
attr_writer :issuer
|
14
|
+
|
13
15
|
alias :error_response :response
|
14
16
|
|
15
17
|
delegate :error, to: :issuer
|
@@ -12,7 +12,9 @@ module Doorkeeper
|
|
12
12
|
validate :scope, error: :invalid_scope
|
13
13
|
|
14
14
|
attr_accessor :access_token, :client, :credentials, :refresh_token,
|
15
|
-
:server
|
15
|
+
:server, :refresh_token_parameter
|
16
|
+
|
17
|
+
private :refresh_token_parameter, :refresh_token_parameter=
|
16
18
|
|
17
19
|
def initialize(server, refresh_token, credentials, parameters = {})
|
18
20
|
@server = server
|
@@ -29,34 +31,44 @@ module Doorkeeper
|
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
|
-
attr_reader :refresh_token_parameter
|
33
|
-
|
34
34
|
def before_successful_response
|
35
35
|
refresh_token.transaction do
|
36
36
|
refresh_token.lock!
|
37
37
|
raise Errors::InvalidTokenReuse if refresh_token.revoked?
|
38
38
|
|
39
|
-
refresh_token.revoke
|
39
|
+
refresh_token.revoke unless refresh_token_revoked_on_use?
|
40
40
|
create_access_token
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def refresh_token_revoked_on_use?
|
45
|
+
server.refresh_token_revoked_on_use?
|
46
|
+
end
|
47
|
+
|
44
48
|
def default_scopes
|
45
49
|
refresh_token.scopes
|
46
50
|
end
|
47
51
|
|
48
52
|
def create_access_token
|
49
|
-
|
50
|
-
|
51
|
-
client
|
52
|
-
)
|
53
|
+
@access_token = AccessToken.create!(access_token_attributes)
|
54
|
+
end
|
53
55
|
|
54
|
-
|
56
|
+
def access_token_attributes
|
57
|
+
{
|
55
58
|
application_id: refresh_token.application_id,
|
56
59
|
resource_owner_id: refresh_token.resource_owner_id,
|
57
60
|
scopes: scopes.to_s,
|
58
|
-
expires_in:
|
59
|
-
use_refresh_token: true
|
61
|
+
expires_in: access_token_expires_in,
|
62
|
+
use_refresh_token: true
|
63
|
+
}.tap do |attributes|
|
64
|
+
if refresh_token_revoked_on_use?
|
65
|
+
attributes[:previous_refresh_token] = refresh_token.refresh_token
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def access_token_expires_in
|
71
|
+
Authorization::Token.access_token_expires_in(server, client)
|
60
72
|
end
|
61
73
|
|
62
74
|
def validate_token_presence
|