@@ -253,6 +253,72 @@ public function testIdTokenSignedWithClientSecret(): void
253
253
});
254
254
}
255
255
256
+ public function testIdTokenSignedWithIncorrectClientSecret (): void
257
+ {
258
+ $ idToken = generateJwt ([
259
+ "iss " => "https://provider.rdobeheer.nl " ,
260
+ "aud " => 'test-client-id ' ,
261
+ "sub " => 'test-subject ' ,
262
+ ], 'not-the-secret-client-secret ' );
263
+
264
+ Http::fake ([
265
+ // Token requested by OpenIDConnectClient::authenticate() function.
266
+ 'https://provider.rdobeheer.nl/token ' => Http::response ([
267
+ 'access_token ' => 'access-token-from-token-endpoint ' ,
268
+ 'id_token ' => $ idToken ,
269
+ 'token_type ' => 'Bearer ' ,
270
+ 'expires_in ' => 3600 ,
271
+ ]),
272
+ ]);
273
+
274
+ // Set OIDC config
275
+ $ this ->mockOpenIDConfigurationLoader ();
276
+ Config::set ('oidc.issuer ' , 'https://provider.rdobeheer.nl ' );
277
+ Config::set ('oidc.client_id ' , 'test-client-id ' );
278
+ Config::set ('oidc.client_secret ' , 'the-secret-client-secret ' );
279
+
280
+ // Mock LoginResponseHandlerInterface to check handleExceptionWhileAuthenticate is called.
281
+ $ mock = Mockery::mock (ExceptionHandlerInterface::class);
282
+ $ mock
283
+ ->shouldReceive ('handleExceptionWhileAuthenticate ' )
284
+ ->withArgs (function (OpenIDConnectClientException $ e ) {
285
+ return $ e ->getMessage () === 'Unable to verify signature ' ;
286
+ })
287
+ ->once ();
288
+ $ this ->app ->instance (ExceptionHandlerInterface::class, $ mock );
289
+
290
+ // Set the current state, which is usually generated and saved in the session before login,
291
+ // and sent to the issuer during the login redirect.
292
+ Session::put ('openid_connect_state ' , 'some-state ' );
293
+
294
+ // We simulate here that the user now comes back after successful login at issuer.
295
+ $ this ->getRoute ('oidc.login ' , ['code ' => 'some-code ' , 'state ' => 'some-state ' ]);
296
+
297
+ Http::assertSentCount (1 );
298
+ Http::assertSentInOrder ([
299
+ 'https://provider.rdobeheer.nl/token ' ,
300
+ ]);
301
+ Http::assertSent (function (Request $ request ) {
302
+ if ($ request ->url () === 'https://provider.rdobeheer.nl/token ' ) {
303
+ $ this ->assertSame (
304
+ expected: 'POST ' ,
305
+ actual: $ request ->method (),
306
+ );
307
+ $ this ->assertSame (
308
+ expected: 'grant_type=authorization_code '
309
+ . '&code=some-code '
310
+ . '&redirect_uri=http%3A%2F%2Flocalhost%2Foidc%2Flogin '
311
+ . '&client_id=test-client-id '
312
+ . '&client_secret=the-secret-client-secret ' ,
313
+ actual: $ request ->body (),
314
+ );
315
+ return true ;
316
+ }
317
+ return true ;
318
+ });
319
+ }
320
+
321
+
256
322
public function testTokenSignedWithPrivateKey (): void
257
323
{
258
324
Http::fake ([
0 commit comments