Psecio\Jwt\Jwt::decode PHP Метод

decode() публичный Метод

Decode the data with the given key Optional "verify" parameter validates the signature as well (default is on)
public decode ( string $data, boolean $verify = true ) : stdClass
$data string Data to decode (entire JWT data string)
$verify boolean Verify the signature on the data [optional]
Результат stdClass Decoded claims data
    public function decode($data, $verify = true)
    {
        $sections = explode('.', $data);
        if (count($sections) < 3) {
            throw new Exception\DecodeException('Invalid number of sections (<3)');
        }
        list($header, $claims, $signature) = $sections;
        $header = json_decode($this->base64Decode($header));
        $claims = json_decode($this->base64Decode($claims));
        $signature = $this->base64Decode($signature);
        $key = $this->getHeader()->getKey();
        if ($verify === true) {
            if ($this->verify($key, $header, $claims, $signature) === false) {
                throw new Exception\BadSignatureException('Signature did not verify');
            }
        }
        return $claims;
    }

Usage Example

Пример #1
0
 public function getTokenData($token)
 {
     $jwt = new Jwt\Jwt(new Jwt\Header('starfish'));
     return $jwt->decode($token);
 }