for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\JWT;
/**
* @author Kevin Bond <[email protected]>
*/
final class TokenBuilder
{
private $claims = [];
private $headers = [Token::HEADER_TYP => 'JWT'];
* @param string $key
* @param mixed $value
*
* @return self
public function set($key, $value)
$this->claims[$key] = $value;
return $this;
}
* @param string $value
public function issuer($value)
return $this->set(Token::CLAIM_ISS, $value);
public function subject($value)
return $this->set(Token::CLAIM_SUB, $value);
public function audience($value)
return $this->set(Token::CLAIM_AUD, $value);
* @param \DateTime $time
public function expiresAt(\DateTime $time)
return $this->set(Token::CLAIM_EXP, $time->getTimestamp());
public function notBefore(\DateTime $time)
return $this->set(Token::CLAIM_NBF, $time->getTimestamp());
* @param \DateTime|null $time
public function issuedAt(\DateTime $time = null)
if (null === $time) {
$time = new \DateTime('now');
return $this->set(Token::CLAIM_IAT, $time->getTimestamp());
public function id($value)
return $this->set(Token::CLAIM_JTI, $value);
* @return Token
public function create()
return new Token($this->claims, $this->headers);