Files
simapi-cj/src/authsdk/SimApiAuthCenterMiddleware.cj
T
xrain f056de582b feat: AuthSDK 认证中心完整实现(对齐 C# AuthSDK)
- SimApiAuthClient:SimApiHttpClient 子类,凭证取 AuthCenterOptions
- SimApiAuthCenter:群组/Profile/内部应用/系统登录/安全验证 12 接口 + VerifySign
- SimApiAuthIam:注册权限/获取权限/校验权限(无权限 403)
- SimApiAuthCenterMiddleware:网关透传(三头 MD5 校验 + Base64 解码 LoginInfo)
- SimApiAuthDto:7 个 DTO(data 字段用 JsonValue 规避宏约束)
2026-08-16 22:46:48 +08:00

46 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 移植自 C# 项目 SimApiE:\simcu\simapi-net),遵循 MIT 许可证。
* AuthSDK/SimApiAuthCenterMiddleware:网关透传认证中间件。
*/
package simapi.authsdk
import soulsoft_web_http.*
import simapi.communications.*
import simapi.configurations.*
import simapi.helpers.*
/**
* 网关透传认证中间件(对齐 C# SimApiAuthCenterMiddleware):
* 当请求带 X-SimApi-Gate-Auth / X-SimApi-Gate-Time / X-SimApi-Gate-Sign 三头时,
* 校验 MD5 签名(appId=..&auth=..&time=..&appKey=..),通过则 Base64 解码登录信息写入 LoginInfo。
*/
public class SimApiAuthCenterMiddleware <: IMiddleware {
private let _options: SimApiOptions
public init(options: SimApiOptions) {
this._options = options
}
public func invoke(context: HttpContext, next: RequestDelegate): Unit {
let auth = context.request.headers.get("X-SimApi-Gate-Auth")
let time = context.request.headers.get("X-SimApi-Gate-Time")
let sign = context.request.headers.get("X-SimApi-Gate-Sign")
if (auth != None && time != None && sign != None) {
let authValue = auth.getOrThrow()
let timeValue = time.getOrThrow()
let signValue = sign.getOrThrow()
if (!authValue.isEmpty()) {
let authOptions = _options.simApiAuthCenterOptions
let signStr = "appId=${authOptions.appId}&auth=${authValue}&time=${timeValue}&appKey=${authOptions.appKey}"
if (SimApiUtil.md5(signStr) == signValue) {
let login = SimApiUtil.base64DecodeTo<SimApiLoginItem>(authValue)
context.items["LoginInfo"] = login
}
}
}
next(context)
}
}