Created
August 25, 2015 10:55
-
-
Save Spomky/de287de15f19baab599b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "my/example", | |
"require": { | |
"spomky-labs/jose-service": "~0.0.6" | |
}, | |
"authors": [ | |
{ | |
"name": "John Smith", | |
"email": "[email protected]" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once __DIR__.'/vendor/autoload.php'; | |
use SpomkyLabs\Service\Jose; | |
use Jose\JWSInterface; | |
use Jose\JWEInterface; | |
/******************/ | |
/* INPUT DATA */ | |
/******************/ | |
//My shared key. This is a direct key | |
$shared_key = [ | |
'kty' => 'dir', | |
'dir' => 'saH0gFSP4XM_tAP_a5rU9ooHbltwLiJpL4LLLnrqQPw', | |
]; | |
//The JWE | |
$jwe = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwia2lkIjoiTXkgU2hhcmVkIEtleSJ9..gqkq-9muWfQd3AHD.kg_fCtrkId7poGRCUP9ARO4KQ4m0R6lU5rwNS8Mm8nLFMy_X3nBC1VkL_zDehO4K6eEliZ9ISBEE7fFM6aFppfTCwFd_q-qikoOy7zsSeOOEawDZX2qMMdZYnaZs1HZTezdgS7HmoNK1J1TfE1PNrmhjrIZEbTANWw.Hxy5fTBX8X10_bz5UuDeBQ'; | |
/******************/ | |
/* INITIALIZATION */ | |
/******************/ | |
//We get an instance of our Jose service | |
$jose = Jose::getInstance(); | |
//We set the configuration | |
$jose->getConfiguration()->set('algorithms', ['A256GCM', 'dir']); | |
$jose->getConfiguration()->set('audience', 'My service'); | |
//We add our shared key to the keyset manager | |
$jose->getKeysetManager()->loadKeyFromValues('My Shared Key', $shared_key); | |
/******************/ | |
/* LOADING */ | |
/******************/ | |
//We try to load the JWE | |
$loaded = $jose->load($jwe); | |
/******************/ | |
/* RESULT */ | |
/******************/ | |
if (false === $loaded) { | |
print_r("We can not load the input...\n"); | |
} elseif($loaded instanceof JWSInterface) { | |
//Following methods are available | |
$loaded->getProtectedHeader(); | |
$loaded->getUnprotectedHeader(); | |
$loaded->getProtectedHeaderValue($key); | |
$loaded->getUnprotectedHeaderValue($key); | |
$loaded->getHeaderValue($key); | |
$loaded->getHeaderOrPayloadValue($key); | |
$loaded->getPayload(); | |
$loaded->getPayloadValue($key); | |
$loaded->getType(); | |
$loaded->getContentType(); | |
$loaded->getIssuer(); | |
$loaded->getSubject(); | |
$loaded->getAudience(); | |
$loaded->getExpirationTime(); | |
$loaded->getNotBefore(); | |
$loaded->getIssuedAt(); | |
$loaded->getJWTID(); | |
$loaded->getAlgorithm(); | |
$loaded->getJWKUrl(); | |
$loaded->getJWK(); | |
$loaded->getKeyID(); | |
$loaded->getX509Url(); | |
$loaded->getX509CertificateChain(); | |
$loaded->getX509CertificateSha1Thumbprint(); | |
$loaded->getX509CertificateSha256Thumbprint(); | |
$loaded->getCritical(); | |
} elseif($loaded instanceof JWEInterface) { | |
//Same as JWSInterface + | |
$loaded->getZip(); | |
$loaded->getEncryptionAlgorithm(); | |
} else { | |
print_r("???...\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment