feat : jwt

This commit is contained in:
2025-09-12 18:12:30 +08:00
parent a80c237bbb
commit ff3e0105ec
14 changed files with 362 additions and 38 deletions

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace App\Middleware\Token;
use App\Exception\ErrException;
use App\Interface\JwtInterface;
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错误');
}
}