forked from doorkeeper-gem/doorkeeper-openid_connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Support prompt=none parameter
- Loading branch information
Showing
5 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Doorkeeper | ||
module OpenidConnect | ||
module Helpers | ||
module Controller | ||
private | ||
|
||
def authenticate_resource_owner! | ||
owner = super | ||
|
||
if prompt_values.include?('none') && (!owner || owner.is_a?(String)) | ||
# clear the previous response body to avoid a DoubleRenderError | ||
# TODO: this is currently broken on Rails 5, see | ||
# https://github.com/rails/rails/issues/25106 | ||
self.response_body = nil | ||
|
||
error = ::Doorkeeper::OAuth::ErrorResponse.new(name: :login_required) | ||
response.headers.merge!(error.headers) | ||
render json: error.body, status: error.status | ||
else | ||
owner | ||
end | ||
end | ||
|
||
def prompt_values | ||
@prompt_values ||= params[:prompt].to_s.split(/ +/) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'rails_helper' | ||
|
||
describe Doorkeeper::AuthorizationsController, type: :controller do | ||
describe '#new' do | ||
context 'without a prompt parameter' do | ||
it 'renders the authorization form if logged in' do | ||
get :new, current_user: 'Joe' | ||
|
||
expect(response).to be_successful | ||
end | ||
|
||
it 'redirects to login form when not logged in' do | ||
get :new | ||
|
||
expect(response).to redirect_to '/login' | ||
end | ||
end | ||
|
||
context 'with a prompt=none parameter' do | ||
it 'renders the authorization form if logged in' do | ||
get :new, current_user: 'Joe', prompt: 'none' | ||
|
||
expect(response).to be_successful | ||
end | ||
|
||
it 'returns an error when not logged in' do | ||
get :new, prompt: 'none' | ||
|
||
expect(response.status).to eq 401 | ||
expect(JSON.parse(response.body)).to eq({ | ||
'error' => 'login_required', | ||
'error_description' => 'The authorization server requires end-user authentication' | ||
}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
Doorkeeper.configure do | ||
resource_owner_authenticator do | ||
if params[:current_user] | ||
User.new name: params[:current_user] | ||
else | ||
redirect_to('/login') | ||
end | ||
end | ||
end |