feat : admin aspect

This commit is contained in:
2025-09-15 14:45:29 +08:00
parent 8665b27294
commit 8046676669
11 changed files with 430 additions and 16 deletions

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\Middleware\Admin;
use App\Constants\ResultCode;
use App\Exception\ErrException;
use App\Interface\JwtInterface;
use App\Middleware\Token\AbstractTokenMiddleware;
use Lcobucci\JWT\Token\RegisteredClaims;
use Lcobucci\JWT\UnencryptedToken;
use function Hyperf\Support\env;
final class AdminTokenMiddleware extends AbstractTokenMiddleware
{
public function getJwt(): JwtInterface
{
return $this->jwtFactory->get('admin');
}
/**
* @param UnencryptedToken $token
* @return void
*/
public function checkIssuer(UnencryptedToken $token): void
{
$audience = $token->claims()->get(RegisteredClaims::ISSUER);
if ($audience !== env('APP_NAME') .'_admin') throw new ErrException('token错误',ResultCode::JWT_ERROR);
}
}