示例#1
0
文件: JWT.php 项目: bendbennett/JWT
 /**
  * Claims is an additional set of claims supplied by end-user
  * There are default claims in Payload class
  * If end-user supplies claims with same name as default claims, the default claims in the Payload class will be overwritten
  *
  * @param array $claims
  * @return string
  */
 public function create(array $claims = array())
 {
     $this->payload->setClaims($claims);
     $this->jws->setPayload($this->payload->getPayload());
     $algo = $this->algoFactory->make();
     $this->jws->sign($algo->getKeyForSigning());
     $this->jti->create(['jti' => $this->payload->getClaim('jti'), 'exp' => $this->payload->getClaim('exp')]);
     return $this->jws->getTokenString();
 }
示例#2
0
 /**
  * @test
  * @group payload
  */
 public function customClaimsShouldBeAddedToClaims()
 {
     $payload = new Payload($this->request, $this->payloadUtilities, $this->payloadValidator, array('iat', 'exp', 'nbf', 'iss', 'jti'));
     $payload->setClaims(array('scopes' => array('hr' => array('admin', 'user' => array('create', 'read')))));
     $claims = $payload->getClaims();
     $this->assertArrayHasKey('scopes', $claims);
 }