Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions solid/lib/Controller/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,21 @@ public function authorize() {
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);

$response = $server->respondToAuthorizationRequest($request, $user, $approval);
$response = $this->tokenGenerator->addIdTokenToResponse(
$response,
$clientId,
$this->getProfilePage(),
$this->session->get("nonce"),
$this->config->getPrivateKey()
);

// In the authorization code flow the ID token is issued by the token
// endpoint, not in the redirect. Clients pass the redirect URI they
// were called back on (minus code, state and iss) to the token
// endpoint, so an extra `id_token` query parameter makes that URI
// differ from the registered one and the code exchange fails.
if ($getVars['response_type'] !== 'code') {
$response = $this->tokenGenerator->addIdTokenToResponse(
$response,
$clientId,
$this->getProfilePage(),
$this->session->get("nonce"),
$this->config->getPrivateKey()
);
}

return $this->respond($response); // ->addHeader('Access-Control-Allow-Origin', '*');
}
Expand Down
47 changes: 47 additions & 0 deletions solid/tests/Unit/Controller/ServerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,53 @@ public function testAuthorizeWithInvalidRedirectUri()
$this->assertEquals($expected, $actual);
}

/**
* @testdox ServerController should not add an ID token to the redirect URI in the authorization code flow
*
* @covers ::authorize
*/
public function testAuthorizeWithCodeResponseTypeOmitsIdToken()
{
$_GET = [
'client_id' => self::MOCK_CLIENT_ID,
'code_challenge' => 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM',
'code_challenge_method' => 'S256',
'nonce' => 'mock-nonce',
'redirect_uri' => 'https://mock.client/redirect',
'response_type' => 'code',
'state' => 'mock-state',
];
$_SERVER['REQUEST_URI'] = '/apps/solid/authorize';

$clientData = json_encode(['client_name' => 'Mock Client', 'redirect_uris' => ['https://mock.client/redirect']]);

$parameters = $this->createMockConstructorParameters($clientData);

$this->mockConfig->method('getUserValue')
->with(self::MOCK_USER_ID, Application::APP_ID, 'allowedClients', '[]')
->willReturn(json_encode([self::MOCK_CLIENT_ID]));

$this->mockUserManager->method('userExists')->willReturn(true);

$controller = new ServerController(...$parameters);

try {
$response = $controller->authorize();
} finally {
$_GET = [];
}

$this->assertEquals(Http::STATUS_FOUND, $response->getStatus());

$location = parse_url($response->getHeaders()['Location'] ?? '');
parse_str($location['query'] ?? '', $query);

$this->assertEquals('https://mock.client/redirect', "{$location['scheme']}://{$location['host']}{$location['path']}");
$this->assertArrayHasKey('code', $query);
$this->assertEquals('mock-state', $query['state']);
$this->assertArrayNotHasKey('id_token', $query);
}

/**
* @testdox ServerController should return a 302 redirect when asked to authorize client that has been approved
*
Expand Down