TsgcWSPClient_MQTT › 이벤트 › OnMQTTAuth
브로커가 AUTH 패킷을 보낼 때 MQTT 5 향상된 인증 교환 중에 발생합니다.
property OnMQTTAuth: TsgcWSMQTTAuthEvent;
// TsgcWSMQTTAuthEvent = procedure(Connection: TsgcWSConnection; ReasonCode: Integer; const ReasonName: String; AuthProperties: TsgcWSMQTTAUTHProperties) of object
—
강화된(챌린지/응답) 인증 교환 중에 사용되는 MQTT 5 AUTH 패킷에 대한 핸들러입니다. 일반적인 플로는 다음과 같습니다. 클라이언트가 AuthenticationMethod와 AuthenticationData와 함께 CONNECT를 보내고, 브로커가 챌린지를 담은 AUTH(ReasonCode = Continue authentication)로 응답하고, 클라이언트가 또 다른 AUTH로 답하고, 마지막으로 브로커가 CONNACK를 보냅니다. 핸들러는 Connection, 브로커 ReasonCode(정수) 및 사람이 읽을 수 있는 ReasonName과, AuthenticationMethod, AuthenticationData, ReasonString 및 UserProperties를 노출하는 AuthProperties를 받습니다. 이 이벤트를 사용하여 브로커 챌린지를 읽은 다음 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;