mirror of
https://gitee.com/ctexthuang/hyperf-micro-svc.git
synced 2026-02-08 10:20:16 +08:00
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?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\Lib\Jwt\RequestScopedTokenTrait;
|
|
use App\Service\Admin\BaseAdminService;
|
|
use App\Service\BaseTokenService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Lcobucci\JWT\Token\RegisteredClaims;
|
|
use Lcobucci\JWT\UnencryptedToken;
|
|
|
|
class RefreshService extends BaseAdminService
|
|
{
|
|
use RequestScopedTokenTrait;
|
|
|
|
/**
|
|
* @var BaseTokenService
|
|
*/
|
|
#[Inject]
|
|
protected BaseTokenService $tokenService;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
return $this->adminReturn->success('success',$this->refreshToken($this->getToken()));
|
|
}
|
|
|
|
/**
|
|
* @param UnencryptedToken $token
|
|
* @return array<string,int|string>
|
|
*/
|
|
public function refreshToken(UnencryptedToken $token): array
|
|
{
|
|
$jwt = $this->tokenService->setJwt('admin')->getJwt();
|
|
$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),
|
|
];
|
|
}
|
|
} |