add france connect logout process

This commit is contained in:
Xavier J 2015-10-07 16:38:29 +02:00
parent 9c6b9d408b
commit aeeb9406e9
3 changed files with 58 additions and 10 deletions

View file

@ -10,14 +10,26 @@ class Users::SessionsController < Devise::SessionsController
def create
super
current_user.login_with_france_connect = false
current_user.save
current_user.update_attributes(login_with_france_connect: false)
end
# DELETE /resource/sign_out
# def destroy
# super
# end
def destroy
connected_with_france_connect = current_user.login_with_france_connect
current_user.update_attributes(login_with_france_connect: false)
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?
yield if block_given?
if connected_with_france_connect
redirect_to FRANCE_CONNECT.logout_endpoint
else
respond_to_on_destroy
end
end
# protected

View file

@ -4,10 +4,13 @@ class FranceConnectClient < OpenIDConnect::Client
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
userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint,
logout_endpoint: FRANCE_CONNECT.logout_endpoint
)
self.authorization_code = params[:code] if params.has_key? :code
end

View file

@ -1,13 +1,16 @@
require 'spec_helper'
describe Users::SessionsController, type: :controller do
let(:login_with_france_connect) { true }
let(:user) { create(:user, login_with_france_connect: login_with_france_connect) }
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
describe '.create' do
let(:user) { create(:user, login_with_france_connect: true) }
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
post :create, user: { email: user.email, password: user.password }
post :create, user: {email: user.email, password: user.password}
end
it 'login_with_france_connect current_user attribut is false' do
@ -15,4 +18,34 @@ describe Users::SessionsController, type: :controller do
expect(user.login_with_france_connect).to be_falsey
end
end
describe '.destroy' do
before do
sign_in user
delete :destroy
end
it 'user is sign out' do
expect(subject.current_user).to be_nil
end
it 'login_with_france_connect current_user attribut is false' do
user.reload
expect(user.login_with_france_connect).to be_falsey
end
context 'when user is connect with france connect' do
it 'redirect to france connect logout page' do
expect(response).to redirect_to(FRANCE_CONNECT.logout_endpoint)
end
end
context 'when user is not connect with france connect' do
let(:login_with_france_connect) { false }
it 'redirect to root page' do
expect(response).to redirect_to(root_path)
end
end
end
end