diff --git a/app/common/controller/SystemController.php b/app/common/controller/SystemController.php index 73f84d2..a845fad 100644 --- a/app/common/controller/SystemController.php +++ b/app/common/controller/SystemController.php @@ -117,12 +117,24 @@ class SystemController */ 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 = [ - 'user_id' => $user->id, - 'sn' => $user->sn ?? '', - 'name' => $user->name ?? '', - 'iat' => time(), - 'exp' => time() + config('jwt.jwt_expiration'), + 'sub' => 'user_' . $user->id, + 'aud' => $system->code, + 'iat' => $now, + 'exp' => $exp, + '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) { @@ -193,7 +205,7 @@ class SystemController 'system_code' => $systemCode, 'login_ip' => $ip, 'user_agent' => $ua, - 'expired_at' => date('Y-m-d H:i:s', $expireAt), + 'expired_at' => $expireAt, ]); } } diff --git a/app/common/utils/SystemAuth.php b/app/common/utils/SystemAuth.php index cbef538..6977fa8 100644 --- a/app/common/utils/SystemAuth.php +++ b/app/common/utils/SystemAuth.php @@ -14,7 +14,7 @@ class SystemAuth public static function generateSignature(string $userId, int $timestamp, string $secret): string { $data = $userId . $timestamp; - return hash_hmac('sha256', $data, $secret); + return hash_hmac('md5', $data, $secret); } /**