简体   繁体   中英

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

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"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM