From d346ca6a1fe1e899492b4d3057b16845aa731682 Mon Sep 17 00:00:00 2001
From: log
Date: Tue, 23 Jun 2026 18:43:48 +0800
Subject: [PATCH] feat: support standard api key authentication for Kling API
---
video-claw/video-claw/backend/models/video_kling.py | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/video-claw/video-claw/backend/models/video_kling.py b/video-claw/video-claw/backend/models/video_kling.py
index a58cc2b..7eb4805 100644
--- a/video-claw/video-claw/backend/models/video_kling.py
+++ b/video-claw/video-claw/backend/models/video_kling.py
@@ -109,31 +109,30 @@
return "std"
return mode if mode in {"std", "pro"} else "pro"
- # ─── JWT 鉴权 ───
+ # ─── 鉴权 ───
def _generate_token(self) -> str:
"""
- 使用 Access Key / Secret Key 生成 JWT Token
- 算法: HS256
- Payload:
- - iss: Access Key
- - iat: 签发时间
- - exp: 过期时间
- - nbf: 生效时间
+ 使用 Access Key / Secret Key 生成 JWT Token (老版本鉴权方式)
"""
now = int(time.time())
payload = {
"iss": self.access_key,
"iat": now,
"exp": now + self.token_ttl,
- "nbf": now - 5, # 允许 5 秒时钟偏差
+ "nbf": now - 5,
}
token = jwt.encode(payload, self.secret_key, algorithm="HS256")
return token
def _auth_headers(self) -> dict:
- """构建带 JWT 鉴权的请求头"""
- token = self._generate_token()
+ """构建带鉴权的请求头 (优先使用新版 API Key,向下兼容老版 JWT)"""
+ # 如果没有配置 secret_key,说明提供的是新版的 API_KEY(直接填在 access_key 字段里)
+ if not self.secret_key:
+ token = self.access_key
+ else:
+ token = self._generate_token()
+
return {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}",
--
Gitblit v1.8.0