TsgcWSPServer_sgc › 事件 › 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 握手时提供的 User 和 Password;将 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;