demarches-normaliennes/app/controllers/france_connect_controller.rb

33 lines
924 B
Ruby
Raw Normal View History

class FranceConnectController < ApplicationController
2015-10-06 16:02:30 +02:00
def login
client = FranceConnectClient.new
session[:state] = SecureRandom.hex(16)
session[:nonce] = SecureRandom.hex(16)
authorization_uri = client.authorization_uri(
scope: [:profile, :email],
state: session[:state],
nonce: session[:nonce]
)
redirect_to authorization_uri
end
def callback
2015-10-06 16:17:15 +02:00
return redirect_to new_user_session_path unless params.has_key?(:code)
user_infos = FranceConnectService.retrieve_user_informations(params[:code])
unless user_infos.nil?
@user = User.find_for_france_connect(user_infos.email)
sign_in @user
redirect_to(controller: 'users/dossiers', action: :index)
end
2015-10-06 16:47:25 +02:00
rescue Rack::OAuth2::Client::Error => e
Rails.logger.error e.message
2015-10-06 17:06:37 +02:00
flash.alert = 'Erreur lors de la connexion à France Connect.'
2015-10-06 16:47:25 +02:00
redirect_to(new_user_session_path)
end
end