Create SAS Token from within an IoT Edge module

Description

IoT Edge 1.2 brings a (currently in preview) MQTT broker, that can be used by local modules or external applications. A SAS token will be needed for authentication.

If you want to use the broker from within an IoT Edge module, you can generate the SAS token by calling the workload API. The current SDK does not offer this functionality, as the MQTT broker is still in preview.

The sample I’ve created uses the SecurityDaemonClient class from the event-grid-iot-edge SDK as reference and is written in C#.

Usage

The project creates a NuGet package, that you can add and reference in your .NET projects to generate a SAS token.

using IoTEdgeSasTokenHelper;
...

var securityDaemonClient = new SecurityDaemonClient();
//call the workload api to get the TOKEN 
string password = await securityDaemonClient.GetModuleToken(3600);

On the Readme page in the repository is more information how to reference a local NuGet package.