Skip to content

Commit 05b52cb

Browse files
committed
Fix redirection URLs when implicit grant is denied
It was generating URLs mixing fragment and query string.
1 parent 42bc990 commit 05b52cb

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Controller/AuthorizationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function indexAction(Request $request): Response
111111

112112
$response = $this->server->completeAuthorizationRequest($authRequest, $serverResponse);
113113
} catch (OAuthServerException $e) {
114-
$response = $e->generateHttpResponse($serverResponse);
114+
$response = $e->generateHttpResponse($serverResponse, str_contains($e->getRedirectUri() ?? '', '#'));
115115
}
116116

117117
return $this->httpFoundationFactory->createResponse($response);

tests/Acceptance/AuthorizationEndpointTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,33 @@ public function testFailedAuthorizeRequest(): void
474474
$this->assertSame('The authorization grant type is not supported by the authorization server.', $jsonResponse['error_description']);
475475
$this->assertSame('Check that all required parameters have been provided', $jsonResponse['hint']);
476476
}
477+
478+
public function testUnathorizedImplicitRequest(): void
479+
{
480+
$this->loginUser();
481+
482+
$this->client->request(
483+
'GET',
484+
'/authorize',
485+
[
486+
'client_id' => FixtureFactory::FIXTURE_CLIENT_FIRST,
487+
'response_type' => 'token',
488+
'state' => 'foobar',
489+
]
490+
);
491+
492+
$response = $this->client->getResponse();
493+
494+
$this->assertSame(302, $response->getStatusCode());
495+
$redirectUri = $response->headers->get('Location');
496+
497+
$this->assertStringStartsWith(FixtureFactory::FIXTURE_CLIENT_FIRST_REDIRECT_URI, $redirectUri);
498+
$fragment = [];
499+
parse_str(parse_url($redirectUri, \PHP_URL_FRAGMENT), $fragment);
500+
$this->assertArrayHasKey('error', $fragment);
501+
$this->assertArrayHasKey('error_description', $fragment);
502+
$this->assertArrayHasKey('state', $fragment);
503+
$this->assertEquals('access_denied', $fragment['error']);
504+
$this->assertEquals('foobar', $fragment['state']);
505+
}
477506
}

0 commit comments

Comments
 (0)