From 2440fc7866cb2408feed552c2f18c0d8a0cb0a47 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Thu, 26 Mar 2020 20:18:37 +0100 Subject: [PATCH] use sendJSONresponse instead of handcrafting portal response --- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index c131250e2..7384193d7 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -260,11 +260,15 @@ sub do { if ( !$self->conf->{noAjaxHook} and $req->wantJSON ) { $self->logger->debug('Processing to JSON response'); if ( ( $err > 0 and !$req->id ) or $err eq PE_SESSIONNOTGRANTED ) { - return [ - 401, - [ 'WWW-Authenticate' => "SSO " . $self->conf->{portal} ], - [qq'{"result":0,"error":$err}'] - ]; + return $self->sendJSONresponse( + $req, + { result => 0, error => $err }, + code => 401, + headers => [ + 'WWW-Authenticate' => "SSO " . $self->conf->{portal}, + "Content-Type" => "application/javascript" + ], + ); } elsif ( $err > 0 and $err != PE_PASSWORD_OK and $err != PE_LOGOUT_OK ) { return $self->sendJSONresponse(