Redirect either with query string parameters or fragment parameters

This commit is contained in:
Alex Bilbie 2016-02-22 07:58:44 +00:00
parent a1bdaae9a9
commit ad270f7d9d

View File

@ -191,10 +191,12 @@ class OAuthServerException extends \Exception
* Generate a HTTP response.
*
* @param \Psr\Http\Message\ResponseInterface $response
* @param bool $useFragment True if errors should be in the URI fragment instead of
* query string
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function generateHttpResponse(ResponseInterface $response = null)
public function generateHttpResponse(ResponseInterface $response = null, $useFragment = false)
{
if (!$response instanceof ResponseInterface) {
$response = new Response();
@ -215,9 +217,15 @@ class OAuthServerException extends \Exception
$redirectUri = new Uri($this->redirectUri);
parse_str($redirectUri->getQuery(), $redirectPayload);
$headers['Location'] = (string) $redirectUri->withQuery(http_build_query(
array_merge($redirectPayload, $payload)
));
if ($useFragment === true) {
$headers['Location'] = (string) $redirectUri->withFragment(http_build_query(
array_merge($redirectPayload, $payload)
));
} else {
$headers['Location'] = (string) $redirectUri->withQuery(http_build_query(
array_merge($redirectPayload, $payload)
));
}
}
foreach ($headers as $header => $content) {