2015-10-06 11:21:20 +02:00
|
|
|
class FranceConnectService
|
2020-08-01 10:33:38 +02:00
|
|
|
def self.enabled?
|
|
|
|
ENV.fetch("FRANCE_CONNECT_ENABLED", "enabled") == "enabled"
|
|
|
|
end
|
|
|
|
|
2018-01-11 15:29:58 +01:00
|
|
|
def self.authorization_uri
|
|
|
|
client = FranceConnectParticulierClient.new
|
|
|
|
|
|
|
|
client.authorization_uri(
|
|
|
|
scope: [:profile, :email],
|
|
|
|
state: SecureRandom.hex(16),
|
2020-03-12 19:46:41 +01:00
|
|
|
nonce: SecureRandom.hex(16),
|
|
|
|
acr_values: 'eidas1'
|
2018-01-15 19:29:44 +01:00
|
|
|
)
|
2018-01-11 15:29:58 +01:00
|
|
|
end
|
|
|
|
|
2021-02-01 14:28:04 +01:00
|
|
|
def self.find_or_retrieve_france_connect_information(code)
|
|
|
|
fetched_fci = FranceConnectService.retrieve_user_informations_particulier(code)
|
|
|
|
FranceConnectInformation.find_by(france_connect_particulier_id: fetched_fci[:france_connect_particulier_id]) || fetched_fci
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-01-11 17:07:35 +01:00
|
|
|
def self.retrieve_user_informations_particulier(code)
|
2018-01-11 11:07:25 +01:00
|
|
|
client = FranceConnectParticulierClient.new(code)
|
2015-12-24 10:12:23 +01:00
|
|
|
|
2018-01-11 18:16:38 +01:00
|
|
|
user_info = client.access_token!(client_auth_method: :secret)
|
|
|
|
.userinfo!
|
|
|
|
.raw_attributes
|
2018-01-11 17:07:35 +01:00
|
|
|
|
2018-01-11 18:16:38 +01:00
|
|
|
FranceConnectInformation.new(
|
|
|
|
gender: user_info[:gender],
|
|
|
|
given_name: user_info[:given_name],
|
|
|
|
family_name: user_info[:family_name],
|
|
|
|
email_france_connect: user_info[:email],
|
|
|
|
birthdate: user_info[:birthdate],
|
|
|
|
birthplace: user_info[:birthplace],
|
2018-01-15 19:29:44 +01:00
|
|
|
france_connect_particulier_id: user_info[:sub]
|
|
|
|
)
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
2015-10-06 11:21:20 +02:00
|
|
|
end
|