mapguesser/src/Util/JwtParser.php

34 lines
705 B
PHP
Raw Normal View History

2020-06-21 01:31:20 +02:00
<?php namespace MapGuesser\Util;
class JwtParser
{
private array $token;
public function __construct(?string $token = null)
{
if ($token !== null) {
$this->setToken($token);
}
}
public function setToken(string $token)
{
$this->token = explode('.', str_replace(['_', '-'], ['/', '+'], $token));
}
public function getHeader(): array
{
return json_decode(base64_decode($this->token[0]), true);
}
public function getPayload(): array
{
return json_decode(base64_decode($this->token[1]), true);
}
public function getSignature(): string
{
return base64_decode($this->token[2]);
}
}