Filter for prompt handling
This commit is contained in:
parent
7b2be0d3c6
commit
d351db1982
2 changed files with 25 additions and 1 deletions
|
|
@ -6,7 +6,7 @@ module Api
|
||||||
render json: {error: e.message || :error, status: e.status}
|
render json: {error: e.message || :error, status: e.status}
|
||||||
end
|
end
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :auth_user_unless_prompt_none!
|
||||||
|
|
||||||
def new
|
def new
|
||||||
auth = Api::OpenidConnect::Authorization.find_by_client_id_and_user(params[:client_id], current_user)
|
auth = Api::OpenidConnect::Authorization.find_by_client_id_and_user(params[:client_id], current_user)
|
||||||
|
|
@ -201,6 +201,17 @@ module Api
|
||||||
redirect_fragment = redirect_params_hash.compact.map {|key, value| key.to_s + "=" + value }.join("&")
|
redirect_fragment = redirect_params_hash.compact.map {|key, value| key.to_s + "=" + value }.join("&")
|
||||||
redirect_to params[:redirect_uri] + "?" + redirect_fragment
|
redirect_to params[:redirect_uri] + "?" + redirect_fragment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def auth_user_unless_prompt_none!
|
||||||
|
if params[:prompt] == "none" && !user_signed_in?
|
||||||
|
render json: {error: "login_required",
|
||||||
|
description: "User must be first logged in when `prompt` is `none`"}
|
||||||
|
else
|
||||||
|
authenticate_user!
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,19 @@ describe Api::OpenidConnect::AuthorizationsController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when prompt is none and user not signed in" do
|
||||||
|
before do
|
||||||
|
sign_out :user
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return an interaction required error" do
|
||||||
|
post :new, client_id: client.client_id, redirect_uri: "http://localhost:3000/",
|
||||||
|
response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none"
|
||||||
|
json_body = JSON.parse(response.body)
|
||||||
|
expect(json_body["error"]).to match("login_required")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when prompt is none and consent" do
|
context "when prompt is none and consent" do
|
||||||
it "should return an interaction required error" do
|
it "should return an interaction required error" do
|
||||||
post :new, client_id: client.client_id, redirect_uri: "http://localhost:3000/",
|
post :new, client_id: client.client_id, redirect_uri: "http://localhost:3000/",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue