verify() public method

Verify if the key matches with the one that created the signature
public verify ( Lcobucci\JWT\Signer $signer, Lcobucci\JWT\Signer\Key | string $key ) : boolean
$signer Lcobucci\JWT\Signer
$key Lcobucci\JWT\Signer\Key | string
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);
 }
 /**
  * @param ParsedToken $parsed
  * @throws InvalidException if token validation fails
  */
 protected function verifyParsedToken(ParsedToken $parsed)
 {
     if ($parsed->verify($this->signer, $this->config->getPublicKey())) {
         return;
     }
     throw new InvalidException('Token signature is not valid', InvalidException::CODE_TOKEN_INVALID);
 }
 /**
  * @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;
 }
示例#4
-1
 /**
  * @test
  *
  * @depends builderCanGenerateAToken
  *
  * @covers Lcobucci\JWT\Builder
  * @covers Lcobucci\JWT\Parser
  * @covers Lcobucci\JWT\Token
  * @covers Lcobucci\JWT\Signature
  * @covers Lcobucci\JWT\Claim\Factory
  * @covers Lcobucci\JWT\Claim\Basic
  * @covers Lcobucci\JWT\Signer\Key
  * @covers Lcobucci\JWT\Signer\BaseSigner
  * @covers Lcobucci\JWT\Signer\Hmac
  * @covers Lcobucci\JWT\Signer\Hmac\Sha256
  */
 public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
 {
     $this->assertTrue($token->verify($this->signer, 'testing'));
 }
示例#5
-1
 /**
  * @test
  *
  * @uses Lcobucci\JWT\Token::__construct
  *
  * @covers Lcobucci\JWT\Token::verify
  * @covers Lcobucci\JWT\Token::getPayload
  */
 public function verifyMustDelegateTheValidationToSignature()
 {
     $signer = $this->getMock(Signer::class);
     $signature = $this->getMock(Signature::class, [], [], '', false);
     $signer->expects($this->any())->method('getAlgorithmId')->willReturn('HS256');
     $signature->expects($this->once())->method('verify')->with($signer, $this->isType('string'), 'test')->willReturn(true);
     $token = new Token(['alg' => 'HS256'], [], $signature);
     $this->assertTrue($token->verify($signer, 'test'));
 }
示例#6
-1
 /**
  * @test
  *
  * @depends builderCanGenerateAToken
  *
  * @covers Lcobucci\JWT\Builder
  * @covers Lcobucci\JWT\Parser
  * @covers Lcobucci\JWT\Token
  * @covers Lcobucci\JWT\Signature
  * @covers Lcobucci\JWT\Claim\Factory
  * @covers Lcobucci\JWT\Claim\Basic
  * @covers Lcobucci\JWT\Signer\Key
  * @covers Lcobucci\JWT\Signer\BaseSigner
  * @covers Lcobucci\JWT\Signer\Rsa
  * @covers Lcobucci\JWT\Signer\Rsa\Sha256
  */
 public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
 {
     $this->assertTrue($token->verify($this->signer, self::$rsaKeys['public']));
 }
示例#7
-1
 /**
  * @test
  *
  * @depends builderCanGenerateAToken
  *
  * @covers \Lcobucci\JWT\Configuration
  * @covers \Lcobucci\JWT\Builder
  * @covers \Lcobucci\JWT\Parser
  * @covers \Lcobucci\JWT\Token
  * @covers \Lcobucci\JWT\Signature
  * @covers \Lcobucci\JWT\Claim\Factory
  * @covers \Lcobucci\JWT\Claim\Basic
  * @covers \Lcobucci\JWT\Signer\Key
  * @covers \Lcobucci\JWT\Signer\BaseSigner
  * @covers \Lcobucci\JWT\Signer\Ecdsa
  * @covers \Lcobucci\JWT\Signer\Ecdsa\KeyParser
  * @covers \Lcobucci\JWT\Signer\Ecdsa\EccAdapter
  * @covers \Lcobucci\JWT\Signer\Ecdsa\SignatureSerializer
  * @covers \Lcobucci\JWT\Signer\Ecdsa\Sha256
  */
 public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
 {
     self::assertTrue($token->verify($this->config->getSigner(), static::$ecdsaKeys['public1']));
 }
示例#8
-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;
 }
示例#9
-1
 /**
  * Verify is validate token in signature.
  *
  * @param Lcobucci\JWT\Token $token
  *
  * @return bool
  */
 public function isValidByToken(Token $token)
 {
     return $token->verify(new Sha256(), env('JWT_SECRET'));
 }
示例#10
-1
 /**
  * @param  \Lcobucci\JWT\Token  $token
  * @return bool
  */
 public function verify(Token $token)
 {
     return $token->verify($this->signer, $this->key);
 }
示例#11
-1
文件: Jwt.php 项目: sizeg/yii2-jwt
 /**
  * Validate token
  * @param Token $token token object
  * @return bool
  */
 public function verifyToken(Token $token)
 {
     $alg = $token->getHeader('alg');
     if (empty($this->supportedAlgs[$alg])) {
         throw new InvalidParamException('Algorithm not supported');
     }
     $signer = Yii::createObject($this->supportedAlgs[$alg]);
     return $token->verify($signer, $this->key);
 }
示例#12
-1
 /**
  * @test
  *
  * @depends builderCanGenerateAToken
  *
  * @covers \Lcobucci\JWT\Configuration
  * @covers \Lcobucci\JWT\Builder
  * @covers \Lcobucci\JWT\Parser
  * @covers \Lcobucci\JWT\Token
  * @covers \Lcobucci\JWT\Signature
  * @covers \Lcobucci\JWT\Claim\Factory
  * @covers \Lcobucci\JWT\Claim\Basic
  * @covers \Lcobucci\JWT\Signer\Key
  * @covers \Lcobucci\JWT\Signer\BaseSigner
  * @covers \Lcobucci\JWT\Signer\Hmac
  * @covers \Lcobucci\JWT\Signer\Hmac\Sha256
  */
 public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
 {
     self::assertTrue($token->verify($this->config->getSigner(), 'testing'));
 }
示例#13
-1
 /**
  * @param Jwt $jwt
  * @return bool
  */
 public function verifySignature(Jwt $jwt)
 {
     return $jwt->verify($this->signer, $this->publicKey);
 }
示例#14
-1
 /**
  * @test
  *
  * @depends builderCanGenerateAToken
  *
  * @covers Lcobucci\JWT\Builder
  * @covers Lcobucci\JWT\Parser
  * @covers Lcobucci\JWT\Token
  * @covers Lcobucci\JWT\Signature
  * @covers Lcobucci\JWT\Parsing\Encoder
  * @covers Lcobucci\JWT\Claim\Factory
  * @covers Lcobucci\JWT\Claim\Basic
  * @covers Lcobucci\JWT\Signer\OpenSSL
  * @covers Lcobucci\JWT\Signer\Ecdsa
  * @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
  */
 public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
 {
     $this->assertTrue($token->verify($this->signer, $this->publicEcdsa()));
 }
示例#15
-1
 /**
  * @param Token|null $token
  *
  * @return SessionInterface
  */
 public function extractSessionContainer(Token $token = null) : SessionInterface
 {
     try {
         if (null === $token || !$token->verify($this->signer, $this->verificationKey)) {
             return DefaultSessionData::newEmptySession();
         }
         return DefaultSessionData::fromDecodedTokenData((object) $token->getClaim(self::SESSION_CLAIM, new \stdClass()));
     } catch (\BadMethodCallException $invalidToken) {
         return DefaultSessionData::newEmptySession();
     }
 }
示例#16
-2
 /**
  * @param ParsedToken $parsed
  * @throws InvalidException if token validation fails
  */
 protected function verifyParsedToken(ParsedToken $parsed)
 {
     if ($parsed->verify($this->signer, $this->config->getPublicKey())) {
         return;
     }
     throw InvalidException::invalidSignature((string) $parsed);
 }