FC service: return domain info
This commit is contained in:
parent
7024e14d1c
commit
02395e732c
5 changed files with 30 additions and 31 deletions
|
@ -8,22 +8,15 @@ class FranceConnect::ParticulierController < ApplicationController
|
||||||
return redirect_to new_user_session_path
|
return redirect_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
user_infos = FranceConnectService.retrieve_user_informations_particulier(params[:code])
|
fetched_fc_information = FranceConnectService.retrieve_user_informations_particulier(params[:code])
|
||||||
|
|
||||||
if user_infos.present?
|
if fetched_fc_information.present?
|
||||||
france_connect_information = FranceConnectInformation
|
france_connect_information = FranceConnectInformation
|
||||||
.find_by(france_connect_particulier_id: user_infos[:france_connect_particulier_id])
|
.find_by(france_connect_particulier_id: fetched_fc_information[:france_connect_particulier_id])
|
||||||
|
|
||||||
if france_connect_information.nil?
|
if france_connect_information.nil?
|
||||||
france_connect_information = FranceConnectInformation.create(
|
fetched_fc_information.save
|
||||||
{gender: user_infos[:gender],
|
france_connect_information = fetched_fc_information
|
||||||
given_name: user_infos[:given_name],
|
|
||||||
family_name: user_infos[:family_name],
|
|
||||||
email_france_connect: user_infos[:email],
|
|
||||||
birthdate: user_infos[:birthdate],
|
|
||||||
birthplace: user_infos[:birthplace],
|
|
||||||
france_connect_particulier_id: user_infos[:france_connect_particulier_id]}
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
user = france_connect_information.user
|
user = france_connect_information.user
|
||||||
|
|
|
@ -11,12 +11,17 @@ class FranceConnectService
|
||||||
def self.retrieve_user_informations_particulier(code)
|
def self.retrieve_user_informations_particulier(code)
|
||||||
client = FranceConnectParticulierClient.new(code)
|
client = FranceConnectParticulierClient.new(code)
|
||||||
|
|
||||||
access_token = client.access_token!(client_auth_method: :secret)
|
user_info = client.access_token!(client_auth_method: :secret)
|
||||||
|
.userinfo!
|
||||||
|
.raw_attributes
|
||||||
|
|
||||||
user_info = access_token.userinfo!
|
FranceConnectInformation.new(
|
||||||
hash = Hashie::Mash.new(user_info.raw_attributes)
|
gender: user_info[:gender],
|
||||||
|
given_name: user_info[:given_name],
|
||||||
hash.france_connect_particulier_id = hash.sub
|
family_name: user_info[:family_name],
|
||||||
hash
|
email_france_connect: user_info[:email],
|
||||||
|
birthdate: user_info[:birthdate],
|
||||||
|
birthplace: user_info[:birthplace],
|
||||||
|
france_connect_particulier_id: user_info[:sub])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe FranceConnect::ParticulierController, type: :controller do
|
||||||
let(:email) { 'test@test.com' }
|
let(:email) { 'test@test.com' }
|
||||||
let(:password) { '' }
|
let(:password) { '' }
|
||||||
|
|
||||||
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email, password: password) }
|
let(:user_info) { { france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email_france_connect: email } }
|
||||||
|
|
||||||
describe '.auth' do
|
describe '.auth' do
|
||||||
it 'redirect to france connect serveur' do
|
it 'redirect to france connect serveur' do
|
||||||
|
@ -31,7 +31,8 @@ describe FranceConnect::ParticulierController, type: :controller do
|
||||||
context 'when params code is present' do
|
context 'when params code is present' do
|
||||||
context 'when code is correct' do
|
context 'when code is correct' do
|
||||||
before do
|
before do
|
||||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(user_info)
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier)
|
||||||
|
.and_return(FranceConnectInformation.new(user_info))
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when france_connect_particulier_id exist in database' do
|
context 'when france_connect_particulier_id exist in database' do
|
||||||
|
|
|
@ -47,7 +47,7 @@ feature 'France Connect Particulier Connexion' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))
|
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))
|
||||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(user_info)
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(FranceConnectInformation.new(user_info))
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when is the first connexion' do
|
context 'when is the first connexion' do
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe FranceConnectService do
|
||||||
|
|
||||||
let(:given_name) { 'plop1' }
|
let(:given_name) { 'plop1' }
|
||||||
let(:family_name) { 'plop2' }
|
let(:family_name) { 'plop2' }
|
||||||
let(:birthdate) { 'plop3' }
|
let(:birthdate) { '2012-12-31' }
|
||||||
let(:gender) { 'plop4' }
|
let(:gender) { 'plop4' }
|
||||||
let(:birthplace) { 'plop5' }
|
let(:birthplace) { 'plop5' }
|
||||||
let(:email) { 'plop@emaiL.com' }
|
let(:email) { 'plop@emaiL.com' }
|
||||||
|
@ -29,15 +29,15 @@ describe FranceConnectService do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns user informations in a object' do
|
it 'returns user informations' do
|
||||||
expect(subject.given_name).to eq(given_name)
|
expect(subject).to have_attributes({
|
||||||
expect(subject.family_name).to eq(family_name)
|
given_name: given_name,
|
||||||
expect(subject.birthdate).to eq(birthdate)
|
family_name: family_name,
|
||||||
expect(subject.gender).to eq(gender)
|
birthdate: DateTime.parse(birthdate),
|
||||||
expect(subject.email).to eq(email)
|
birthplace: birthplace,
|
||||||
expect(subject.phone).to eq(phone)
|
gender: gender,
|
||||||
expect(subject.birthplace).to eq(birthplace)
|
email_france_connect: email,
|
||||||
expect(subject.france_connect_particulier_id).to eq(france_connect_particulier_id)
|
france_connect_particulier_id: france_connect_particulier_id })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue