Skip to content

Commit f3822ea

Browse files
authored
Merge pull request #1144 from pakwfoley/pakwfoley/make_breaking_api_change_optional
Make breaking api change to native authorization code route optional
2 parents 9772e05 + 2aba4e1 commit f3822ea

File tree

7 files changed

+87
-2
lines changed

7 files changed

+87
-2
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ User-visible changes worth mentioning.
44

55
## master
66

7+
## 4.4.3
8+
- [#1143] Adds a config option opt_out_native_route_change to opt out of the
9+
breaking api changed introduced in
10+
https://github.com/doorkeeper-gem/doorkeeper/pull/1003
11+
712
## 4.4.2
813
- [#1130] Backport fix for native redirect_uri from 5.x.
914

lib/doorkeeper/config.rb

+14
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ def use_refresh_token
114114
def reuse_access_token
115115
@config.instance_variable_set(:@reuse_access_token, true)
116116
end
117+
118+
# Opt out of breaking api change to the native authorization code flow.
119+
# Opting out sets the authorization code response route for native
120+
# redirect uris to oauth/authorize/<code>. The default is
121+
# oauth/authorize/native?code=<code>.
122+
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1143
123+
def opt_out_native_route_change
124+
@config.instance_variable_set(:@opt_out_native_route_change, true)
125+
end
117126
end
118127

119128
module Option
@@ -295,6 +304,11 @@ def token_grant_types
295304
@token_grant_types ||= calculate_token_grant_types
296305
end
297306

307+
def native_authorization_code_route
308+
@opt_out_native_route_change ||= false
309+
@opt_out_native_route_change ? '/:code' : '/native'
310+
end
311+
298312
private
299313

300314
# Determines what values are acceptable for 'response_type' param in

lib/doorkeeper/rails/routes.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def authorization_routes(mapping)
4747
as: mapping[:as],
4848
controller: mapping[:controllers]
4949
) do
50-
routes.get '/native', action: :show, on: :member
50+
routes.get native_authorization_code_route, action: :show, on: :member
5151
routes.get '/', action: :new, on: :member
5252
end
5353
end
@@ -85,6 +85,10 @@ def application_routes(mapping)
8585
def authorized_applications_routes(mapping)
8686
routes.resources :authorized_applications, only: %i[index destroy], controller: mapping[:controllers]
8787
end
88+
89+
def native_authorization_code_route
90+
Doorkeeper.configuration.native_authorization_code_route
91+
end
8892
end
8993
end
9094
end

lib/doorkeeper/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module VERSION
2828
# Semantic versioning
2929
MAJOR = 4
3030
MINOR = 4
31-
TINY = 2
31+
TINY = 3
3232

3333
# Full version number
3434
STRING = [MAJOR, MINOR, TINY].compact.join('.')

spec/controllers/authorizations_controller_spec.rb

+32
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ def translated_error_message(key)
164164
it 'should not issue a token' do
165165
expect(Doorkeeper::AccessToken.count).to be 0
166166
end
167+
168+
context 'with opt_out_native_route_change' do
169+
around(:each) do |example|
170+
Doorkeeper.configure do
171+
orm DOORKEEPER_ORM
172+
opt_out_native_route_change
173+
end
174+
175+
Rails.application.reload_routes!
176+
177+
example.run
178+
179+
Doorkeeper.configure do
180+
orm DOORKEEPER_ORM
181+
end
182+
183+
Rails.application.reload_routes!
184+
end
185+
186+
it 'should redirect immediately' do
187+
expect(response).to be_redirect
188+
expect(response.location).to match(/oauth\/authorize\/#{Doorkeeper::AccessGrant.first.token}/)
189+
end
190+
191+
it 'should issue a grant' do
192+
expect(Doorkeeper::AccessGrant.count).to be 1
193+
end
194+
195+
it 'should not issue a token' do
196+
expect(Doorkeeper::AccessToken.count).to be 0
197+
end
198+
end
167199
end
168200

169201
describe 'GET #new with skip_authorization true' do

spec/dummy/config/initializers/doorkeeper.rb

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
# Issue access tokens with refresh token (disabled by default)
3030
use_refresh_token
3131

32+
# Opt out of breaking api change to the native authorization code flow. Opting out sets the authorization
33+
# code response route for native redirect uris to oauth/authorize/<code>. The default is oauth/authorize/native?code=<code>.
34+
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1143
35+
# opt_out_native_route_change
36+
3237
# Provide support for an owner to be assigned to each registered application (disabled by default)
3338
# Optional parameter confirmation: true (default false) if you want to enforce ownership of
3439
# a registered application

spec/lib/config_spec.rb

+25
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,31 @@
162162
end
163163
end
164164

165+
describe 'opt_out_native_route_change' do
166+
around(:each) do |example|
167+
Doorkeeper.configure do
168+
orm DOORKEEPER_ORM
169+
opt_out_native_route_change
170+
end
171+
172+
Rails.application.reload_routes!
173+
174+
subject { Doorkeeper.configuration }
175+
176+
example.run
177+
178+
Doorkeeper.configure do
179+
orm DOORKEEPER_ORM
180+
end
181+
182+
Rails.application.reload_routes!
183+
end
184+
185+
it 'sets the native authorization code route /:code' do
186+
expect(subject.native_authorization_code_route).to eq('/:code')
187+
end
188+
end
189+
165190
describe 'client_credentials' do
166191
it 'has defaults order' do
167192
expect(subject.client_credentials_methods).to eq([:from_basic, :from_params])

0 commit comments

Comments
 (0)