签名
This commit is contained in:
@@ -117,12 +117,24 @@ class SystemController
|
|||||||
*/
|
*/
|
||||||
private function buildJwtPayload(User $user, ?Systems $system): array
|
private function buildJwtPayload(User $user, ?Systems $system): array
|
||||||
{
|
{
|
||||||
|
$now = time();
|
||||||
|
$exp = $now + config('jwt.jwt_expiration');
|
||||||
|
$system_ids = $user->systems ? $user->systems->pluck('id')->toArray() : [];
|
||||||
|
$role_ids = $user->roles ? $user->roles->pluck('id')->toArray() : [];
|
||||||
$payload = [
|
$payload = [
|
||||||
'user_id' => $user->id,
|
'sub' => 'user_' . $user->id,
|
||||||
'sn' => $user->sn ?? '',
|
'aud' => $system->code,
|
||||||
'name' => $user->name ?? '',
|
'iat' => $now,
|
||||||
'iat' => time(),
|
'exp' => $exp,
|
||||||
'exp' => time() + config('jwt.jwt_expiration'),
|
'nbf' => $now,
|
||||||
|
'typ' => 'access',
|
||||||
|
'uid' => $user->id,
|
||||||
|
'uname' => $user->name,
|
||||||
|
'role_ids' => $role_ids,
|
||||||
|
'system_ids' => $system_ids,
|
||||||
|
// 'user_id' => $user->id,
|
||||||
|
// 'sn' => $user->sn ?? '',
|
||||||
|
// 'name' => $user->name ?? '',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($system) {
|
if ($system) {
|
||||||
@@ -193,7 +205,7 @@ class SystemController
|
|||||||
'system_code' => $systemCode,
|
'system_code' => $systemCode,
|
||||||
'login_ip' => $ip,
|
'login_ip' => $ip,
|
||||||
'user_agent' => $ua,
|
'user_agent' => $ua,
|
||||||
'expired_at' => date('Y-m-d H:i:s', $expireAt),
|
'expired_at' => $expireAt,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class SystemAuth
|
|||||||
public static function generateSignature(string $userId, int $timestamp, string $secret): string
|
public static function generateSignature(string $userId, int $timestamp, string $secret): string
|
||||||
{
|
{
|
||||||
$data = $userId . $timestamp;
|
$data = $userId . $timestamp;
|
||||||
return hash_hmac('sha256', $data, $secret);
|
return hash_hmac('md5', $data, $secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user