TsgcWebSocketServer_HTTPAPI › 属性 › Authentication

Authentication 属性

为传入的 WebSocket 和 HTTP 请求启用并配置用户名/密码认证。

语法

property Authentication: TsgcWSAuthenticationServer_Options read FAuthentication write SetAuthentication;

默认值

Enabled=False

备注

当 Authentication.Enabled 为 True 时,服务器会根据 AuthUsers 列表(每行格式为 user=password)对每个传入连接进行身份验证。支持三种内置方案:Session(客户端先发送 HTTP GET,获取会话 ID,再将该 ID 作为参数建立 WebSocket 连接)、URL(用户名和密码通过 WebSocket 握手的查询字符串发送)以及 Basic(HTTP 基本访问认证,仅用于 VCL 客户端/服务器及 HTTP 请求)。OnAuthentication 事件允许插入自定义凭据验证逻辑;OnUnknownAuthentication 用于处理非标准方案(如 Bearer/JWT)。使用 CustomHeaders 可在身份验证失败时添加额外的 HTTP 响应头。

Negotiate(Kerberos / SPNEGO,在 Windows 上可回退到 NTLM)在 Authentication.Negotiate 子属性中配置,并且需要 sgcWebSockets Enterprise Edition。Negotiate.Enabled(Boolean,默认值为 False)用于启用该功能,并且需要 Authentication.Enabled。Negotiate.ServicePrincipal(String)是可选的 SPN,例如 HTTP/host.example.com@EXAMPLE.COM;为空时,接受 keytab 中的任意密钥或计算机帐户。Negotiate.Keytab(String,仅限 Linux)是服务 keytab 的路径;为空时使用 KRB5_KTNAME 或系统默认值。使用 http.sys 服务器时,身份验证由 Windows 内核模式身份验证(服务帐户或计算机 SPN)完成,因此会忽略 ServicePrincipal 和 Keytab。结果由 OnNegotiateAuthentication 报告。请参阅 Kerberos 和 Negotiate 身份验证。

示例


oServer := TsgcWebSocketServer_HTTPAPI.Create(nil);
oServer.Authentication.Enabled := true;
oServer.Authentication.Basic.Enabled := true;
oServer.Authentication.AuthUsers.Add('user=secret');
oServer.Active := true;

返回属性