Implement Custom autoloader and JwtDecoder

This commit is contained in:
2026-05-31 12:49:27 +03:30
parent 83c6ce655b
commit a8a5065553
33 changed files with 208 additions and 3668 deletions
@@ -3,8 +3,8 @@
namespace Dabestaniha\AuthenticateBridge\App\Http\Controllers;
use Dabestaniha\AuthenticateBridge\App\Http\Requests\MahakAuthenticateRequest;
use ReflectionMethod;
use Firebase\JWT;
use Dabestaniha\AuthenticateBridge\App\Support\JwtDecoder;
use UnexpectedValueException;
class AuthenticateController extends InvocableController
{
@@ -32,9 +32,15 @@ class AuthenticateController extends InvocableController
$jwt_secret = get_configured_option('jwt-secret');
try {
$decoded = (array) JWT\JWT::decode($token, new JWT\Key($jwt_secret, 'HS256'));
return (array) $decoded['data'];
} catch (\Exception $e) {
$decoded = JwtDecoder::decodeHs256($token, $jwt_secret);
$data = $decoded['data'] ?? null;
if (!is_array($data)) {
throw new UnexpectedValueException('JWT data must be an object.');
}
return $data;
} catch (\Throwable $e) {
wp_die(view('invalid-token'), 'Invalid Token', ['response' => 500]);
}
}
@@ -75,4 +81,4 @@ class AuthenticateController extends InvocableController
do_action('wp_login', get_userdata($user_id)->user_login, get_userdata($user_id));
return true;
}
}
}