Rename FranceConnect to FranceConnect::Entreprise

This commit is contained in:
Xavier J 2015-12-18 12:01:26 +01:00
parent 563e739958
commit 229973f14c
11 changed files with 44 additions and 44 deletions

View file

@ -1,6 +1,6 @@
class FranceConnectController < ApplicationController class FranceConnect::EntrepriseController < ApplicationController
def login def login
client = FranceConnectClient.new client = FranceConnectEntrepriseClient.new
session[:state] = SecureRandom.hex(16) session[:state] = SecureRandom.hex(16)
session[:nonce] = SecureRandom.hex(16) session[:nonce] = SecureRandom.hex(16)
@ -16,7 +16,7 @@ class FranceConnectController < ApplicationController
def callback def callback
return redirect_to new_user_session_path unless params.has_key?(:code) 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? unless user_infos.nil?
@user = User.find_for_france_connect(user_infos.email, user_infos.siret) @user = User.find_for_france_connect(user_infos.email, user_infos.siret)

View file

@ -18,14 +18,12 @@ class Users::SessionsController < Sessions::SessionsController
connected_with_france_connect = current_user.loged_in_with_france_connect connected_with_france_connect = current_user.loged_in_with_france_connect
current_user.update_attributes(loged_in_with_france_connect: false) current_user.update_attributes(loged_in_with_france_connect: false)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) 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? set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
yield if block_given? yield if block_given?
if connected_with_france_connect if connected_with_france_connect
redirect_to FRANCE_CONNECT.logout_endpoint redirect_to FRANCE_CONNECT.entreprise_logout_endpoint
else else
respond_to_on_destroy respond_to_on_destroy
end end

View file

@ -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

View file

@ -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

View file

@ -1,6 +1,6 @@
class FranceConnectService class FranceConnectService
def self.retrieve_user_informations code def self.retrieve_user_informations_entreprise code
client = FranceConnectClient.new code: code client = FranceConnectEntrepriseClient.new code: code
access_token = client.access_token!(client_auth_method: :secret) access_token = client.access_token!(client_auth_method: :secret)
user_info = access_token.userinfo! user_info = access_token.userinfo!

View file

@ -15,8 +15,10 @@ Rails.application.routes.draw do
root 'root#index' root 'root#index'
get 'france_connect' => 'france_connect#login' namespace :france_connect do
get 'france_connect/callback' => 'france_connect#callback' get 'entreprise' => 'entreprise#login'
get 'entreprise/callback' => 'entreprise#callback'
end
get 'demo' => 'demo#index' get 'demo' => 'demo#index'

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe FranceConnectController, type: :controller do describe FranceConnect::EntrepriseController, type: :controller do
describe '.login' do describe '.login' do
it 'redirect to france connect serveur' 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) } let(:current_user) { User.find_by_email(email) }
before do 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 get :callback, code: code
end end
@ -43,7 +43,7 @@ describe FranceConnectController, type: :controller do
context 'when code is not correct' do context 'when code is not correct' do
before 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 get :callback, code: code
end end

View file

@ -40,7 +40,7 @@ describe Users::SessionsController, type: :controller do
context 'when user is connect with france connect' do context 'when user is connect with france connect' do
it 'redirect to france connect logout page' 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
end end

View file

@ -16,8 +16,8 @@ feature 'France Connect Connexion' do
# #
# context 'when authentification is ok' do # context 'when authentification is ok' do
# before do # before do
# allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) # allow_any_instance_of(FranceConnectEntrepriseClient).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(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
# page.find_by_id('btn_fc').click # page.find_by_id('btn_fc').click
# end # end
# #
@ -28,8 +28,8 @@ feature 'France Connect Connexion' do
# #
# context 'when authentification is not ok' do # context 'when authentification is not ok' do
# before do # before do
# allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) # allow_any_instance_of(FranceConnectEntrepriseClient).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(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
# page.find_by_id('btn_fc').click # page.find_by_id('btn_fc').click
# end # end
# #
@ -55,8 +55,8 @@ feature 'France Connect Connexion' do
# let(:siret) { '00000000000000' } # let(:siret) { '00000000000000' }
# let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) } # let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) }
# before do # before do
# allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
# allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_infos) # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_infos)
# page.find_by_id('btn_fc').click # page.find_by_id('btn_fc').click
# end # end
# context 'when starting page is dossiers list' do # context 'when starting page is dossiers list' do

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe FranceConnectClient do describe FranceConnectEntrepriseClient do
describe '.initialize' do describe '.initialize' do
it 'create an openid client' do it 'create an openid client' do
expect(described_class).to be < OpenIDConnect::Client expect(described_class).to be < OpenIDConnect::Client

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe FranceConnectService do describe FranceConnectService do
describe '.retrieve_user_informations' do describe '.retrieve_user_informations_entreprise' do
let(:code) { 'plop' } let(:code) { 'plop' }
let(:access_token) { 'my access_token' } let(:access_token) { 'my access_token' }
@ -10,15 +10,15 @@ describe FranceConnectService do
let(:user_info_hash) { {'email' => email, 'siret' => siret} } let(:user_info_hash) { {'email' => email, 'siret' => siret} }
let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash, email: email) } 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 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) allow(access_token).to receive(:userinfo!).and_return(user_info)
end end
it 'set code for FranceConnectClient' do it 'set code for FranceConnectEntrepriseClient' do
expect_any_instance_of(FranceConnectClient).to receive(:authorization_code=).with(code) expect_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_code=).with(code)
described_class.retrieve_user_informations code described_class.retrieve_user_informations_entreprise code
end end
it 'returns user informations in a object' do it 'returns user informations in a object' do