Skip to content

Instantly share code, notes, and snippets.

@ridomin
Last active April 5, 2022 02:45
Show Gist options
  • Save ridomin/63942b7e7e18f15dd0010d0f565e51cb to your computer and use it in GitHub Desktop.
Save ridomin/63942b7e7e18f15dd0010d0f565e51cb to your computer and use it in GitHub Desktop.
WithAzureSasCredentials.cs
public static MqttClientOptionsBuilder WithAzureIoTHubCredentialsSas(this MqttClientOptionsBuilder builder, string hostName, string deviceId, string sasKey, string modelId, int sasMinutes = 60)
{
(string username, string password) = SasAuth.GenerateHubSasCredentials(hostName, deviceId, sasKey, modelId, sasMinutes);
builder
.WithTcpServer(hostName, 8883)
.WithTls()
.WithClientId($"{deviceId}")
.WithCredentials(username, password);
return builder;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment