From 94c901a233e14c9a32231ed245ba4ede334238c4 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 7 Dec 2025 00:03:24 +0800 Subject: [PATCH] =?UTF-8?q?ignore=5Fall=5Fempty=3F:=20boolean=20this.refre?= =?UTF-8?q?sh=5Ftoken=20=3D=20args.refresh=5Ftoken=20/**=20=20=20=20=20=20?= =?UTF-8?q?*=20=E8=BF=9B=E8=A1=8C=E8=BA=AB=E4=BB=BD=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E4=BB=A5=E6=8E=A5=E5=8F=97=E5=AE=A2=E6=88=B7=E7=AB=AF=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=20=20=20=20=20=20*=20=20=20=20=20=20*=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=AA=8C=E8=AF=81=E6=96=B9=E5=BC=8F=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7:=20=E8=AE=BF=E9=97=AE=20>=20=E5=88=B7=E6=96=B0=20>=20?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81=20=20=20=20=20=20*=20=20?= =?UTF-8?q?=20=20=20=20*=20=E8=8B=A5=E4=BC=A0=E9=80=92=E4=BA=86=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E5=AF=86=E7=A0=81,=20=E5=88=99=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=96=B0=E7=9A=84=E8=AE=BF=E9=97=AE=E4=BB=A4?= =?UTF-8?q?=E7=89=8C=E5=92=8C=E5=88=B7=E6=96=B0=E4=BB=A4=E7=89=8C=20=20=20?= =?UTF-8?q?=20=20=20*=20=20=20=20=20=20*=20=E5=A6=82=E5=8F=AA=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E4=B8=A4=E4=B8=AA=E4=BB=A4=E7=89=8C=E7=9A=84=E5=85=B6?= =?UTF-8?q?=E4=B8=80,=20=E6=8C=89=E7=85=A7=E4=BC=98=E5=85=88=E7=BA=A7?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=E6=88=90=E5=8A=9F=E9=AA=8C=E8=AF=81=E5=90=8E?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=20=20=20=20=20=20*=20=20=20=20=20=20*=20?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E9=AA=8C=E8=AF=81=E6=96=B9=E5=BC=8F=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E9=80=90=E4=B8=80=E5=B0=9D=E8=AF=95=20=20=20=20=20=20?= =?UTF-8?q?*/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client-protocol/LingChairClient.ts | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/client-protocol/LingChairClient.ts b/client-protocol/LingChairClient.ts index e9be490..543152a 100644 --- a/client-protocol/LingChairClient.ts +++ b/client-protocol/LingChairClient.ts @@ -131,33 +131,37 @@ export default class LingChairClient { } } /** - * 客户端上线 + * 进行身份验证以接受客户端事件 * * 使用验证方式优先级: 访问 > 刷新 > 账号密码 * - * 不会逐一尝试 + * 若传递了账号密码, 则同时缓存新的访问令牌和刷新令牌 + * + * 如只传递两个令牌的其一, 按照优先级并在成功验证后赋值 + * + * 多个验证方式不会逐一尝试 */ async authOrThrow(args: { - refresh_token?: string, - access_token?: string, - account?: string, - password?: string, + refresh_token?: string + access_token?: string + account?: string + password?: string + ignore_all_empty?: boolean }) { - if ((!args.access_token && !args.refresh_token) && (!args.account && !args.password)) - throw new Error('Access/Refresh token or account & password required') + if ((!args.access_token && !args.refresh_token) && (!args.account && !args.password) && !args.ignore_all_empty) + throw new Error('Access/Refresh token or account & password required, or ignore_all_empty=true') this.auth_cache = args - this.refresh_token = args.refresh_token - let access_token = args.access_token if (!access_token && args.refresh_token) { const re = await this.invoke('User.refreshAccessToken', { refresh_token: args.refresh_token, }) - if (re.code == 200) + if (re.code == 200) { access_token = re.data!.access_token as string | undefined - else + this.refresh_token = args.refresh_token + } else throw new CallbackError(re) } @@ -166,9 +170,10 @@ export default class LingChairClient { account: args.account, password: crypto.createHash('sha256').update(args.password).digest('hex'), }) - if (re.code == 200) + if (re.code == 200) { access_token = re.data!.access_token as string | undefined - else + this.refresh_token = re.data!.refresh_token as string + } else throw new CallbackError(re) }