diff --git a/app/controllers/france_connect_controller.rb b/app/controllers/france_connect/entreprise_controller.rb similarity index 86% rename from app/controllers/france_connect_controller.rb rename to app/controllers/france_connect/entreprise_controller.rb index 48ea640e6..760f5bae4 100644 --- a/app/controllers/france_connect_controller.rb +++ b/app/controllers/france_connect/entreprise_controller.rb @@ -1,6 +1,6 @@ -class FranceConnectController < ApplicationController +class FranceConnect::EntrepriseController < ApplicationController def login - client = FranceConnectClient.new + client = FranceConnectEntrepriseClient.new session[:state] = SecureRandom.hex(16) session[:nonce] = SecureRandom.hex(16) @@ -16,7 +16,7 @@ class FranceConnectController < ApplicationController def callback return redirect_to new_user_session_path unless params.has_key?(:code) - user_infos = FranceConnectService.retrieve_user_informations(params[:code]) + user_infos = FranceConnectService.retrieve_user_informations_entreprise(params[:code]) unless user_infos.nil? @user = User.find_for_france_connect(user_infos.email, user_infos.siret) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index b4f85b7fb..e09a7e61b 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -18,14 +18,12 @@ class Users::SessionsController < Sessions::SessionsController connected_with_france_connect = current_user.loged_in_with_france_connect current_user.update_attributes(loged_in_with_france_connect: false) - signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) set_flash_message :notice, :signed_out if signed_out && is_flashing_format? yield if block_given? - if connected_with_france_connect - redirect_to FRANCE_CONNECT.logout_endpoint + redirect_to FRANCE_CONNECT.entreprise_logout_endpoint else respond_to_on_destroy end diff --git a/app/models/france_connect_client.rb b/app/models/france_connect_client.rb deleted file mode 100644 index 274db2f9c..000000000 --- a/app/models/france_connect_client.rb +++ /dev/null @@ -1,17 +0,0 @@ -class FranceConnectClient < OpenIDConnect::Client - - def initialize params={} - super( - identifier: FRANCE_CONNECT.identifier, - secret: FRANCE_CONNECT.secret, - - redirect_uri: FRANCE_CONNECT.redirect_uri, - - authorization_endpoint: FRANCE_CONNECT.authorization_endpoint, - token_endpoint: FRANCE_CONNECT.token_endpoint, - userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint, - logout_endpoint: FRANCE_CONNECT.logout_endpoint - ) - self.authorization_code = params[:code] if params.has_key? :code - end -end diff --git a/app/models/france_connect_entreprise_client.rb b/app/models/france_connect_entreprise_client.rb new file mode 100644 index 000000000..5d8f218a2 --- /dev/null +++ b/app/models/france_connect_entreprise_client.rb @@ -0,0 +1,17 @@ +class FranceConnectEntrepriseClient < OpenIDConnect::Client + + def initialize params={} + super( + identifier: FRANCE_CONNECT.identifier, + secret: FRANCE_CONNECT.secret, + + redirect_uri: FRANCE_CONNECT.entreprise_redirect_uri, + + authorization_endpoint: FRANCE_CONNECT.entreprise_authorization_endpoint, + token_endpoint: FRANCE_CONNECT.entreprise_token_endpoint, + userinfo_endpoint: FRANCE_CONNECT.entreprise_userinfo_endpoint, + logout_endpoint: FRANCE_CONNECT.entreprise_logout_endpoint + ) + self.authorization_code = params[:code] if params.has_key? :code + end +end diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index 167525bcf..93ae87eb0 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -1,6 +1,6 @@ class FranceConnectService - def self.retrieve_user_informations code - client = FranceConnectClient.new code: code + def self.retrieve_user_informations_entreprise code + client = FranceConnectEntrepriseClient.new code: code access_token = client.access_token!(client_auth_method: :secret) user_info = access_token.userinfo! diff --git a/config/routes.rb b/config/routes.rb index cc6085089..2f0b69329 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,8 +15,10 @@ Rails.application.routes.draw do root 'root#index' - get 'france_connect' => 'france_connect#login' - get 'france_connect/callback' => 'france_connect#callback' + namespace :france_connect do + get 'entreprise' => 'entreprise#login' + get 'entreprise/callback' => 'entreprise#callback' + end get 'demo' => 'demo#index' diff --git a/spec/controllers/france_connect_controller_spec.rb b/spec/controllers/entreprise_controller_spec.rb similarity index 89% rename from spec/controllers/france_connect_controller_spec.rb rename to spec/controllers/entreprise_controller_spec.rb index 84f9a0866..ba664fb1f 100644 --- a/spec/controllers/france_connect_controller_spec.rb +++ b/spec/controllers/entreprise_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe FranceConnectController, type: :controller do +describe FranceConnect::EntrepriseController, type: :controller do describe '.login' do it 'redirect to france connect serveur' do @@ -26,7 +26,7 @@ describe FranceConnectController, type: :controller do let(:current_user) { User.find_by_email(email) } before do - allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_info) + allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_info) get :callback, code: code end @@ -43,7 +43,7 @@ describe FranceConnectController, type: :controller do context 'when code is not correct' do before do - allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } + allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } get :callback, code: code end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index c4bcdaac3..11f138f2f 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -40,7 +40,7 @@ describe Users::SessionsController, type: :controller do context 'when user is connect with france connect' do it 'redirect to france connect logout page' do - expect(response).to redirect_to(FRANCE_CONNECT.logout_endpoint) + expect(response).to redirect_to(FRANCE_CONNECT.entreprise_logout_endpoint) end end diff --git a/spec/features/france_connect/france_connect_spec.rb b/spec/features/france_connect/france_connect_spec.rb index 148732178..8b9cfb1b9 100644 --- a/spec/features/france_connect/france_connect_spec.rb +++ b/spec/features/france_connect/france_connect_spec.rb @@ -16,8 +16,8 @@ feature 'France Connect Connexion' do # # context 'when authentification is ok' do # before do - # allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) - # allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com')) + # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) + # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(Hashie::Mash.new(email: 'patator@cake.com')) # page.find_by_id('btn_fc').click # end # @@ -28,8 +28,8 @@ feature 'France Connect Connexion' do # # context 'when authentification is not ok' do # before do - # allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) - # allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } + # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) + # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } # page.find_by_id('btn_fc').click # end # @@ -55,8 +55,8 @@ feature 'France Connect Connexion' do # let(:siret) { '00000000000000' } # let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) } # before do - # allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) - # allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_infos) + # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) + # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_infos) # page.find_by_id('btn_fc').click # end # context 'when starting page is dossiers list' do diff --git a/spec/models/france_connect_client_spec.rb b/spec/models/france_connect_entreprise_client_spec.rb similarity index 91% rename from spec/models/france_connect_client_spec.rb rename to spec/models/france_connect_entreprise_client_spec.rb index 174151ff5..2f1385747 100644 --- a/spec/models/france_connect_client_spec.rb +++ b/spec/models/france_connect_entreprise_client_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe FranceConnectClient do +describe FranceConnectEntrepriseClient do describe '.initialize' do it 'create an openid client' do expect(described_class).to be < OpenIDConnect::Client diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb index 25753fa96..3e962eb8d 100644 --- a/spec/services/france_connect_service_spec.rb +++ b/spec/services/france_connect_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe FranceConnectService do - describe '.retrieve_user_informations' do + describe '.retrieve_user_informations_entreprise' do let(:code) { 'plop' } let(:access_token) { 'my access_token' } @@ -10,15 +10,15 @@ describe FranceConnectService do let(:user_info_hash) { {'email' => email, 'siret' => siret} } let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash, email: email) } - subject { described_class.retrieve_user_informations code } + subject { described_class.retrieve_user_informations_entreprise code } before do - allow_any_instance_of(FranceConnectClient).to receive(:access_token!).and_return(access_token) + allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:access_token!).and_return(access_token) allow(access_token).to receive(:userinfo!).and_return(user_info) end - it 'set code for FranceConnectClient' do - expect_any_instance_of(FranceConnectClient).to receive(:authorization_code=).with(code) - described_class.retrieve_user_informations code + it 'set code for FranceConnectEntrepriseClient' do + expect_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_code=).with(code) + described_class.retrieve_user_informations_entreprise code end it 'returns user informations in a object' do