Skip to content
Advertisement

Base 64 Decode Token that may have expired JWT php

I am using the code below to base 64 decode a token

list($header, $payload, $signature) = explode (".", $token);
$jsondata = base64_decode($payload);    

$data = (array) $jsondata;

$oSession->aSSO["email"] = $data["emails"];
$oSession->aSSO["customerId"] = $data["CustomerId"];

If I do var_dump($data);

I get

array(1) { [0]=> string(411) 
"{"nbf":1572801391,
"exp":1572801691,
"iss":"ISS",
"aud":"AUD","nonce":"NONCE",
"iat":IAT,
"sid":"SOD",
"sub":"SUB",
"auth_time":1572800662,
"idp":"IDP",
"CustomerId":"CUSTOMERID",
"emails":"EMAIL",
"amr":["pwd"]}" 
}

How do I get access to emails and CustomerId?

These are both coming back blank even though we can see from the var_dump that they are present

I have tried data[0]->CustomerId with no joy either

Advertisement

Answer

What you should be able to do is JSON decode the string without casting it to an array.

list($header, $payload, $signature) = explode (".", $token);
$jsondata = base64_decode($payload); 
$data = json_decode($jsondata, true);

$oSession->aSSO["email"] = $data["emails"];
$oSession->aSSO["customerId"] = $data["CustomerId"];
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement