MAPG-69 add simple JWT parser

This commit is contained in:
Bence Pőcze 2020-06-21 01:31:20 +02:00
parent 7ba11f34cc
commit 2d2e218002

33
src/Util/JwtParser.php Normal file
View File

@ -0,0 +1,33 @@
<?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]);
}
}