Jose\Factory\JWSFactory::createJWSToCompactJSON PHP Method

createJWSToCompactJSON() public static method

public static createJWSToCompactJSON ( $payload, Jose\Object\JWKInterface $signature_key, array $protected_headers )
$signature_key Jose\Object\JWKInterface
$protected_headers array
    public static function createJWSToCompactJSON($payload, JWKInterface $signature_key, array $protected_headers)
    {
        $jws = self::createJWSAndSign($payload, $signature_key, $protected_headers, []);
        return $jws->toCompactJSON(0);
    }

Usage Example

 /**
  * Create a JSON Web Token.
  *
  * @param array $payload
  * @return string
  * @throws JWTException
  */
 public function encode(array $payload)
 {
     try {
         $token = JWEFactory::createJWEToCompactJSON($payload, $this->encryptionKey, ['alg' => 'dir', 'enc' => $this->encryptionKey->get('alg'), 'zip' => 'DEF']);
         return JWSFactory::createJWSToCompactJSON($token, $this->signatureKey, ['alg' => $this->signatureKey->get('alg'), 'zip' => 'DEF']);
     } catch (Exception $e) {
         throw new JWTException('Could not create token: ' . $e->getMessage());
     }
 }
All Usage Examples Of Jose\Factory\JWSFactory::createJWSToCompactJSON