Code Monkey home page Code Monkey logo

iotsastokengenerate's Introduction

IoTSASTokenGenerate

C and C++ sample programs that demonstrate how to generate a SAS Token from a device connection string in order to connect a device to an Azure IoT hub without using the Microsoft SDK. In addition to a regular C sample there is also a version that does not use malloc. The caller is required to pass a buffer and it will use this for all of its dynamic memory usage. This is useful for highly constrained devices where keeping a track of in use memory is imperative.

When connecting to an Azure IoT hub using the standard Microsoft SDKs one only needs to provide a device connection string. This string is used to create a SAS token which is subsequently used to authenticate the device with the Azure IoT hub.

However, there instances that you may wish to access the Azure IoT hub using a mechanism other than the Microsoft SDKs. This requires one to create the SAS token in order to authenticate with the hub. One can do this by generating the SAS token with the Device Explorer (https://github.com/Azure/azure-iot-sdk-csharp/tree/master/tools/DeviceExplorer) or the iothub-explorer node tool (https://github.com/azure/iothub-explorer) but neither of these is a suitable long term solution because the SAS token has a finite lifetime. When it expires one will no longer be able to use it to authenticate with the Azure IoT hub.

This project presents an example of how to generate your own SAS token from a device connection string. I have attempted to minimize the number of dependencies in it by including my own implementations of URL encoding and Base 64 encoding and decoding. This code is based upon the code that I used to generate the SAS token in the ESP8266 sample that uses a third party MQTT library.

This is sample code only. It doesn't do much error checking and it might leak memory. It is provided for the purposes of demonstration only.

iotsastokengenerate's People

Contributors

markrad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.