I have implemented JWT token generator library from Here, and i am able to get RS256 Token (Payload). But i am having issue with Header data: I need one header value "x5t", which is not generated from the given library. I need header data like:
{
"typ": "JWT",
"alg": "RS256",
"x5t": "COm8ON2SD2MTc5jwcxZ0vE3-XJo"
}
I am getting first two parameter successfully, but not able to get valid third parameter.
My Sample code is :
$fingerprint = str_replace("SHA1 Fingerprint=", '', system('openssl x509 -noout -in my.pem -fingerprint'));
$fingerprint = sha1($fingerprint);
$fingerprint = base64_encode($fingerprint);
$fingerprint = rtrim(strtr($fingerprint, "+/", "-_"), '=');
To generate Valid "x5t" parameter there is already code available in .NET, need to convert in PHP.
Thanks for watching my question. Any suggestion welcomed.
If you have PHP 5.6, you can use the following function
openssl_x509_fingerprint
:If you do not have PHP 5.6, you can generate this fingerprint by yourself using the content of your certificate file (begins with
BEGIN CERTIFICATE
and ends withEND CERTIFICATE
):Do not forget to encode in Base64 Url Safe the result.
openssl_x509_fingerprint
(which Florent Morselli mentioned) returns an sha1 hash of the DER encoding of the cert. eg.They output the same thing. At least with this cert:
openssl_x509_fingerprint
is only on PHP 5.6 so if you're PHP 5.5 or earlier you can use the alternative method instead.system
outputs its result directly, unless you use the optional second parameter, which puts the result into the variable.So use
http://php.net/manual/en/function.system.php