TsgcWebSocketProxyServer › 属性 › Authentication
为连接到代理的传入 WebSocket 客户端启用并配置用户名/密码身份验证。
property Authentication: TsgcWSAuthenticationServer_Options read FAuthentication write SetAuthentication;
Enabled=False
当 Authentication.Enabled 为 True 时,代理在对 Proxy 中定义的上游服务器建立匹配链路之前,先根据 AuthUsers 列表(格式为每行 user=password)对每个传入的下游连接进行身份验证。支持三种内置方案:Session(客户端先发 HTTP GET,收到会话 id,然后将 id 作为参数打开 WebSocket)、URL(用户名和密码在 WebSocket 握手的查询字符串中发送)和 Basic(HTTP 基本访问认证)。OnAuthentication 事件允许您插入自定义凭证检查;OnUnknownAuthentication 处理 Bearer/JWT 等非标准方案。认证仅在下游端执行;代理不会自动将凭证转发给上游服务器。
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 或系统默认值。结果由 OnNegotiateAuthentication 报告。请参阅 Kerberos 和 Negotiate 身份验证。
oProxy := TsgcWebSocketProxyServer.Create(nil);
oProxy.Authentication.Enabled := true;
oProxy.Authentication.Basic.Enabled := true;
oProxy.Authentication.AuthUsers.Add('user=secret');
oProxy.Proxy.Host := 'upstream.example.com';
oProxy.Proxy.Port := 8080;
oProxy.Active := true;