TsgcWebSocketServer_HTTPAPI属性 › Authentication

Authentication 属性

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

语法

property Authentication: TsgcWSAuthenticationServer_Options read FAuthentication write SetAuthentication;

默认值

Enabled=False

备注

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

示例


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

返回属性