|
6 | 6 |
|
7 | 7 | use Facile\OpenIDClient\AuthMethod\AuthMethodFactoryInterface; |
8 | 8 | use Facile\OpenIDClient\AuthMethod\AuthMethodInterface; |
| 9 | +use Facile\OpenIDClient\Client\Client; |
9 | 10 | use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient; |
| 11 | +use Facile\OpenIDClient\Client\Metadata\ClientMetadata; |
10 | 12 | use Facile\OpenIDClient\Client\Metadata\ClientMetadataInterface; |
11 | 13 | use Facile\OpenIDClient\Issuer\IssuerInterface; |
12 | 14 | use Facile\OpenIDClient\Issuer\Metadata\IssuerMetadataInterface; |
13 | 15 | use Facile\OpenIDClient\Service\AuthorizationService; |
14 | 16 | use Facile\OpenIDClient\Token\IdTokenVerifierBuilderInterface; |
| 17 | +use Facile\OpenIDClient\Token\TokenSetFactory; |
15 | 18 | use Facile\OpenIDClient\Token\TokenSetFactoryInterface; |
16 | 19 | use Facile\OpenIDClient\Token\TokenSetInterface; |
17 | 20 | use Facile\OpenIDClient\Token\TokenVerifierBuilderInterface; |
@@ -123,4 +126,46 @@ public function testFetchTokenFromCode(): void |
123 | 126 |
|
124 | 127 | static::assertSame($tokenSet->reveal(), $service->grant($openIdClient->reveal(), $claims)); |
125 | 128 | } |
| 129 | + |
| 130 | + public function testCallbackShouldNotProcessUnknownParams(): void |
| 131 | + { |
| 132 | + $tokenSetFactory = $this->prophesize(TokenSetFactoryInterface::class); |
| 133 | + $client = $this->prophesize(ClientInterface::class); |
| 134 | + $requestFactory = $this->prophesize(RequestFactoryInterface::class); |
| 135 | + $idTokenVerifierBuilder = $this->prophesize(IdTokenVerifierBuilderInterface::class); |
| 136 | + $tokenVerifierBuilder = $this->prophesize(TokenVerifierBuilderInterface::class); |
| 137 | + |
| 138 | + $service = new AuthorizationService( |
| 139 | + $tokenSetFactory->reveal(), |
| 140 | + $client->reveal(), |
| 141 | + $requestFactory->reveal(), |
| 142 | + $idTokenVerifierBuilder->reveal(), |
| 143 | + $tokenVerifierBuilder->reveal() |
| 144 | + ); |
| 145 | + |
| 146 | + $issuer = $this->prophesize(IssuerInterface::class); |
| 147 | + $clientMetadata = ClientMetadata::fromArray([ |
| 148 | + 'client_id' => 'foobar', |
| 149 | + 'client_secret' => 'secret', |
| 150 | + 'redirect_uris' => [ |
| 151 | + 'http://localhost/callback', |
| 152 | + ], |
| 153 | + ]); |
| 154 | + $client = new Client( |
| 155 | + $issuer->reveal(), |
| 156 | + $clientMetadata |
| 157 | + ); |
| 158 | + |
| 159 | + // Build poc request |
| 160 | + $body = 'claims[iss]=foobar&claims[sub]=adminuser1'; // forge arbitrary claims |
| 161 | + $headers = ['test' => 'test']; |
| 162 | + $serverRequest = new \GuzzleHttp\Psr7\ServerRequest('POST', 'http://127.0.0.1:8082', $headers, $body); |
| 163 | + |
| 164 | + $callbackParams = $service->getCallbackParams($serverRequest, $client); |
| 165 | + $tokenSet = $service->callback($client, $callbackParams); // tokenSet contains forged claims |
| 166 | + |
| 167 | + $claims = $tokenSet->claims(); |
| 168 | + |
| 169 | + $this->assertSame([], $claims); |
| 170 | + } |
126 | 171 | } |
0 commit comments