mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 15:57:50 +08:00
32 lines
776 B
PHP
32 lines
776 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Middleware\Token;
|
|
|
|
use App\Constants\ResultCode;
|
|
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错误',ResultCode::JWT_ERROR);
|
|
}
|
|
}
|