Emarref\Jwt\Signature\Jws::sign PHP Method

sign() public method

public sign ( Token $token )
$token Emarref\Jwt\Token
    public function sign(Token $token)
    {
        $token->addHeader(new Algorithm($this->encryption->getAlgorithmName()));
        $rawSignature = $this->getUnsignedValue($token);
        $signature = $this->encryption->encrypt($rawSignature);
        $token->setSignature($signature);
    }

Usage Example

コード例 #1
0
ファイル: JwsTest.php プロジェクト: emarref/jwt
 public function testSign()
 {
     $expectedSignature = 'foobar';
     // Configure payload
     $headerParameters = $this->getMockBuilder('Emarref\\Jwt\\Token\\PropertyList')->getMock();
     $headerParameters->expects($this->once())->method('jsonSerialize');
     $this->encoder->expects($this->at(0))->method('encode');
     $header = $this->getMockBuilder('Emarref\\Jwt\\Token\\Header')->getMock();
     $header->expects($this->once())->method('getParameters')->will($this->returnValue($headerParameters));
     // Configure payload
     $claims = $this->getMockBuilder('Emarref\\Jwt\\Token\\PropertyList')->getMock();
     $claims->expects($this->once())->method('jsonSerialize');
     $payload = $this->getMockBuilder('Emarref\\Jwt\\Token\\Payload')->getMock();
     $payload->expects($this->once())->method('getClaims')->will($this->returnValue($claims));
     $this->encoder->expects($this->at(1))->method('encode');
     // Configure token
     $token = $this->getMockBuilder('Emarref\\Jwt\\Token')->getMock();
     $token->expects($this->once())->method('getHeader')->will($this->returnValue($header));
     $token->expects($this->once())->method('getPayload')->will($this->returnValue($payload));
     $this->encryption->expects($this->once())->method('getAlgorithmName')->will($this->returnValue('alg'));
     $this->encryption->expects($this->once())->method('encrypt')->will($this->returnValue($expectedSignature));
     $token->expects($this->once())->method('addHeader')->with(new Algorithm('alg'));
     $token->expects($this->once())->method('setSignature')->with($expectedSignature);
     $this->signer->sign($token);
 }
All Usage Examples Of Emarref\Jwt\Signature\Jws::sign