TsgcWebSocketServer_HTTPAPI › 事件 › 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 以接受连接,或设置为 False 以拒绝。如果未在此处验证凭据,则使用内置的 AuthUsers 列表作为回退。
procedure OnAuthentication(Connection: TsgcWSConnection; aUser, aPassword: string;
var Authenticated: Boolean);
begin
if ((aUser = 'user') and (aPassword = 'secret')) then
Authenticated := True
else
Authenticated := False;
end;