Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paho client doesn't support custom headers for MQTT connection over WebSockets #502

Open
3 tasks
vit21ik opened this issue Mar 22, 2018 · 10 comments
Open
3 tasks

Comments

@vit21ik
Copy link
Contributor

vit21ik commented Mar 22, 2018

When you need connection to MQTT broker using WebSockets, paho client sets default headers:

pw.print("Upgrade: websocket" + LINE_SEPARATOR);
pw.print("Connection: Upgrade" + LINE_SEPARATOR);
pw.print("Sec-WebSocket-Key: " + key + LINE_SEPARATOR);
pw.print("Sec-WebSocket-Protocol: mqtt" + LINE_SEPARATOR);
pw.print("Sec-WebSocket-Version: 13" + LINE_SEPARATOR);

In some cases required send custom headers, for example if you wanted to connect to AWS Iot broker.
https://docs.aws.amazon.com/iot/latest/developerguide/custom-auth.html

It would be great add custom headers support to WebSocket handshake request.

  • Bug exists Release Version 1.2.0 ( Master Branch)
  • Bug exists in Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
  • Bug exists in MQTTv5 Version (mqttv5-new Branch)

If this is a bug regarding the Android Service, please raise the bug here instead: https://github.com/eclipse/paho.mqtt.android/issues/new

@vit21ik
Copy link
Contributor Author

vit21ik commented Mar 22, 2018

Actually I did this changes in my forked repository - vit21ik@7df2eaa

I could create merge request to develop branch.

@jpwsutton
Copy link
Member

Thanks for the pull request, once we merge it would you mind if I ported your changes over to our new MQTTv5 client?

@davidgraeff
Copy link

Eclipse Smarthome would use this as well. A near term release including this could help our current mqtt ambitions.

davidgraeff pushed a commit to davidgraeff/paho.mqtt.java that referenced this issue Apr 12, 2018
Fixes eclipse#502

Signed-off-by: David Graeff <david.graeff@web.de>
Also-by: Vitalii <vitalii.vlasiuk@temy.co>
Signed-off-by: David Graeff <david.graeff@web.de>
davidgraeff pushed a commit to davidgraeff/paho.mqtt.java that referenced this issue Apr 12, 2018
Fixes eclipse#502

Signed-off-by: David Graeff <david.graeff@web.de>
Also-by: Vitalii <vitalii.vlasiuk@temy.co>
Signed-off-by: David Graeff <david.graeff@web.de>
davidgraeff pushed a commit to davidgraeff/paho.mqtt.java that referenced this issue Apr 12, 2018
Fixes eclipse#502

Also-by: Vitalii <vitalii.vlasiuk@temy.co>
Signed-off-by: David Graeff <david.graeff@web.de>
@vit21ik
Copy link
Contributor Author

vit21ik commented Apr 30, 2018

Added custom headers to mqtt v5

@davidgraeff
Copy link

Can be closed, can't it?

@desokroshan
Copy link
Contributor

desokroshan commented Jan 3, 2019

@jpwsutton Is there a way to consume these changes via gradle?

@aniket91
Copy link

aniket91 commented Feb 8, 2019

How do I use this feature? I used the latest dependency in maven-


org.eclipse.paho
org.eclipse.paho.client.mqttv3
1.2.0

But I do not see an option to set custom headers.

@desokroshan
Copy link
Contributor

You can build the jar file from the develop branch as mentioned here and add it to your classpath. These changes will be available as part of 1.3.0 which is overdue.

@JacquesSmuts
Copy link

It is now available in version 1.2.1 and you implement it like so:

MqttClient client = new MqttClient("wss://<BROKER_URI>", "MyClient");
MqttConnectOptions connectOptions = new MqttConnectOptions();
Properties properties = new Properties();
properties.setProperty("X-Amz-CustomAuthorizer-Name", <SOME_VALUE>);
properties.setProperty("X-Amz-CustomAuthorizer-Signature", <SOME_VALUE>);
properties.setProperty(<SOME_VALUE>, <SOME_VALUE>);
connectOptions.setCustomWebSocketHeaders(properties);
client.connect(connectOptions);

@rrmorey
Copy link

rrmorey commented Nov 8, 2019

It is now available in version 1.2.1 and you implement it like so:

MqttClient client = new MqttClient("wss://<BROKER_URI>", "MyClient");
MqttConnectOptions connectOptions = new MqttConnectOptions();
Properties properties = new Properties();
properties.setProperty("X-Amz-CustomAuthorizer-Name", <SOME_VALUE>);
properties.setProperty("X-Amz-CustomAuthorizer-Signature", <SOME_VALUE>);
properties.setProperty(<SOME_VALUE>, <SOME_VALUE>);
connectOptions.setCustomWebSocketHeaders(properties);
client.connect(connectOptions);

How can we retrieve the headers on the subscriber side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants