Skip to content

Commit

Permalink
replaced deprecated methods of lcobucci/jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
SPie committed Oct 8, 2020
1 parent 13494ca commit 2b7e4fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/JWTHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Signer\Key;
use SPie\LaravelJWT\Contracts\JWT;
use SPie\LaravelJWT\Contracts\JWTFactory;
use SPie\LaravelJWT\Contracts\JWTHandler as JWTHandlerContract;
Expand Down Expand Up @@ -178,23 +179,23 @@ public function getValidJWT(string $token): JWT
*/
public function createJWT(string $subject, array $payload = [], int $ttl = null): JWT
{
list($issuedAt, $expiresAt) = $this->createTimestamps($ttl);
[$issuedAt, $expiresAt] = $this->createTimestamps($ttl);

$builder = $this->getNewBuilder()
->setIssuer($this->getIssuer())
->setSubject($subject)
->setIssuedAt($issuedAt);
->issuedBy($this->getIssuer())
->relatedTo($subject)
->issuedAt($issuedAt);

if ($expiresAt) {
$builder->setExpiration($expiresAt);
$builder->expiresAt($expiresAt);
}

foreach ($payload as $name => $value) {
$builder->set($name, $value);
$builder->withClaim($name, $value);
}

return $this->getJWTFactory()->createJWT(
$builder->sign($this->getSigner(), $this->getSecret())->getToken()
$builder->getToken($this->getSigner(), new Key($this->getSecret()))
);
}

Expand Down
13 changes: 5 additions & 8 deletions tests/JWTHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,19 @@ protected function createBuilder(Token $token = null): Builder
$builder = Mockery::spy(Builder::class);

return $builder
->shouldReceive('setIssuer')
->shouldReceive('issuedBy')
->andReturn($builder)
->getMock()
->shouldReceive('setSubject')
->shouldReceive('relatedTo')
->andReturn($builder)
->getMock()
->shouldReceive('setIssuedAt')
->shouldReceive('issuedAt')
->andReturn($builder)
->getMock()
->shouldReceive('setExpiration')
->shouldReceive('expiresAt')
->andReturn($builder)
->getMock()
->shouldReceive('set')
->andReturn($builder)
->getMock()
->shouldReceive('sign')
->shouldReceive('withClaim')
->andReturn($builder)
->getMock()
->shouldReceive('getToken')
Expand Down

0 comments on commit 2b7e4fd

Please sign in to comment.