public static function deserialize($input) { $json = JWTRawSerializer::deserialize($input); $raw_claims = json_decode($json, true); return JWTClaimSetFactory::build($raw_claims); }
/** * @throws \jwk\exceptions\InvalidJWKAlgorithm * @throws \jwk\exceptions\InvalidJWKType */ public function testSignAndVerificationTokenRSAUnicode() { $claim_set = JWTClaimSetFactory::build(array(RegisteredJWTClaimNames::Issuer => 'セバスチャン', RegisteredJWTClaimNames::ExpirationTime => 1300819380, "http://example.com/is_root" => true, 'groups' => array('admin', 'sudo', 'devs'))); //load server private key. $key = RSAJWKFactory::build(new RSAJWKPEMPrivateKeySpecification(TestKeys::$private_key_pem, RSAJWKPEMPrivateKeySpecification::WithoutPassword, JSONWebSignatureAndEncryptionAlgorithms::PS512)); $key->setId('server_key'); $alg = new StringOrURI(JSONWebSignatureAndEncryptionAlgorithms::PS512); $jws = JWSFactory::build(new JWS_ParamsSpecification($key, $alg, $claim_set)); // and sign with server private key $compact_serialization = $jws->toCompactSerialization(); $this->assertTrue(!is_null($jws)); $this->assertTrue(!empty($compact_serialization)); // then on client side, load the JWS from compact format $jws_1 = JWSFactory::build(new JWS_CompactFormatSpecification($compact_serialization)); $this->assertTrue(!is_null($jws_1)); // get the server public key from jose header .. $public_key = $jws_1->getJOSEHeader()->getHeaderByName(RegisteredJOSEHeaderNames::JSONWebKey); $this->assertTrue(!is_null($public_key)); $public_key = $public_key->getRawValue(); // and re built it from params $public_key = RSAJWKFactory::build(new RSAJWKParamsPublicKeySpecification($public_key[RSAKeysParameters::Modulus], $public_key[RSAKeysParameters::Exponent], $public_key[JSONWebKeyParameters::Algorithm], $public_key[JSONWebKeyParameters::PublicKeyUse])); //set the server public key and then proceed to verify signature $res = $jws_1->setKey($public_key)->verify($alg->getString()); $this->assertTrue($res); $this->assertTrue($jws_1->getClaimSet()->getIssuer()->getString() === 'セバスチャン'); }
public function testCreateWithZip() { $claim_set = JWTClaimSetFactory::build(array(RegisteredJWTClaimNames::Issuer => 'joe', RegisteredJWTClaimNames::ExpirationTime => 1300819380, "http://example.com/is_root" => true, 'groups' => array('admin', 'sudo', 'devs'))); // load server key from pem format $server_key = RSAJWKFactory::build(new RSAJWKPEMPrivateKeySpecification(TestKeys::$private_key_pem, RSAJWKPEMPrivateKeySpecification::WithoutPassword, JSONWebSignatureAndEncryptionAlgorithms::RS384)); $server_key->setId('rsa_server'); // and sign the jws with server private key $alg = new StringOrURI(JSONWebSignatureAndEncryptionAlgorithms::RS384); $jws = JWSFactory::build(new JWS_ParamsSpecification($server_key, $alg, $claim_set)); $payload = $jws->toCompactSerialization(); //load client public key $recipient_key = RSAJWKFactory::build(new RSAJWKPEMPublicKeySpecification(TestKeys::$public_key2_pem, JSONWebSignatureAndEncryptionAlgorithms::RSA1_5)); $recipient_key->setKeyUse(JSONWebKeyPublicKeyUseValues::Encryption)->setId('recipient_public_key'); $alg = new StringOrURI(JSONWebSignatureAndEncryptionAlgorithms::RSA1_5); $enc = new StringOrURI(JSONWebSignatureAndEncryptionAlgorithms::A256CBC_HS512); $zip = new JsonValue(CompressionAlgorithmsNames::Deflate); $jwe = JWEFactory::build(new JWE_ParamsSpecification($recipient_key, $alg, $enc, $payload, $zip)); // and finally encrypt it ... $compact_serialization = $jwe->toCompactSerialization(); $this->assertTrue(!empty($compact_serialization)); }