TsgcHTTPServer › 属性 › Authentication

Authentication 属性

启用并配置对传入 HTTP 连接的用户名/密码身份验证。

语法

property Authentication: TsgcWSAuthenticationServer_Options read FAuthentication write SetAuthentication;

默认值

Enabled=False

备注

当 Authentication.Enabled 为 True 时,服务器会使用 Basic 方案(HTTP 基本访问身份验证)根据 AuthUsers 列表(格式为每行 user=password)对每个传入连接进行身份验证。TsgcWebSocketHTTPServer 上记录的 Session 和 URL 方案将凭据附加到 WebSocket 握手上,由于该组件从不升级连接,因此对 TsgcHTTPServer 没有任何效果。OnAuthentication 事件允许您插入自定义凭据检查;OnUnknownAuthentication 处理非标准方案,例如 Bearer/JWT/OAuth2/WebAuthn。使用 CustomHeaders 可添加在身份验证错误时返回的额外 HTTP 标头。

示例


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

返回属性