@koishi-ce/plugin-auth 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/index.d.ts +46 -44
- package/lib/index.mjs +155 -158
- package/package.json +2 -2
- package/src/__tests__/helpers.ts +272 -0
- package/src/__tests__/intercept.test.ts +102 -0
- package/src/__tests__/login.test.ts +237 -0
- package/src/__tests__/user-events.test.ts +189 -0
- package/src/__tests__/verification.test.ts +122 -0
- package/src/crypto.ts +77 -0
- package/src/index.ts +19 -374
- package/src/login.ts +243 -0
- package/src/types.ts +52 -0
- package/src/__tests__/index.test.ts +0 -797
package/src/types.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2019-present Shigma and Koishijs contributors.
|
|
3
|
+
// Copyright (c) 2026-present Koishi-CE contributors.
|
|
4
|
+
|
|
5
|
+
// upstream: koishijs/webui plugins/auth/src/index.ts L43-L64, L72-L77(类型段;上游为单文件 plugin-auth 4.1.7,本仓拆分时抽离至本文件,同步时以其整体 diff 对照本目录)
|
|
6
|
+
|
|
7
|
+
import type { Binding, User } from "@koishi-ce/koishi";
|
|
8
|
+
|
|
9
|
+
/** token 表记录:一次登录会话的令牌及其来源信息。 */
|
|
10
|
+
export interface LoginToken {
|
|
11
|
+
/** 自增主键(删除指定会话用) */
|
|
12
|
+
inc: number;
|
|
13
|
+
/** 所属用户 id */
|
|
14
|
+
id: number;
|
|
15
|
+
/** 登录方式 */
|
|
16
|
+
type: LoginType;
|
|
17
|
+
/** 随机令牌(唯一索引) */
|
|
18
|
+
token: string;
|
|
19
|
+
/** 过期时间戳(毫秒) */
|
|
20
|
+
expiredAt: number;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
lastUsedAt: Date;
|
|
23
|
+
/** 登录时的 User-Agent */
|
|
24
|
+
userAgent: string;
|
|
25
|
+
/** 登录时的来源 IP */
|
|
26
|
+
address: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 下发到客户端的登录态(user 数据服务的单条形态,不含 tokens/bindings 明细)。 */
|
|
30
|
+
export type Auth = Pick<LoginToken, "token" | "expiredAt"> &
|
|
31
|
+
Pick<User, "id" | "name" | "authority" | "config">;
|
|
32
|
+
|
|
33
|
+
/** user 数据服务下发给客户端的完整鉴权数据:登录态 + 会话列表 + 绑定列表。 */
|
|
34
|
+
export interface AuthData extends Auth {
|
|
35
|
+
tokens: Omit<LoginToken, "token" | "id">[];
|
|
36
|
+
bindings: Omit<Binding, "aid">[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 登录方式:平台验证码 / 用户密码 / 已存令牌续期。 */
|
|
40
|
+
export type LoginType = "platform" | "password" | "token";
|
|
41
|
+
|
|
42
|
+
/** login/platform 事件的返回值:待登录用户信息 + 一次性验证码及其过期时间。 */
|
|
43
|
+
export interface UserLogin
|
|
44
|
+
extends Pick<User, "id" | "name"> {
|
|
45
|
+
token: string;
|
|
46
|
+
expiredAt: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** user/update 事件允许修改的用户字段。 */
|
|
50
|
+
export type UserUpdate = Partial<
|
|
51
|
+
Pick<User, "name" | "password" | "config">
|
|
52
|
+
>;
|