1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClient\ConformanceTest\RpTest\ScopeRequestParameter; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Assert; |
8
|
|
|
use function Facile\OpenIDClient\base64url_decode; |
9
|
|
|
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest; |
10
|
|
|
use Facile\OpenIDClient\ConformanceTest\TestInfo; |
11
|
|
|
use Facile\OpenIDClient\Session\AuthSession; |
12
|
|
|
use Facile\OpenIDClient\Service\AuthorizationService; |
13
|
|
|
use Facile\OpenIDClient\Service\UserInfoService; |
14
|
|
|
use function Facile\OpenIDClient\base64url_encode; |
15
|
|
|
use function var_dump; |
16
|
|
|
|
17
|
|
|
class RpScopeUserinfoClaimsTest extends AbstractRpTest |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
public function getTestId(): string |
21
|
|
|
{ |
22
|
|
|
return 'rp-scope-userinfo-claims'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function execute(TestInfo $testInfo): void |
26
|
|
|
{ |
27
|
|
|
$client = $this->registerClient($testInfo); |
28
|
|
|
|
29
|
|
|
$authorizationService = new AuthorizationService(); |
|
|
|
|
30
|
|
|
$userInfoService = new UserInfoService(); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$authSession = AuthSession::fromArray([ |
33
|
|
|
'nonce' => base64url_encode(\random_bytes(32)), |
34
|
|
|
]); |
35
|
|
|
$uri = $authorizationService->getAuthorizationUri($client, [ |
36
|
|
|
'scope' => 'openid email', |
37
|
|
|
'response_type' => $testInfo->getResponseType(), |
38
|
|
|
'nonce' => $authSession->getNonce(), |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
// Simulate a redirect and create the server request |
42
|
|
|
$serverRequest = $this->simulateAuthRedirect($uri); |
43
|
|
|
|
44
|
|
|
$params = $authorizationService->getCallbackParams($serverRequest, $client); |
45
|
|
|
|
46
|
|
|
$tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
47
|
|
|
|
48
|
|
|
$accessToken = $tokenSet->getAccessToken(); |
49
|
|
|
|
50
|
|
|
if ($accessToken) { |
51
|
|
|
$userInfo = $userInfoService->getUserInfo($client, $tokenSet); |
52
|
|
|
} else { |
53
|
|
|
$userInfo = \json_decode(base64url_decode(\explode('.', $tokenSet->getIdToken())[1]), true); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
Assert::assertArrayHasKey('email', $userInfo); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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.