From 2236363a73ef3852eaf3e07680246481345fdb16 Mon Sep 17 00:00:00 2001 From: David Verhasselt Date: Thu, 30 Nov 2017 08:54:56 +0200 Subject: [PATCH] Make native redirect code a query param This allows for automated flows to detect that an Authorization code was granted in much the same way as a normal redirect. This is used by e.g. Mac Paw. --- NEWS.md | 1 + lib/doorkeeper/rails/routes.rb | 2 +- spec/controllers/authorizations_controller_spec.rb | 2 +- spec/requests/flows/authorization_code_spec.rb | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index ba9b52f93..7f68e0f54 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ User-visible changes worth mentioning. ## master +- [#1003] Use URL query param to pass through native redirect auth code so automated apps can find it. - [#868] `Scopes#&` and `Scopes#+` now take an array or any other enumerable object. - [#1019] Remove translation not in use: `invalid_resource_owner`. diff --git a/lib/doorkeeper/rails/routes.rb b/lib/doorkeeper/rails/routes.rb index 00873f99c..a90ff8741 100644 --- a/lib/doorkeeper/rails/routes.rb +++ b/lib/doorkeeper/rails/routes.rb @@ -49,7 +49,7 @@ def authorization_routes(mapping) as: mapping[:as], controller: mapping[:controllers] ) do - routes.get '/:code', action: :show, on: :member + routes.get '/native', action: :show, on: :member routes.get '/', action: :new, on: :member end end diff --git a/spec/controllers/authorizations_controller_spec.rb b/spec/controllers/authorizations_controller_spec.rb index 5056050c9..59d11aeb0 100644 --- a/spec/controllers/authorizations_controller_spec.rb +++ b/spec/controllers/authorizations_controller_spec.rb @@ -154,7 +154,7 @@ def translated_error_message(key) it 'should redirect immediately' do expect(response).to be_redirect - expect(response.location).to match(/oauth\/authorize\//) + expect(response.location).to match(/oauth\/authorize\/native\?code=#{Doorkeeper::AccessGrant.first.token}/) end it 'should issue a grant' do diff --git a/spec/requests/flows/authorization_code_spec.rb b/spec/requests/flows/authorization_code_spec.rb index 45dfc8c11..6a63b8948 100644 --- a/spec/requests/flows/authorization_code_spec.rb +++ b/spec/requests/flows/authorization_code_spec.rb @@ -29,6 +29,7 @@ access_grant_should_exist_for(@client, @resource_owner) + url_should_have_param('code', Doorkeeper::AccessGrant.first.token) i_should_see 'Authorization code:' i_should_see Doorkeeper::AccessGrant.first.token end