An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
By examining source code of azure-iot-cli-extension I came up with this:
def generate_sas_token(uri, key, policy=None, expiry=3600, absolute=False):
"""
Create a shared access signature token as a string literal.
Args:
uri (str): Uri of target resource.
policy (str): Name of shared access policy.
key (str): Shared access key.
expiry (int): Future expiry (in seconds) of the token to be generated.
absolute (bool): In general the sas token ttl is generated relative to 'now' (UTC) + expiry.
Set to true to generate a sas token with no relative start.
Returns:
result (str): SAS token as string literal.
"""
encoded_uri = quote_plus(uri)
ttl = int(expiry) if absolute else int(time() + expiry)
sign_key = '%s\n%d' % (encoded_uri, ttl)
signature = b64encode(HMAC(b64decode(key), sign_key.encode('utf-8'), sha256).digest())
result = {
'sr': uri,
'sig': signature,
'se': str(ttl)
}
if policy:
result['skn'] = policy
return 'SharedAccessSignature ' + urlencode(result)
Still, I cant connect one publisher and one subscriber at the same time, so major question still remains.