begin spec client france connect service
This commit is contained in:
parent
5cb8f92a81
commit
20cae835e6
5 changed files with 22 additions and 18 deletions
|
@ -14,7 +14,7 @@ class FranceConnectController < ApplicationController
|
|||
end
|
||||
|
||||
def callback
|
||||
user_infos = FranceConnectService.retrive_user(params[:code])
|
||||
user_infos = FranceConnectService.retrieve_user_informations(params[:code])
|
||||
|
||||
unless user_infos.nil?
|
||||
@user = User.find_for_france_connect(user_infos.email)
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
class FranceConnectClient < OpenIDConnect::Client
|
||||
|
||||
def initialize params={}
|
||||
redirect_uri = 'http://localhost:3000/france_connect/callback'
|
||||
authorization_endpoint = 'https://fce.integ01.dev-franceconnect.fr/api/v1/authorize'
|
||||
token_endpoint = 'https://fce.integ01.dev-franceconnect.fr/api/v1/token'
|
||||
userinfo_endpoint = 'https://fce.integ01.dev-franceconnect.fr/api/v1/userinfo'
|
||||
|
||||
super(
|
||||
identifier: FRANCE_CONNECT.identifier,
|
||||
secret: FRANCE_CONNECT.secret,
|
||||
redirect_uri: redirect_uri,
|
||||
authorization_endpoint: authorization_endpoint,
|
||||
token_endpoint: token_endpoint,
|
||||
userinfo_endpoint: userinfo_endpoint
|
||||
redirect_uri: FRANCE_CONNECT.redirect_uri,
|
||||
authorization_endpoint: FRANCE_CONNECT.authorization_endpoint,
|
||||
token_endpoint: FRANCE_CONNECT.token_endpoint,
|
||||
userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint
|
||||
)
|
||||
self.authorization_code = params[:code] if params.has_key? :code
|
||||
end
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
class FranceConnectService
|
||||
def self.retrive_user code
|
||||
def self.retrieve_user_informations code
|
||||
client = FranceConnectClient.new code: code
|
||||
|
||||
begin
|
||||
access_token = client.access_token!(client_auth_method: :secret)
|
||||
access_token.userinfo!
|
||||
rescue Exception => e
|
||||
Rails.logger.error(e.message)
|
||||
end
|
||||
access_token = client.access_token!(client_auth_method: :secret)
|
||||
access_token.userinfo!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe FranceConnectClient do
|
|||
let(:code) { 'plop' }
|
||||
subject { described_class.new(code: code) }
|
||||
it 'set authorisation code' do
|
||||
expect_any_instance_of(described_class).to receive(:authorization_code=)
|
||||
expect_any_instance_of(described_class).to receive(:authorization_code=).with(code)
|
||||
described_class.new(code: code)
|
||||
end
|
||||
end
|
||||
|
|
13
spec/services/france_connect_service_spec.rb
Normal file
13
spec/services/france_connect_service_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FranceConnectService do
|
||||
|
||||
describe '.retrieve_user_informations' do
|
||||
let(:code) { 'plop' }
|
||||
|
||||
it 'set code for FranceConnectClient' do
|
||||
expect_any_instance_of(FranceConnectClient).to receive(:initialize).with(code: code)
|
||||
described_class.retrieve_user_informations code
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue