diff --git a/README.md b/README.md index fda9865c..c74803ae 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ use Lcobucci\JWT\Builder; $time = time(); $token = (new Builder())->issuedBy('http://example.com') // Configures the issuer (iss claim) - ->canOnlyBeUsedBy('http://example.org') // Configures the audience (aud claim) + ->permittedFor('http://example.org') // Configures the audience (aud claim) ->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item ->issuedAt($time) // Configures the time that the token was issue (iat claim) ->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim) @@ -151,7 +151,7 @@ $signer = new Sha256(); $time = time(); $token = (new Builder())->issuedBy('http://example.com') // Configures the issuer (iss claim) - ->canOnlyBeUsedBy('http://example.org') // Configures the audience (aud claim) + ->permittedFor('http://example.org') // Configures the audience (aud claim) ->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item ->issuedAt($time) // Configures the time that the token was issue (iat claim) ->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim) @@ -178,7 +178,7 @@ $privateKey = new Key('file://{path to your private key}'); $time = time(); $token = (new Builder())->issuedBy('http://example.com') // Configures the issuer (iss claim) - ->canOnlyBeUsedBy('http://example.org') // Configures the audience (aud claim) + ->permittedFor('http://example.org') // Configures the audience (aud claim) ->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item ->issuedAt($time) // Configures the time that the token was issue (iat claim) ->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim) diff --git a/src/Builder.php b/src/Builder.php index 9af1d5bb..f7aa9b65 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -7,7 +7,6 @@ namespace Lcobucci\JWT; -use BadMethodCallException; use Lcobucci\JWT\Claim\Factory as ClaimFactory; use Lcobucci\JWT\Parsing\Encoder; use Lcobucci\JWT\Signer\Key; @@ -76,6 +75,9 @@ public function __construct( /** * Configures the audience * + * @deprecated This method has been wrongly added and doesn't exist on v4 + * @see Builder::permittedFor() + * * @param string $audience * @param bool $replicateAsHeader * @@ -86,11 +88,24 @@ public function canOnlyBeUsedBy($audience, $replicateAsHeader = false) return $this->setRegisteredClaim('aud', (string) $audience, $replicateAsHeader); } + /** + * Configures the audience + * + * @param string $audience + * @param bool $replicateAsHeader + * + * @return Builder + */ + public function permittedFor($audience, $replicateAsHeader = false) + { + return $this->setRegisteredClaim('aud', (string) $audience, $replicateAsHeader); + } + /** * Configures the audience * * @deprecated This method will be removed on v4 - * @see Builder::canOnlyBeUsedBy() + * @see Builder::permittedFor() * * @param string $audience * @param boolean $replicateAsHeader diff --git a/test/unit/BuilderTest.php b/test/unit/BuilderTest.php index 2d2eca7d..30c43b66 100644 --- a/test/unit/BuilderTest.php +++ b/test/unit/BuilderTest.php @@ -75,13 +75,13 @@ public function constructMustInitializeTheAttributes() * @uses Lcobucci\JWT\Builder::__construct * @uses Lcobucci\JWT\Builder::withClaim * - * @covers Lcobucci\JWT\Builder::canOnlyBeUsedBy + * @covers Lcobucci\JWT\Builder::permittedFor * @covers Lcobucci\JWT\Builder::setRegisteredClaim */ - public function canOnlyBeUsedByMustChangeTheAudClaim() + public function permittedForMustChangeTheAudClaim() { $builder = $this->createBuilder(); - $builder->canOnlyBeUsedBy('test'); + $builder->permittedFor('test'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder); $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder); @@ -93,13 +93,13 @@ public function canOnlyBeUsedByMustChangeTheAudClaim() * @uses Lcobucci\JWT\Builder::__construct * @uses Lcobucci\JWT\Builder::withClaim * - * @covers Lcobucci\JWT\Builder::canOnlyBeUsedBy + * @covers Lcobucci\JWT\Builder::permittedFor * @covers Lcobucci\JWT\Builder::setRegisteredClaim */ - public function canOnlyBeUsedByCanReplicateItemOnHeader() + public function permittedForCanReplicateItemOnHeader() { $builder = $this->createBuilder(); - $builder->canOnlyBeUsedBy('test', true); + $builder->permittedFor('test', true); $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder); @@ -116,14 +116,14 @@ public function canOnlyBeUsedByCanReplicateItemOnHeader() * @uses Lcobucci\JWT\Builder::__construct * @uses Lcobucci\JWT\Builder::withClaim * - * @covers Lcobucci\JWT\Builder::canOnlyBeUsedBy + * @covers Lcobucci\JWT\Builder::permittedFor * @covers Lcobucci\JWT\Builder::setRegisteredClaim */ - public function canOnlyBeUsedByMustKeepAFluentInterface() + public function permittedForMustKeepAFluentInterface() { $builder = $this->createBuilder(); - $this->assertSame($builder, $builder->canOnlyBeUsedBy('test')); + $this->assertSame($builder, $builder->permittedFor('test')); } /**