重构: 源码文件蛇形命名, 接口去I头(BindRequestContext/SimApiAuthChecker), 清理C#相关说明, serialization依赖路径改 serialization-cj
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
* 遵循 MIT 许可证。
|
||||
* AuthSDK/SimApiAuthCenter:认证中心远程 SDK。
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,7 @@ import simcu::simapi.communications.*
|
||||
import simcu::simapi.helpers.*
|
||||
|
||||
/**
|
||||
* 认证中心远程 SDK(对齐 C# SimApiAuthCenter):
|
||||
* 认证中心远程 SDK:
|
||||
* 群组 / Profile / 内部应用 / 系统登录 / 安全验证 等接口,走签名请求。
|
||||
*/
|
||||
public class SimApiAuthCenter {
|
||||
@@ -35,7 +35,7 @@ public class SimApiAuthCenter {
|
||||
// ===== 公共 =====
|
||||
|
||||
/**
|
||||
* 委托 AuthCenter 进行应用签名验证(对齐 C# VerifySign)。
|
||||
* 委托 AuthCenter 进行应用签名验证。
|
||||
*/
|
||||
public func verifySign(appId: String, timestamp: String, nonce: String, sign: String): Unit {
|
||||
let url = "${_client.server}/api/auth/sign/verify?appId=${appId}×tamp=${timestamp}&nonce=${nonce}&sign=${sign}"
|
||||
@@ -55,7 +55,7 @@ public class SimApiAuthCenter {
|
||||
SimApiError.errorWhenFalse(isSuccess(response.status), code: Int64(response.status),
|
||||
message: "HTTP ERROR: ${response.status}")
|
||||
let json = readBodyText(response.body)
|
||||
let resp = JsonSerializer.Deserialize<SimApiBaseResponse>(json)
|
||||
let resp = JsonSerializer.deserialize<SimApiBaseResponse>(json)
|
||||
SimApiError.errorWhen(resp.code != 200, code: 400, message: "签名验证失败")
|
||||
} finally {
|
||||
response.close()
|
||||
@@ -104,7 +104,7 @@ public class SimApiAuthCenter {
|
||||
// ===== 群组相关 =====
|
||||
|
||||
/**
|
||||
* 根据 profileId 获取群组列表(对齐 C# GroupRelated)。
|
||||
* 根据 profileId 获取群组列表。
|
||||
*/
|
||||
public func groupRelated(profileId: String): Array<GroupRelatedItem> {
|
||||
_client.signQuery<Array<GroupRelatedItem>>("/api/auth/group/related",
|
||||
@@ -112,7 +112,7 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 按关键字搜索群组,输入群组 ID 精准搜索(对齐 C# GroupSearch)。
|
||||
* 按关键字搜索群组,输入群组 ID 精准搜索。
|
||||
*/
|
||||
public func groupSearch(keyword: String, skip!: Int64 = 0, take!: Int64 = 20): Array<AppAndProfileItem> {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -123,7 +123,7 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用组 ID 以及组内成员/管理员 profile 获取组的详细树结构(对齐 C# GroupDetail)。
|
||||
* 使用组 ID 以及组内成员/管理员 profile 获取组的详细树结构。
|
||||
*/
|
||||
public func groupDetail(groupId: String, profileId: String): GroupDetailTreeNode {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -133,7 +133,7 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 profile 在本组的所有子组(对齐 C# GroupRelatedIndex)。
|
||||
* 获取 profile 在本组的所有子组。
|
||||
*/
|
||||
public func groupRelatedIndex(groupId: String, profileId: String): Array<String> {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -146,7 +146,7 @@ public class SimApiAuthCenter {
|
||||
// ===== Profile 相关 =====
|
||||
|
||||
/**
|
||||
* 按关键字搜索用户 Profile(对齐 C# ProfileSearch)。
|
||||
* 按关键字搜索用户 Profile。
|
||||
*/
|
||||
public func profileSearch(keyword: String, skip!: Int64 = 0, take!: Int64 = 20): Array<AppAndProfileItem> {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -157,7 +157,7 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 id 批量获取用户基本信息(对齐 C# ProfileList)。
|
||||
* 通过 id 批量获取用户基本信息。
|
||||
*/
|
||||
public func profileList(ids: Array<String>): Array<AppAndProfileItem> {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -172,7 +172,7 @@ public class SimApiAuthCenter {
|
||||
// ===== AuthGate 内部应用专用 =====
|
||||
|
||||
/**
|
||||
* 获取是否为 App 的拥有者(对齐 C# CheckIsAppOwner,字段为 PascalCase)。
|
||||
* 获取是否为 App 的拥有者。
|
||||
*/
|
||||
public func checkIsAppOwner(profileId: String, applicationId: String): Bool {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -182,7 +182,7 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户 profileId 和提供的 appIds 获取应用列表(对齐 C# GetAppList,字段为 PascalCase)。
|
||||
* 根据用户 profileId 和提供的 appIds 获取应用列表。
|
||||
*/
|
||||
public func getAppList(profileId: String, appIds: Array<String>): Array<AppAndProfileItem> {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -199,7 +199,7 @@ public class SimApiAuthCenter {
|
||||
// ===== 系统登录 =====
|
||||
|
||||
/**
|
||||
* 获取登录授权 CODE(对齐 C# GetLoginCode)。
|
||||
* 获取登录授权 CODE。
|
||||
* @param scene 场景标识。
|
||||
* @param data 附加数据。
|
||||
* @param backUrl 回调地址。
|
||||
@@ -217,12 +217,12 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 code 获取登录信息(对齐 C# GetLoginInfo,场景不匹配抛 403003)。
|
||||
* 使用 code 获取登录信息。
|
||||
*/
|
||||
public func getLoginInfo(code: String, scene!: ?String = None): LoginInfoResponse {
|
||||
var body = HashMap<String, Any>()
|
||||
body["code"] = code
|
||||
// 说明:C# 的 ErrorWhenNull(resp, 400232, "登录信息获取失败") 对应 signQuery 内部 data.getOrThrow() 的
|
||||
// 说明:ErrorWhenNull(resp, 400232, "登录信息获取失败") 对应 signQuery 内部 data.getOrThrow() 的
|
||||
// None 分支;仓颉版 signQuery 返回非空 T(data 缺失即抛异常),故此处无需重复判空。
|
||||
let resp = _client.signQuery<LoginInfoResponse>("/api/auth/login/get", body: SimApiUtil.json(Some(body)))
|
||||
SimApiError.errorWhen(resp.scene != scene, code: 403003, message: "登录场景不匹配")
|
||||
@@ -232,7 +232,7 @@ public class SimApiAuthCenter {
|
||||
// ===== 安全验证 =====
|
||||
|
||||
/**
|
||||
* 获取安全验证代码(对齐 C# GetConfirmCode)。
|
||||
* 获取安全验证代码。
|
||||
*/
|
||||
public func getConfirmCode(scene: String, userId: String, data!: ?HashMap<String, Any> = None,
|
||||
backUrl!: ?String = None): GetCodeResponse {
|
||||
@@ -247,7 +247,7 @@ public class SimApiAuthCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用安全验证 code 获取验证结果(对齐 C# Confirm,身份/场景不匹配分别抛 403002/403003)。
|
||||
* 使用安全验证 code 获取验证结果。
|
||||
*/
|
||||
public func confirm(code: String, scene: String, userId!: ?String = None): ConfirmResponse {
|
||||
var body = HashMap<String, Any>()
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
* 遵循 MIT 许可证。
|
||||
* AuthSDK/SimApiAuthCenterMiddleware:网关透传认证中间件。
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ import simcu::simapi.configurations.*
|
||||
import simcu::simapi.helpers.*
|
||||
|
||||
/**
|
||||
* 网关透传认证中间件(对齐 C# SimApiAuthCenterMiddleware):
|
||||
* 网关透传认证中间件:
|
||||
* 当请求带 X-SimApi-Gate-Auth / X-SimApi-Gate-Time / X-SimApi-Gate-Sign 三头时,
|
||||
* 校验 MD5 签名(appId=..&auth=..&time=..&appKey=..),通过则 Base64 解码登录信息写入 LoginInfo。
|
||||
*/
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
* 遵循 MIT 许可证。
|
||||
* AuthSDK/SimApiAuthClient:认证中心专用签名客户端。
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ import simcu::simapi.configurations.*
|
||||
import simcu::simapi.helpers.*
|
||||
|
||||
/**
|
||||
* 认证中心签名客户端(对齐 C# SimApiAuthClient):
|
||||
* 认证中心签名客户端:
|
||||
* SimApiHttpClient 子类,凭证(Server/AppId/AppKey)取自 SimApiAuthCenterOptions。
|
||||
*/
|
||||
public class SimApiAuthClient <: SimApiHttpClient {
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
* AuthSDK 用到的 DTO(对齐 C# SimApiAuthCenterDto / SimApiAuthIamDto)。
|
||||
* 遵循 MIT 许可证。
|
||||
* AuthSDK 用到的 DTO。
|
||||
*
|
||||
* 说明:C# 中这些 DTO 是 SimApiAuthCenterDto / SimApiAuthIamDto 的嵌套类;
|
||||
* 说明:原版中这些 DTO 是 SimApiAuthCenterDto / SimApiAuthIamDto 的嵌套类;
|
||||
* 仓颉不支持在类体内声明嵌套类(unexpected class declaration in class body),
|
||||
* 故拍平为顶层类,语义与字段保持一致。
|
||||
*
|
||||
@@ -15,7 +15,7 @@ package simcu::simapi.authsdk
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* 应用/Profile 通用项(对齐 C# AppAndProfileItem)。
|
||||
* 应用/Profile 通用项。
|
||||
*/
|
||||
public class AppAndProfileItem {
|
||||
public var id: String = ""
|
||||
@@ -25,8 +25,8 @@ public class AppAndProfileItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全确认响应(对齐 C# ConfirmResponse)。
|
||||
* data 用 ?HashMap<String, Any> 对齐 C# Dictionary<string,object>?(任意 JSON 对象)。
|
||||
* 安全确认响应。
|
||||
* data 用 ?HashMap<String, Any> 表示任意 JSON 对象。
|
||||
*/
|
||||
public class ConfirmResponse {
|
||||
public var applicationId: String = ""
|
||||
@@ -36,7 +36,7 @@ public class ConfirmResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录信息响应(对齐 C# LoginInfoResponse)。
|
||||
* 登录信息响应。
|
||||
*/
|
||||
public class LoginInfoResponse {
|
||||
public var scene: ?String = None
|
||||
@@ -48,7 +48,7 @@ public class LoginInfoResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权码响应(对齐 C# GetCodeResponse)。
|
||||
* 获取授权码响应。
|
||||
*/
|
||||
public class GetCodeResponse {
|
||||
public var code: String = ""
|
||||
@@ -65,7 +65,7 @@ public class GetCodeResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* 群组关联项(对齐 C# GroupRelatedItem)。
|
||||
* 群组关联项。
|
||||
*/
|
||||
public class GroupRelatedItem {
|
||||
public var id: String = ""
|
||||
@@ -78,7 +78,7 @@ public class GroupRelatedItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* 群组详情树节点(对齐 C# GroupDetailTreeNode,children 递归)。
|
||||
* 群组详情树节点。
|
||||
*/
|
||||
public class GroupDetailTreeNode {
|
||||
public var id: String = ""
|
||||
@@ -90,7 +90,7 @@ public class GroupDetailTreeNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限项(对齐 C# PermissionItem)。
|
||||
* 权限项。
|
||||
*/
|
||||
public class PermissionItem {
|
||||
public var identifier: String = ""
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
* 遵循 MIT 许可证。
|
||||
* AuthSDK/SimApiAuthIam:权限中心远程 SDK。
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ import simcu::simapi.communications.*
|
||||
import simcu::simapi.helpers.*
|
||||
|
||||
/**
|
||||
* 权限中心远程 SDK(对齐 C# SimApiAuthIam):
|
||||
* 权限中心远程 SDK:
|
||||
* 注册权限点 / 获取权限标识 / 校验权限。
|
||||
*/
|
||||
public class SimApiAuthIam {
|
||||
@@ -22,7 +22,7 @@ public class SimApiAuthIam {
|
||||
}
|
||||
|
||||
/**
|
||||
* 向 IAM 注册权限(对齐 C# RegisterPermissions)。
|
||||
* 向 IAM 注册权限。
|
||||
*/
|
||||
public func registerPermissions(permissions: Array<PermissionItem>): Unit {
|
||||
// 请求体:{"permissions":[{"identifier":...,"name":...,"group":...,"description":...},...]}
|
||||
@@ -41,7 +41,7 @@ public class SimApiAuthIam {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拥有的权限标识数组(对齐 C# GetPermissionOwned)。
|
||||
* 获取拥有的权限标识数组。
|
||||
*/
|
||||
public func getPermissionOwned(profileId: String, groupId!: ?String = None): Array<String> {
|
||||
var body = HashMap<String, Any>()
|
||||
@@ -53,7 +53,7 @@ public class SimApiAuthIam {
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测 profileId 是否有该权限,无权限抛 403(对齐 C# CheckPermission)。
|
||||
* 检测 profileId 是否有该权限,无权限抛 403。
|
||||
*/
|
||||
public func checkPermission(profileId: String, permission: String, groupId!: ?String = None): Unit {
|
||||
var body = HashMap<String, Any>()
|
||||
Reference in New Issue
Block a user