TsgcWebSocketProxyServer › 事件 › OnAuthentication
启用认证时触发,应用程序可在此检查用户名和密码,并决定接受或拒绝下游客户端连接。
property OnAuthentication: TsgcWSAuthenticationEvent;
// TsgcWSAuthenticationEvent = procedure(Connection: TsgcWSConnection; aUser, aPassword: String; var Authenticated: Boolean) of object
—
每当代理服务器收到来自下游客户端的身份验证请求时,若 Authentication.Enabled 为 True 且身份验证方式为内置方案之一(Basic、Session、URL),则触发 OnAuthentication 事件。aUser 和 aPassword 参数携带客户端提供的凭据;将 Authenticated 设为 True 表示接受连接(代理将代表客户端建立上游 TCP 会话),设为 False 则拒绝连接。若此处未通过验证,则回退使用内置的 AuthUsers 列表。对于组件未识别的自定义方案(例如 JWT Bearer 令牌),请改用 OnUnknownAuthentication。
procedure OnAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string;
var Authenticated: Boolean);
begin
if ((aUser = 'user') and (aPassword = 'secret')) then
Authenticated := True
else
Authenticated := False;
end;