getClaim() public method

Returns the value of a token claim
public getClaim ( string $name, mixed $default = null ) : mixed
$name string
$default mixed
return mixed
示例#1
1
 public function loginByToken(Token $token)
 {
     $uid = $token->getClaim('uid');
     try {
         $this->user = $this->usersRepository->getById($uid);
     } catch (UserNotFoundException $e) {
         // do nothing here
     }
 }
 /**
  * Validates JWT token
  *
  * @param Token $token
  * @throws ExpiredTokenException when token has expired and can be refreshed
  * @throws InvalidTokenException when token has expired or is invalid
  */
 protected function validateToken(Token $token = null)
 {
     if (null === $token) {
         throw new InvalidTokenException();
     }
     $exp = (new \DateTime())->setTimestamp($token->getClaim('exp'));
     $now = date_create();
     $refreshTtl = \DateInterval::createFromDateString($this->refreshTtl);
     if ($now < $exp) {
         return;
     }
     if ($exp->add($refreshTtl) > $now) {
         throw new ExpiredTokenException();
     }
     throw new InvalidTokenException();
 }
示例#3
0
 /**
  * @test
  *
  * @uses Lcobucci\JWT\Token::__construct
  * @uses Lcobucci\JWT\Token::hasClaim
  * @uses Lcobucci\JWT\Claim\Basic
  *
  * @covers Lcobucci\JWT\Token::getClaim
  */
 public function getClaimShouldReturnTheClaimValueWhenItExists()
 {
     $token = new Token([], ['testing' => new Basic('testing', 'test')]);
     $this->assertEquals('test', $token->getClaim('testing'));
 }
 public function deSerialize(Token $token) : Data
 {
     return Data::fromJsonString($token->getClaim('data'));
 }
 /**
  * {@inheritDoc}
  */
 private function shouldTokenBeRefreshed(Token $token) : bool
 {
     if (!$token->hasClaim(self::ISSUED_AT_CLAIM)) {
         return false;
     }
     return $this->timestamp() >= $token->getClaim(self::ISSUED_AT_CLAIM) + $this->refreshTime;
 }
示例#6
0
 /**
  * Get the unique key held within the blacklist.
  *
  * @param  \Lcobucci\JWT\Token  $token
  *
  * @return mixed
  */
 public function getKey(Token $token)
 {
     return $token->getClaim($this->key);
 }
示例#7
0
 protected function getTokenCredentials(Token $token)
 {
     $creds = [];
     foreach ($this->config['payload'] as $property) {
         $creds[$property] = $token->getClaim($property);
     }
     return $creds;
 }
 /**
  * @inheritdoc
  */
 public function isValid(Token $token)
 {
     $signer = new Sha256();
     $key = new Key($this->pathPublicKey);
     if (!$token->verify($signer, $key)) {
         throw new InvalidDefinitionException('Invalid token');
     }
     $data = new ValidationData();
     $data->setIssuer($token->getClaim('iss'));
     $data->setAudience($token->getClaim('aud'));
     $data->setId($token->getClaim('jti'));
     $isValid = $token->validate($data);
     if (!$isValid) {
         throw new AuthenticationExpiredException('The access token has expired');
     }
     return $isValid;
 }