Started implementing token exchange, tests

This commit is contained in:
Barnaby Walters 2021-06-10 18:25:54 +02:00
parent c3b4e5ec5b
commit 9c6ef316e1

View File

@ -537,33 +537,33 @@ EOT
]; ];
foreach ($testCases as $name => $params) { foreach ($testCases as $name => $params) {
// Create an auth code. foreach ([
$codeVerifier = generateRandomString(32); [$s, 'handleAuthorizationEndpointRequest'],
$authCode = $storage->createAuthCode([ [$s, 'handleTokenEndpointRequest'],
'client_id' => 'https://client.example.com/', ] as $endpointHandler) {
'redirect_uri' => 'https://client.example.com/auth', // Create an auth code.
'code_challenge' => generatePKCECodeChallenge($codeVerifier), $codeVerifier = generateRandomString(32);
'state' => '12345', $authCode = $storage->createAuthCode([
'code_challenge_method' => 'S256' 'client_id' => 'https://client.example.com/',
]); 'redirect_uri' => 'https://client.example.com/auth',
'code_challenge' => generatePKCECodeChallenge($codeVerifier),
$req = (new ServerRequest('POST', 'https://example.com'))->withParsedBody(array_merge([ 'state' => '12345',
'grant_type' => 'authorization_code', 'code_challenge_method' => 'S256'
'code' => $authCode->getKey(), ]);
'client_id' => $authCode->getData()['client_id'],
'redirect_uri' => $authCode->getData()['redirect_uri'], $req = (new ServerRequest('POST', 'https://example.com'))->withParsedBody(array_merge([
'code_verifier' => $codeVerifier 'grant_type' => 'authorization_code',
], $params)); 'code' => $authCode->getKey(),
'client_id' => $authCode->getData()['client_id'],
'redirect_uri' => $authCode->getData()['redirect_uri'],
'code_verifier' => $codeVerifier
], $params));
$authEndpointResponse = $s->handleAuthorizationEndpointRequest($req); $res = $endpointHandler($req);
$this->assertEquals(400, $authEndpointResponse->getStatusCode()); $this->assertEquals(400, $res->getStatusCode());
$authEndpointJson = json_decode((string) $authEndpointResponse->getBody(), true); $resJson = json_decode((string) $res->getBody(), true);
$this->assertEquals('invalid_grant', $authEndpointJson['error']); $this->assertEquals('invalid_grant', $resJson['error']);
}
$tokenEndpointResponse = $s->handleTokenEndpointRequest($req);
$this->assertEquals(400, $tokenEndpointResponse->getStatusCode());
$tokenEndpointJson = json_decode((string) $tokenEndpointResponse->getBody(), true);
$this->assertEquals('invalid_grant', $tokenEndpointJson['error']);
} }
} }