示例#1
0
 /**
  * @param \Cyh\Jose\Signing\Signer\SignerInterface $signer
  * @param mixed $claims
  * @param resource|string $key default null
  * @param string $pass_phrase default null
  * @return string
  * @throws UnexpectedValueException
  * @throws InvalidSignatureException
  */
 public static function sign(SignerInterface $signer, $claims, $key = null, $pass_phrase = null)
 {
     $header_arr = array('typ' => 'JWT', 'alg' => $signer->getAlg());
     $header = new Header($header_arr);
     $message = $header->toString() . '.' . Base64Url::encode(Json::encode($claims));
     $signature = $signer->sign($message, $key, $pass_phrase);
     $signature_base64 = Base64Url::encode($signature);
     return $message . '.' . $signature_base64;
 }
示例#2
0
 public function testEncodeJsonInvalidParam()
 {
     if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
         $deep_array = array();
         $depth = 0;
         $deep_array = $this->_nestArray($deep_array, $depth);
         $depth = 0;
         $deep_array = $this->_nestArray($deep_array, $depth);
         $depth = 0;
         $deep_array = $this->_nestArray($deep_array, $depth);
         $this->setExpectedException('Cyh\\Jose\\Exception\\UnexpectedValueException');
         Json::encode($deep_array);
     }
 }
示例#3
0
 /**
  * @return string
  */
 public function __toString()
 {
     return Base64Url::encode(Json::encode($this->headers));
 }
示例#4
0
 /**
  * @expectedException Cyh\Jose\Signing\Exception\InvalidSignatureException
  */
 public function testRS256ModifiedClaimExp()
 {
     $token_strings = Jwt::sign(new RS256(), $this->valid_claims, $this->rsa_prv_key);
     list($h, $p, $s) = explode('.', $token_strings);
     $payload = Json::decode(Base64Url::decode($p));
     $payload['exp'] = time() + 86400;
     $p = Base64Url::encode(Json::encode($payload));
     $mod_token = "{$h}.{$p}.{$s}";
     Jwt::verify(new RS256(), $mod_token, $this->rsa_pub_key);
 }