|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClient\ConformanceTest\RpTest\NonceRequestParameter; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Assert; |
|
8
|
|
|
use PHPUnit\Framework\AssertionFailedError; |
|
9
|
|
|
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest; |
|
10
|
|
|
use Facile\OpenIDClient\ConformanceTest\TestInfo; |
|
11
|
|
|
use Facile\OpenIDClient\Exception\InvalidArgumentException; |
|
12
|
|
|
use Facile\OpenIDClient\Session\AuthSession; |
|
13
|
|
|
use Facile\OpenIDClient\Service\AuthorizationService; |
|
14
|
|
|
use Facile\OpenIDClient\Service\UserInfoService; |
|
15
|
|
|
use function Facile\OpenIDClient\base64url_encode; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Always send a 'nonce' value as a request parameter while using implicit or hybrid flow. |
|
19
|
|
|
* Verify the 'nonce' value returned in the ID Token. |
|
20
|
|
|
* |
|
21
|
|
|
* An ID Token, either from the Authorization Endpoint or from the Token Endpoint, containing the same 'nonce' value |
|
22
|
|
|
* as passed in the authentication request when using hybrid flow or implicit flow. |
|
23
|
|
|
*/ |
|
24
|
|
|
class RpNonceUnlessCodeFlowTest extends AbstractRpTest |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
public function getTestId(): string |
|
28
|
|
|
{ |
|
29
|
|
|
return 'rp-nonce-unless-code-flow'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function execute(TestInfo $testInfo): void |
|
33
|
|
|
{ |
|
34
|
|
|
$client = $this->registerClient($testInfo); |
|
35
|
|
|
|
|
36
|
|
|
$authorizationService = new AuthorizationService(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
try { |
|
39
|
|
|
$authorizationService->getAuthorizationUri($client, [ |
|
40
|
|
|
'response_type' => $testInfo->getResponseType(), |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
throw new AssertionFailedError('No assertion'); |
|
44
|
|
|
} catch (InvalidArgumentException $e) { |
|
45
|
|
|
Assert::assertRegExp('/nonce MUST be provided for implicit and hybrid flows/', $e->getMessage()); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$nonce = base64url_encode(\random_bytes(32)); |
|
49
|
|
|
$authSession = AuthSession::fromArray(['nonce' => $nonce]); |
|
50
|
|
|
|
|
51
|
|
|
$uri = $authorizationService->getAuthorizationUri($client, [ |
|
52
|
|
|
'response_type' => $testInfo->getResponseType(), |
|
53
|
|
|
'nonce' => $nonce, |
|
54
|
|
|
]); |
|
55
|
|
|
// Simulate a redirect and create the server request |
|
56
|
|
|
$serverRequest = $this->simulateAuthRedirect($uri); |
|
57
|
|
|
|
|
58
|
|
|
$params = $authorizationService->getCallbackParams($serverRequest, $client); |
|
59
|
|
|
$tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
Assert::assertTrue(true); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.