eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 883 forks source link

MQTTv5: Auth Packet #417

Closed jpwsutton closed 6 years ago

jpwsutton commented 7 years ago

The Auth packet is a new packet in MQTTv5 and will require a mechanism for it to be sent by the client. Fortunately it does not have a payload and simply has Variable properties. Some investigation will need to be done to see how best to fit it into the flow.

Properties to implement:

jpwsutton commented 6 years ago

Next Step here is to expose API methods that allow the developer to send AUTH packets, as well as a callback when they are recieved.

jpwsutton commented 6 years ago

Adding to MqttAsyncClient:

 /**
 * An AUTH Packet is sent from Client to Server or Server to Client as part of
 * an extended authentication exchange, such as challenge / response
 * authentication. It is a protocol error for the Client or Server to send an
 * AUTH packet if the CONNECT packet did not contain the same Authentication
 * Method.
 * 
 * @param reasonCode
 *            The Reason code, can be Success (0), Continue authentication (24)
 *            or Re-authenticate (25).
 * @param userContext
 *            optional object used to pass context to the callback. Use null if
 *            not required.
 * @param properties
 *            The {@link MqttProperties} to be sent, containing the
 *            Authentication Method, Authentication Data and any required User
 *            Defined Properties.
 * @return token used to track and wait for the authentication to complete. 
 * @throws MqttException
 */
IMqttToken authenticate(int reasonCode, Object userContext, MqttProperties properties) throws MqttException;

And the callback in MqttCallback:

/**
 * Called when an AUTH packet is received by the client.
 * 
 * @param reasonCode
 *            The Reason code, can be Success (0), Continue authentication (24)
 *            or Re-authenticate (25).
 * @param properties
 *            The {@link MqttProperties} to be sent, containing the
 *            Authentication Method, Authentication Data and any required User
 *            Defined Properties.
 */
public void authMessageArrived(int reasonCode, MqttProperties properties);