TsgcWSPServer_sgc事件 › OnRPCAuthentication

OnRPCAuthentication 事件

当 RPC 方法不在允许列表中时触发,让处理程序对其进行授权。

语法

property OnRPCAuthentication: TsgcWSRPCAuthenticationEvent;
// TsgcWSRPCAuthenticationEvent = procedure(Connection: TsgcWSConnection; const Method, User, Password: string; var Authenticated: Boolean) of object

默认值

备注

仅当 RPCAuthentication.Enabled 为 True 且方法名称未以裸名或 method=user 形式出现在 RPCAuthentication.Methods 中时触发。处理程序接收所请求的 Method,以及在 WebSocket 握手时提供的 UserPassword;将 Authenticated 设置为 True 以分发 OnRPC,或保持为 False 以让服务器返回 JSON-RPC 的"方法未找到"错误。

示例

procedure TForm1.oProtocolRPCAuthentication(Connection: TsgcWSConnection;
  const Method, User, Password: string; var Authenticated: Boolean);
begin
  Authenticated := (User = 'admin') and (Password = 'secret');
end;

返回事件