Skip to content

Support WebSocket connection to IoT Hub via an Application Gateway. #3485

@BillArmstrong

Description

@BillArmstrong

Our company has a requirement preventing us from exposing the IoT Hub to the internet. The solution that we're trying to investigate is communicating to the IoT Hub via an Application Gateway.

We discovered that this can and does appear to work, but it requires a slight modification to the device client. Also admittedly it would require more extensive testing to confirm that it works reliably over an extended period of time.

The MqttIotHubAdapter class contains the following line of code:

string usernameString = $"{_iotHubHostName}/{id}/?{ClientApiVersionHelper.ApiVersionQueryStringLatest}&{DeviceClientTypeParam}={Uri.EscapeDataString(_productInfo.ToString())}";

If I configure the Device Client connection string using the App Gateway's address, but modify the line of code above such that _iotHubHostName contains the actual IoT Hub's hostname, everything seems to work. The device connects to the App Gateway, which forwards the requests to the IoT Hub on the private VPN, and the connection is authenticated properly because the usernameString contains the correct IoT Hub hostname.

We would prefer not to use a custom build of the client library. If I were to provide a pull request to add an ApplicationGateway parameter to the connection string so that we can provide both the App Gateway hostname and the IoT Hub hostname, would this PR be accepted?

I saw that the connection string supports a GatewayHostName parameter, but I guess that is meant to work with IoT Edge. I tried using it, but it didn't work. The usernameString was still configured with the wrong IoT Hub name.

I'm open to any suggestions for configuring the connection string. Another option would be to use the existing GatewayHostName parameter, but add an addition parameter for the type of gateway (e.g. Edge vs Application), with Edge being the default of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions