TsgcWSPClient_MQTT › 属性 › Authentication
在 MQTT CONNECT 数据包中发送用户名和密码,以针对代理验证客户端身份。
property Authentication: TsgcWSMQTTAuthentication_Options read FAuthentication write SetAuthentication;
Enabled=False
默认情况下身份验证处于禁用状态。将 Authentication.Enabled 设为 True,并分配 UserName 和 Password,即可在发送给代理的 CONNECT 数据包中包含 MQTT 用户名和密码字段。凭据在 MQTT 层携带,与底层 WebSocket 传输无关:当 Active 设为 True 时,客户端通过附加的 Client(或通过 Broker 的原始 TCP)打开 WebSocket,然后使用提供的凭据发送 MQTT CONNECT。对于 MQTT 5.0 扩展身份验证(质询/响应),请结合 ConnectProperties 的 AuthenticationMethod 字段与 Auth 方法使用。
MQTT := TsgcWSPClient_MQTT.Create(nil);
MQTT.Client := WSClient;
MQTT.Authentication.Enabled := True;
MQTT.Authentication.UserName := 'your user';
MQTT.Authentication.Password := 'your password';
WSClient.Active := True;