TsgcWSPClient_MQTT事件 › OnMQTTAuth

OnMQTTAuth 事件

在 MQTT 5 增强认证交换过程中,当 broker 发送 AUTH 数据包时触发。

语法

property OnMQTTAuth: TsgcWSMQTTAuthEvent;
// TsgcWSMQTTAuthEvent = procedure(Connection: TsgcWSConnection; ReasonCode: Integer; const ReasonName: String; AuthProperties: TsgcWSMQTTAUTHProperties) of object

默认值

备注

用于 MQTT 5 AUTH 数据包的处理程序,在增强型(挑战/响应)身份验证交换期间使用。典型流程为:客户端发送带有 AuthenticationMethod 和 AuthenticationData 的 CONNECT,代理以 AUTH(ReasonCode = 继续身份验证)回复并携带其挑战,客户端以另一个 AUTH 作答,代理最终发送 CONNACK。处理程序接收 Connection、代理 ReasonCode(整数)和人类可读的 ReasonName,以及公开 AuthenticationMethodAuthenticationDataReasonStringUserPropertiesAuthProperties。使用此事件读取代理挑战,然后调用 Auth 方法发布交换的下一步。仅在 MQTTVersion 为 5.0 时可用。

示例

procedure TForm1.MQTTAuth(Connection: TsgcWSConnection;
  ReasonCode: Integer; const ReasonName: String;
  AuthProperties: TsgcWSMQTTAUTHProperties);
var
  vMethod, vData: String;
begin
  vMethod := AuthProperties.AuthenticationMethod;
  vData   := AuthProperties.AuthenticationData;
  Memo1.Lines.Add(Format('AUTH %d (%s) method=%s',
    [ReasonCode, ReasonName, vMethod]));

  // continue the exchange with the next client step
  if ReasonCode = 24 then // Continue authentication
    MQTT.Auth(False, vMethod, ComputeClientResponse(vData));
end;

返回事件