Merge commit '23e201d50ca14ecb3cb4dee157304c730062589d'

This commit is contained in:
R
2026-04-01 20:02:33 +07:00
4 changed files with 423 additions and 69 deletions

View File

@@ -20,7 +20,7 @@ class AuthService
exec($cmd);
}
}
/**
* Issue JWT access token for the given client
*/
@@ -90,23 +90,30 @@ class AuthService
{
try {
$parts = explode('.', $token);
if (count($parts) !== 3) {
return false;
}
$payload = json_decode(base64_decode(strtr($parts[1], '-_', '+/')));
// $payload = json_decode(base64_decode(strtr($parts[1], '-_', '+/')));
$payloadRaw = $parts[1];
$payloadRaw = strtr($payloadRaw, '-_', '+/');
$padding = strlen($payloadRaw) % 4;
if ($padding) {
$payloadRaw .= str_repeat('=', 4 - $padding);
}
$payload = json_decode(base64_decode($payloadRaw));
$clientId = $payload->sub ?? null;
if (!$clientId) {
return false;
}
$clients = config('api_clients.clients');
$client = collect($clients)->where('api_key', $clientId)->first();
$client = collect($clients)->where('api_key', $clientId)->first();
if (!$client || !isset($client['api_secret'])) {
return false;
}
return \Firebase\JWT\JWT::decode($token, new \Firebase\JWT\Key($client['api_secret'], 'HS256'));
} catch (\Exception $e) {
return false;