refactor: extract agent_connect logout_url to a agent_connect_service
This commit is contained in:
parent
1706feec3d
commit
6f5135a6b2
3 changed files with 27 additions and 8 deletions
|
@ -59,7 +59,8 @@ class Users::SessionsController < Devise::SessionsController
|
|||
end
|
||||
|
||||
if agent_connect_id_token.present?
|
||||
return redirect_to build_agent_connect_logout_url(agent_connect_id_token), allow_other_host: true
|
||||
return redirect_to AgentConnectService.logout_url(agent_connect_id_token, host_with_port: request.host_with_port),
|
||||
allow_other_host: true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -110,11 +111,4 @@ class Users::SessionsController < Devise::SessionsController
|
|||
def logout
|
||||
redirect_to root_path, notice: I18n.t('devise.sessions.signed_out')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_agent_connect_logout_url(id_token)
|
||||
h = { id_token_hint: id_token, post_logout_redirect_uri: logout_url }
|
||||
"#{AGENT_CONNECT[:end_session_endpoint]}?#{h.to_query}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,6 +39,12 @@ class AgentConnectService
|
|||
[access_token.userinfo!.raw_attributes, access_token.id_token, amr]
|
||||
end
|
||||
|
||||
def self.logout_url(id_token, host_with_port:)
|
||||
app_logout = Rails.application.routes.url_helpers.logout_url(host: host_with_port)
|
||||
h = { id_token_hint: id_token, post_logout_redirect_uri: app_logout }
|
||||
"#{AGENT_CONNECT[:end_session_endpoint]}?#{h.to_query}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO: remove this block when migration to new domain is done
|
||||
|
|
19
spec/services/agent_connect_service_spec.rb
Normal file
19
spec/services/agent_connect_service_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe AgentConnectService do
|
||||
describe '.logout_url' do
|
||||
let(:id_token) { 'id_token' }
|
||||
|
||||
before do
|
||||
::AGENT_CONNECT ||= {}
|
||||
allow(AGENT_CONNECT).to receive(:[])
|
||||
.with(:end_session_endpoint).and_return("https://agent-connect.fr/logout")
|
||||
end
|
||||
|
||||
subject { described_class.logout_url(id_token, host_with_port: 'test.host') }
|
||||
|
||||
it 'returns the correct url' do
|
||||
expect(subject).to eq("https://agent-connect.fr/logout?id_token_hint=id_token&post_logout_redirect_uri=http%3A%2F%2Ftest.host%2Flogout")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue