Example #1
0
 /**
  * Returns the signature from given data
  *
  * @param array $header
  * @param string $data
  *
  * @return Signature
  */
 protected function parseSignature(array $header, $data)
 {
     if (empty($data) || !isset($header['alg']) || $header['alg'] == 'none') {
         return null;
     }
     $hash = $this->decoder->base64UrlDecode($data);
     return new Signature($hash);
 }
Example #2
0
 /**
  * @test
  *
  * @uses Lcobucci\JWT\Parser::__construct
  * @uses Lcobucci\JWT\Token::__construct
  * @uses Lcobucci\JWT\Signature::__construct
  *
  * @covers Lcobucci\JWT\Parser::parse
  * @covers Lcobucci\JWT\Parser::splitJwt
  * @covers Lcobucci\JWT\Parser::parseHeader
  * @covers Lcobucci\JWT\Parser::parseClaims
  * @covers Lcobucci\JWT\Parser::parseSignature
  */
 public function parseMustReturnASignedTokenWhenSignatureIsInformed()
 {
     $this->decoder->expects($this->at(1))->method('jsonDecode')->willReturn(['typ' => 'JWT', 'alg' => 'HS256']);
     $this->decoder->expects($this->at(3))->method('jsonDecode')->willReturn(['aud' => 'test']);
     $this->decoder->expects($this->at(4))->method('base64UrlDecode')->willReturn('aaa');
     $parser = $this->createParser();
     $token = $parser->parse('a.a.a');
     $this->assertAttributeEquals(['typ' => 'JWT', 'alg' => 'HS256'], 'headers', $token);
     $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $token);
     $this->assertAttributeEquals(new Signature('aaa'), 'signature', $token);
 }