Skip to content

Commit

Permalink
Merge pull request #297 from lcobucci/fix-method-name
Browse files Browse the repository at this point in the history
Fix method name for audience configuration
  • Loading branch information
lcobucci authored May 24, 2019
2 parents cc63116 + 107946f commit a11ec5f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 17 additions & 2 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions test/unit/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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'));
}

/**
Expand Down

0 comments on commit a11ec5f

Please sign in to comment.