consolidate some JWT handling into one class

This commit is contained in:
Dylan K. Taylor
2020-05-06 21:32:22 +01:00
parent 5d154e43a9
commit ed757c7207
5 changed files with 78 additions and 47 deletions

View File

@@ -361,30 +361,6 @@ class Utils{
return $hash;
}
/**
* @return mixed[] array of claims
* @phpstan-return array<string, mixed>
*
* @throws \UnexpectedValueException
*/
public static function getJwtClaims(string $token) : array{
$v = explode(".", $token);
if(count($v) !== 3){
throw new \UnexpectedValueException("Expected exactly 3 JWT parts, got " . count($v));
}
$payloadB64 = $v[1];
$payloadJSON = base64_decode(strtr($payloadB64, '-_', '+/'), true);
if($payloadJSON === false){
throw new \UnexpectedValueException("Invalid base64 JWT payload");
}
$result = json_decode($payloadJSON, true);
if(!is_array($result)){
throw new \UnexpectedValueException("Failed to decode JWT payload JSON: " . json_last_error_msg());
}
return $result;
}
/**
* @param object $value
*/