mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 18:17:49 +08:00
fix : jwt
This commit is contained in:
27
app/Service/Admin/Login/RefreshService.php
Normal file
27
app/Service/Admin/Login/RefreshService.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Login;
|
||||
|
||||
use App\Service\Admin\BaseAdminService;
|
||||
use Lcobucci\JWT\UnencryptedToken;
|
||||
|
||||
class RefreshService extends BaseAdminService
|
||||
{
|
||||
public function handle(): array
|
||||
{
|
||||
return $this->adminReturn->success();
|
||||
}
|
||||
|
||||
public function refreshToken(UnencryptedToken $token)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,10 @@ use App\Exception\ErrException;
|
||||
use App\Interface\CheckTokenInterface;
|
||||
use App\Lib\Jwt\JwtFactory;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Lcobucci\JWT\Token\RegisteredClaims;
|
||||
use Lcobucci\JWT\UnencryptedToken;
|
||||
use App\Interface\JwtInterface;
|
||||
use function Hyperf\Support\value;
|
||||
|
||||
final class BaseTokenService implements CheckTokenInterface
|
||||
{
|
||||
@@ -35,14 +37,6 @@ final class BaseTokenService implements CheckTokenInterface
|
||||
return $this->jwtFactory->get($this->jwt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JwtInterface
|
||||
*/
|
||||
public function getApiJwt(): JwtInterface
|
||||
{
|
||||
return $this->jwtFactory->get('api');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UnencryptedToken $token
|
||||
* @return void
|
||||
@@ -51,4 +45,20 @@ final class BaseTokenService implements CheckTokenInterface
|
||||
{
|
||||
$this->getJwt()->hasBlackList($token) && throw new ErrException('token已过期');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UnencryptedToken $token
|
||||
* @return \Closure
|
||||
*/
|
||||
public function refreshToken(UnencryptedToken $token): \Closure
|
||||
{
|
||||
return value(static function (JwtInterface $jwt) use ($token) {
|
||||
$jwt->addBlackList($token);
|
||||
return [
|
||||
'access_token' => $jwt->builderAccessToken($token->claims()->get(RegisteredClaims::ID))->toString(),
|
||||
'refresh_token' => $jwt->builderRefreshToken($token->claims()->get(RegisteredClaims::ID))->toString(),
|
||||
'expire_at' => (int) $jwt->getConfig('ttl', 0),
|
||||
];
|
||||
}, $this->getJwt());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user