Add multi-session auth and changelog tracking
这个提交包含在:
@@ -21,7 +21,8 @@ const isNonEmptyString = (value: unknown): value is string =>
|
||||
export type SessionPayload = {
|
||||
openId: string;
|
||||
appId: string;
|
||||
name: string;
|
||||
name?: string;
|
||||
sid?: string;
|
||||
};
|
||||
|
||||
const EXCHANGE_TOKEN_PATH = `/webdev.v1.WebDevAuthPublicService/ExchangeToken`;
|
||||
@@ -173,6 +174,7 @@ class SDKServer {
|
||||
openId,
|
||||
appId: ENV.appId,
|
||||
name: options.name || "",
|
||||
sid: crypto.randomUUID(),
|
||||
},
|
||||
options
|
||||
);
|
||||
@@ -190,7 +192,8 @@ class SDKServer {
|
||||
return new SignJWT({
|
||||
openId: payload.openId,
|
||||
appId: payload.appId,
|
||||
name: payload.name,
|
||||
name: payload.name || "",
|
||||
sid: payload.sid || crypto.randomUUID(),
|
||||
})
|
||||
.setProtectedHeader({ alg: "HS256", typ: "JWT" })
|
||||
.setExpirationTime(expirationSeconds)
|
||||
@@ -199,7 +202,7 @@ class SDKServer {
|
||||
|
||||
async verifySession(
|
||||
cookieValue: string | undefined | null
|
||||
): Promise<{ openId: string; appId: string; name: string } | null> {
|
||||
): Promise<{ openId: string; appId: string; name?: string; sid?: string } | null> {
|
||||
if (!cookieValue) {
|
||||
console.warn("[Auth] Missing session cookie");
|
||||
return null;
|
||||
@@ -210,12 +213,11 @@ class SDKServer {
|
||||
const { payload } = await jwtVerify(cookieValue, secretKey, {
|
||||
algorithms: ["HS256"],
|
||||
});
|
||||
const { openId, appId, name } = payload as Record<string, unknown>;
|
||||
const { openId, appId, name, sid } = payload as Record<string, unknown>;
|
||||
|
||||
if (
|
||||
!isNonEmptyString(openId) ||
|
||||
!isNonEmptyString(appId) ||
|
||||
!isNonEmptyString(name)
|
||||
!isNonEmptyString(appId)
|
||||
) {
|
||||
console.warn("[Auth] Session payload missing required fields");
|
||||
return null;
|
||||
@@ -224,7 +226,8 @@ class SDKServer {
|
||||
return {
|
||||
openId,
|
||||
appId,
|
||||
name,
|
||||
name: typeof name === "string" ? name : undefined,
|
||||
sid: typeof sid === "string" ? sid : undefined,
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn("[Auth] Session verification failed", String(error));
|
||||
|
||||
在新工单中引用
屏蔽一个用户