|
10 | 10 | use Laravel\Passport\ClientRepository;
|
11 | 11 | use Laravel\Passport\Database\Factories\ClientFactory;
|
12 | 12 | use Laravel\Passport\HasApiTokens;
|
| 13 | +use Laravel\Passport\Passport; |
13 | 14 | use Laravel\Passport\Token;
|
14 | 15 | use Laravel\Passport\TokenRepository;
|
15 | 16 | use Lcobucci\JWT\Configuration;
|
@@ -270,9 +271,65 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
|
270 | 271 |
|
271 | 272 | $this->assertSame(0, Token::count());
|
272 | 273 | }
|
| 274 | + |
| 275 | + public function testGettingCustomResponseType() |
| 276 | + { |
| 277 | + $this->withoutExceptionHandling(); |
| 278 | + Passport::$authorizationServerResponseType = new IdTokenResponse('foo_bar_open_id_token'); |
| 279 | + |
| 280 | + $user = new User(); |
| 281 | + $user-> email = '[email protected]'; |
| 282 | + $user->password = $this->app->make(Hasher::class)->make('foobar123'); |
| 283 | + $user->save(); |
| 284 | + |
| 285 | + /** @var Client $client */ |
| 286 | + $client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->id]); |
| 287 | + |
| 288 | + $response = $this->post( |
| 289 | + '/oauth/token', |
| 290 | + [ |
| 291 | + 'grant_type' => 'client_credentials', |
| 292 | + 'client_id' => $client->id, |
| 293 | + 'client_secret' => $client->secret, |
| 294 | + ] |
| 295 | + ); |
| 296 | + |
| 297 | + $response->assertOk(); |
| 298 | + |
| 299 | + $decodedResponse = $response->decodeResponseJson()->json(); |
| 300 | + |
| 301 | + $this->assertArrayHasKey('id_token', $decodedResponse); |
| 302 | + $this->assertSame('foo_bar_open_id_token', $decodedResponse['id_token']); |
| 303 | + } |
273 | 304 | }
|
274 | 305 |
|
275 | 306 | class User extends \Illuminate\Foundation\Auth\User
|
276 | 307 | {
|
277 | 308 | use HasApiTokens;
|
278 | 309 | }
|
| 310 | + |
| 311 | +class IdTokenResponse extends \League\OAuth2\Server\ResponseTypes\BearerTokenResponse |
| 312 | +{ |
| 313 | + /** |
| 314 | + * @var string Id token. |
| 315 | + */ |
| 316 | + protected $idToken; |
| 317 | + |
| 318 | + /** |
| 319 | + * @param string $idToken |
| 320 | + */ |
| 321 | + public function __construct($idToken) |
| 322 | + { |
| 323 | + $this->idToken = $idToken; |
| 324 | + } |
| 325 | + |
| 326 | + /** |
| 327 | + * @inheritdoc |
| 328 | + */ |
| 329 | + protected function getExtraParams(\League\OAuth2\Server\Entities\AccessTokenEntityInterface $accessToken) |
| 330 | + { |
| 331 | + return [ |
| 332 | + 'id_token' => $this->idToken, |
| 333 | + ]; |
| 334 | + } |
| 335 | +} |
0 commit comments