File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -412,7 +412,11 @@ private function configureClaim($name, $value)
412412 public function withClaim ($ name , $ value )
413413 {
414414 if (in_array ($ name , RegisteredClaims::ALL , true )) {
415- throw RegisteredClaimGiven::forClaim ($ name );
415+ trigger_error ('The use of the method "withClaim" is deprecated for registered claims. Please use dedicated method instead. ' , E_USER_DEPRECATED );
416+ }
417+
418+ if ($ name === RegisteredClaims::AUDIENCE ) {
419+ return $ this ->permittedFor ($ value );
416420 }
417421
418422 return $ this ->configureClaim ($ name , $ value );
Original file line number Diff line number Diff line change @@ -564,15 +564,33 @@ public function withClaimMustKeepAFluentInterface()
564564 /**
565565 * @test
566566 *
567+ * @param string $claim
568+ * @param array $value
569+ *
567570 * @covers ::__construct
568571 * @covers ::withClaim
569572 * @covers \Lcobucci\JWT\Token\RegisteredClaimGiven
573+ *
574+ * @dataProvider dataWithClaimDeprecationNotice
570575 */
571- public function withClaimShouldThrowExceptionWhenTryingToConfigureARegisteredClaim ( )
576+ public function withClaimShouldSendDeprecationNoticeWhenTryingToConfigureARegisteredClaim ( $ claim , $ value )
572577 {
573- $ this ->expectException (RegisteredClaimGiven::class );
578+ $ this ->expectDeprecation ( ' The use of the method "withClaim" is deprecated for registered claims. Please use dedicated method instead. ' );
574579
575- $ this ->createBuilder ()->withClaim ('sub ' , 'me ' );
580+ $ this ->createBuilder ()->withClaim ($ claim , $ value );
581+ }
582+
583+ public function dataWithClaimDeprecationNotice ()
584+ {
585+ return [
586+ ['sub ' , 'me ' ],
587+ ['aud ' , 'him ' ],
588+ ['jti ' , '0123456789ABCDEF ' ],
589+ ['iss ' , 'you ' ],
590+ ['exp ' , time ()+3600 ],
591+ ['iat ' , time ()],
592+ ['nbf ' , time ()],
593+ ];
576594 }
577595
578596 /**
You can’t perform that action at this time.
0 commit comments