diff --git a/src/Server.php b/src/Server.php index 5d8f514..0c7c316 100644 --- a/src/Server.php +++ b/src/Server.php @@ -100,7 +100,7 @@ final public function respondToAuthorizationRequest( // Return the HTTP redirect response $response = $authorizationServer->completeAuthorizationRequest($authRequest, $response); - $this->addIssuerToResponse($response); // add &iss=... to the response to comply with RFC 9207 + $response = $this->addIssuerToResponse($response); // add &iss=... to the response to comply with RFC 9207 } else { // @CHECKME: 404 or throw Exception? $response = $response->withStatus(404); @@ -117,20 +117,21 @@ final public function respondToAuthorizationRequest( public function addIssuerToResponse($response): Response { - // Adds &iss=... to the response to comply with RFC 9207 - $location = $response->getHeaderLine('Location'); - $uri = new Uri($location); + // Adds &iss=... to the response to comply with RFC 9207 + if ($response->hasHeader("Location")) { + $location = $response->getHeaderLine('Location'); + $uri = new Uri($location); - parse_str($uri->getQuery(), $params); - $params['iss'] = $this->config->getServer()->get(OidcMeta::ISSUER); + parse_str($uri->getQuery(), $params); + $params['iss'] = $this->config->getServer()->get(OidcMeta::ISSUER); - $uri = $uri->withQuery(http_build_query($params)); - - $response = $response->withHeader( - 'Location', - (string) $uri - ); + $uri = $uri->withQuery(http_build_query($params)); + $response = $response->withHeader( + 'Location', + (string) $uri + ); + } return $response; }