public function testGenerationOfTheSigninInput() { $payload = array('a' => 'b'); $header = array('a' => 'b'); $jwt = new JWT($payload, $header); $encoder = new Base64UrlSafeEncoder(); $this->assertEquals(sprintf("%s.%s", $encoder->encode(json_encode($payload)), $encoder->encode(json_encode($header))), $jwt->generateSigninInput()); }
public function testPayload() { $jwt = new JWT(array('a' => 'b'), array()); $payload = $jwt->getPayload(); $this->assertSame(array('a' => 'b'), $payload); $jwt = new JWT(array('a' => 'b'), array()); $jwt->setPayload(array('b' => 'a')); $payload = $jwt->getPayload(); $this->assertSame($payload['b'], 'a'); $this->assertSame(array('b' => 'a'), $payload); }
/** * Constructor * * @param array $header An associative array of headers. The value can be any type accepted by json_encode or a JSON serializable object * @see http://php.net/manual/en/function.json-encode.php * @see http://php.net/manual/en/jsonserializable.jsonserialize.php * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#section-4 * @param string $encryptionEngine * } */ public function __construct($header = array(), $encryptionEngine = "OpenSSL") { if (!in_array($encryptionEngine, $this->supportedEncryptionEngines)) { throw new InvalidArgumentException(sprintf("Encryption engine %s is not supported", $encryptionEngine)); } $this->encryptionEngine = $encryptionEngine; parent::__construct(array(), $header); }
/** * Constructor. * * @param array $header An associative array of headers. The value can be any type accepted by json_encode or a JSON serializable object * * @see http://php.net/manual/en/function.json-encode.php * @see http://php.net/manual/en/jsonserializable.jsonserialize.php * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#section-4 * * @param string $encryptionEngine * } */ public function __construct($header = array(), $encryptionEngine = 'OpenSSL') { if (!in_array($encryptionEngine, $this->supportedEncryptionEngines)) { throw new InvalidArgumentException(sprintf('Encryption engine %s is not supported', $encryptionEngine)); } if ('SecLib' === $encryptionEngine && version_compare(PHP_VERSION, '7.0.0-dev') >= 0) { throw new InvalidArgumentException("phpseclib 1.0.0(LTS), even the latest 2.0.0, doesn't support PHP7 yet"); } $this->encryptionEngine = $encryptionEngine; parent::__construct(array(), $header); }
/** * Constructor * * @param string $algorithm * @param string $type */ public function __construct($algorithm, $type = null) { parent::__construct(array(), array('alg' => $algorithm, 'typ' => $type ?: "JWS")); }