mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 17:07:49 +08:00
feat : jwt
This commit is contained in:
34
app/Service/Admin/AdminUser/UserService.php
Normal file
34
app/Service/Admin/AdminUser/UserService.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\AdminUser;
|
||||
|
||||
use App\Lib\Jwt\RequestScopedTokenTrait;
|
||||
use App\Service\Admin\BaseAdminService;
|
||||
use Lcobucci\JWT\Token\RegisteredClaims;
|
||||
|
||||
class UserService extends BaseAdminService
|
||||
{
|
||||
use RequestScopedTokenTrait;
|
||||
|
||||
public function handle(): array
|
||||
{
|
||||
var_dump($this->getToken()->claims()->all());
|
||||
var_dump($this->getToken()->claims()->get(RegisteredClaims::ID));
|
||||
var_dump($this->getToken()->claims()->get(RegisteredClaims::AUDIENCE));
|
||||
|
||||
return $this->adminReturn->success();
|
||||
}
|
||||
|
||||
public function refresh(): array
|
||||
{
|
||||
return $this->adminReturn->success();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ use App\Interface\JwtInterface;
|
||||
use App\Lib\Jwt\JwtFactory;
|
||||
use App\Repository\AdminUserRepository;
|
||||
use App\Service\Admin\BaseAdminService;
|
||||
use App\Service\BaseTokenService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class LoginService extends BaseAdminService
|
||||
@@ -32,10 +33,10 @@ class LoginService extends BaseAdminService
|
||||
protected AdminUserRepository $userRepository;
|
||||
|
||||
/**
|
||||
* @var JwtFactory
|
||||
* @var BaseTokenService
|
||||
*/
|
||||
#[Inject]
|
||||
protected JwtFactory $jwtFactory;
|
||||
protected BaseTokenService $tokenService;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -53,20 +54,12 @@ class LoginService extends BaseAdminService
|
||||
|
||||
if ($adminInfo->status == AdminUserStatusCode::DISABLE) throw new ErrException('用户已禁用');
|
||||
|
||||
$jwtHandle = $this->getJwt();
|
||||
$jwtHandle = $this->tokenService->getJwt();
|
||||
|
||||
return [
|
||||
return $this->adminReturn->success('success',[
|
||||
'access_token' => $jwtHandle->builderAccessToken((string) $adminInfo->id)->toString(),
|
||||
'refresh_token' => $jwtHandle->builderRefreshToken((string) $adminInfo->id)->toString(),
|
||||
'expire_at' => (int) $jwtHandle->getConfig('ttl', 0),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JwtInterface
|
||||
*/
|
||||
private function getJwt(): JwtInterface
|
||||
{
|
||||
return $this->jwtFactory->get($this->jwt);
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user