public function testEncodeDecode01() { $jwt = new Jwt(); $jwt->setIssuedAt($expectedIssuedAt = time())->setIssuer($expectedIssuer = 'BWC')->setSubject($expectedSubject = 'subject')->setAudience($expectedAudience = 'audience')->setExpirationTime($expectedExpirationTime = $expectedIssuedAt + 120)->setNotBefore($expectedNotBefore = $expectedIssuedAt - 120)->setJwtId($expectedId = mt_rand(10000, 999999))->set('email', $expectedEmail = '*****@*****.**'); $encoder = new Encoder(); $key = 's466j5424G1eLsSBT45I2p94t'; $token = $encoder->encode($jwt, $key); $jwt = $encoder->decode($token, null, $key); $this->assertEquals($expectedIssuedAt, $jwt->getIssuedAt()); $this->assertEquals($expectedIssuer, $jwt->getIssuer()); $this->assertEquals($expectedSubject, $jwt->getSubject()); $this->assertEquals($expectedAudience, $jwt->getAudience()); $this->assertEquals($expectedExpirationTime, $jwt->getExpirationTime()); $this->assertEquals($expectedNotBefore, $jwt->getNotBefore()); $this->assertEquals($expectedId, $jwt->getJwtId()); $this->assertEquals($expectedEmail, $jwt->get('email')); }
public function __construct(array $header = array(), array $payload = array()) { parent::__construct($header, $payload); }
/** * @param Jwt $jwt */ public function timestampJwt(Jwt $jwt) { $jwt->setIssuer($this->issuer); $jwt->setIssuedAt(time()); if (null === $jwt->getJwtId()) { $jwt->setJwtId(sha1(uniqid(mt_rand(), true))); } }