validate() public method

Validates if the token is valid
public validate ( ValidationData $data ) : boolean
$data ValidationData
return boolean
示例#1
0
 /**
  * @param Token $token
  * @return bool
  */
 public function validateToken(Token $token) : bool
 {
     return $token->validate($this->validationData) && $token->verify($this->signer, $this->secret);
 }
示例#2
0
 /**
  * @test
  *
  * @uses Lcobucci\JWT\Token::__construct
  * @uses Lcobucci\JWT\ValidationData
  * @uses Lcobucci\JWT\Claim\Basic
  * @uses Lcobucci\JWT\Claim\EqualsTo
  * @uses Lcobucci\JWT\Claim\LesserOrEqualsTo
  * @uses Lcobucci\JWT\Claim\GreaterOrEqualsTo
  *
  * @covers Lcobucci\JWT\Token::validate
  * @covers Lcobucci\JWT\Token::getValidatableClaims
  */
 public function validateShouldReturnTrueWhenThereAreNoFailedValidatableClaims()
 {
     $now = time();
     $token = new Token([], ['iss' => new EqualsTo('iss', 'test'), 'iat' => new LesserOrEqualsTo('iat', $now), 'exp' => new GreaterOrEqualsTo('ext', $now + 500), 'testing' => new Basic('testing', 'test')]);
     $data = new ValidationData($now + 10);
     $data->setIssuer('test');
     $this->assertTrue($token->validate($data));
 }
示例#3
0
文件: Jwt.php 项目: sizeg/yii2-jwt
 /**
  * Validate token
  * @param Token $token token object
  * @return bool
  */
 public function validateToken(Token $token, $currentTime = null)
 {
     $data = $this->getValidationData($currentTime);
     // @todo Add claims for validation
     return $token->validate($data);
 }
 /**
  * @param ParsedToken $parsed
  * @throws InvalidException if token validation fails
  */
 protected function validateParsedToken(ParsedToken $parsed)
 {
     if ($parsed->validate($this->validation)) {
         return;
     }
     throw new InvalidException('Token is expired or otherwise invalid', InvalidException::CODE_TOKEN_EXPIRED);
 }
示例#5
0
 /**
  * @param Jwt $jwt
  * @return bool
  */
 public function validateData(Jwt $jwt)
 {
     return $jwt->validate($this->validationData);
 }
示例#6
0
 /**
  * @param ParsedToken $parsed
  * @throws InvalidException if token validation fails
  */
 protected function validateParsedToken(ParsedToken $parsed)
 {
     if ($parsed->validate($this->validation)) {
         return;
     }
     throw InvalidException::invalidToken((string) $parsed);
 }
 /**
  * @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;
 }
 /**
  * @test
  *
  * @dataProvider invalidValidationData
  *
  * @depends builderCanGenerateAToken
  *
  * @covers Lcobucci\JWT\Builder
  * @covers Lcobucci\JWT\Parser
  * @covers Lcobucci\JWT\Token
  * @covers Lcobucci\JWT\ValidationData
  * @covers Lcobucci\JWT\Claim\Factory
  * @covers Lcobucci\JWT\Claim\Basic
  * @covers Lcobucci\JWT\Claim\EqualsTo
  * @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo
  * @covers Lcobucci\JWT\Parsing\Encoder
  * @covers Lcobucci\JWT\Parsing\Decoder
  */
 public function tokenValidationShouldReturnFalseWhenExpectedDataDontMatch(ValidationData $data, Token $generated)
 {
     $this->assertFalse($generated->validate($data));
 }
示例#9
-1
 /**
  * validate a given token object
  * 
  * @param Token $token
  * @return boolean
  */
 public function validate(Token $token)
 {
     $valid = $token->validate($this->rules());
     $verified = $token->verify(new Sha256(), config('jwt.key'));
     return $valid && $verified;
 }