Commit 0d513ce5 authored by Maxime Besson's avatar Maxime Besson
Browse files

Fix CORS on userinfo error response (#2567)

parent 9281e4c7
......@@ -1358,8 +1358,7 @@ sub sendOIDCError {
sub returnBearerError {
my ( $self, $error_code, $error_message ) = @_;
# TODO: verify this
return [
my $res = [
401,
[
'WWW-Authenticate' =>
......@@ -1367,6 +1366,10 @@ sub returnBearerError {
],
[]
];
$self->p->setCorsHeaderFromConfig($res);
return $res;
}
sub checkEndPointAuthenticationCredentials {
......
......@@ -877,12 +877,7 @@ sub sendHtml {
'Pragma' => 'no-cache', # HTTP 1.0
'Expires' => '0'; # Proxies
if ( $self->conf->{corsEnabled} ) {
my @cors = split /;/, $self->cors;
push @{ $res->[1] }, @cors;
$self->logger->debug('Apply following CORS policy :');
$self->logger->debug(" $_") for @cors;
}
$self->setCorsHeaderFromConfig($res);
# Set authorized URL for POST
my $csp = $self->csp . "form-action " . $self->conf->{cspFormAction};
......@@ -1088,7 +1083,7 @@ sub registerLogin {
}
my $history = $req->sessionInfo->{_loginHistory} ||= {};
my $type = ( $req->authResult > 0 ? 'failed' : 'success' ) . 'Login';
my $type = ( $req->authResult > 0 ? 'failed' : 'success' ) . 'Login';
$history->{$type} ||= [];
$self->logger->debug("Current login saved into $type");
......@@ -1131,13 +1126,11 @@ sub _sumUpSession {
sub corsPreflight {
my ( $self, $req ) = @_;
my @headers;
if ( $self->conf->{corsEnabled} ) {
my @cors = split /;/, $self->cors;
push @headers, @cors;
$self->logger->debug('Apply following CORS policy :');
$self->logger->debug(" $_") for @cors;
}
return [ 204, \@headers, [] ];
my $res = [ 204, \@headers, [] ];
$self->setCorsHeaderFromConfig($res);
return $res;
}
sub sendJSONresponse {
......@@ -1166,11 +1159,8 @@ sub sendJSONresponse {
"Access-Control-Allow-Credentials" => "true";
}
elsif ( $self->conf->{corsEnabled} ) {
my @cors = split /;/, $self->cors;
push @{ $res->[1] }, @cors;
$self->logger->debug('Apply following CORS policy :');
$self->logger->debug(" $_") for @cors;
else {
$self->setCorsHeaderFromConfig($res);
}
return $res;
}
......@@ -1178,13 +1168,21 @@ sub sendJSONresponse {
sub sendRawHtml {
my ($self) = $_[0];
my $res = Lemonldap::NG::Common::PSGI::sendRawHtml(@_);
$self->setCorsHeaderFromConfig($res);
return $res;
}
sub setCorsHeaderFromConfig {
my ( $self, $response ) = @_;
if ( $self->conf->{corsEnabled} ) {
my @cors = split /;/, $self->cors;
push @{ $res->[1] }, @cors;
push @{ $response->[1] }, @cors;
$self->logger->debug('Apply following CORS policy :');
$self->logger->debug(" $_") for @cors;
}
return $res;
}
# Temlate loader
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment