
Field | Description | Remarks |
DeviceID | Device ID, equivalent to Client ID | Associate device configuration with the MQTT client session. |
Status | Device identity status | Ignore this configuration when the status is Disabled. |
PropagatingProperties | Propagation attributes | |
PrimaryKey | Primary key | |
SecondaryKey | Secondary key | |
CreateTime | Device identity record creation time | - |

Password field to connect to the MQTT server. The Username field is not used in the "one-device-one-secret" authentication. However, it is one of the dimensions considered by the authorization policy when Data Plane Authorization Policy is enabled. For details, see Authorization Policy Description./*** @clientId client identifier* @key PrimaryKey or SecondaryKey in the Device Identity Registry*/public static String generateSasToken(String clientId, String key) throws Exception {// Token is valid for 3,600 seconds.var expiry = Instant.now().getEpochSecond() + 3600;String stringToSign = URLEncoder.encode(clientId, StandardCharsets.UTF_8) + "\\n" + expiry;byte[] decodedKey = Base64.getDecoder().decode(key);Mac sha256HMAC = Mac.getInstance("HmacSHA256");SecretKeySpec secretKey = new SecretKeySpec(decodedKey, "HmacSHA256");sha256HMAC.init(secretKey);Base64.Encoder encoder = Base64.getEncoder();String signature = new String(encoder.encode(sha256HMAC.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8);String token = "SharedAccessSignature sr=" + URLEncoder.encode(clientId, StandardCharsets.UTF_8)+ "&sig=" + URLEncoder.encode(signature, StandardCharsets.UTF_8.name()) + "&se=" + expiry;return token;}
from base64 import b64encode, b64decodefrom hashlib import sha256from time import timefrom urllib import parsefrom hmac import HMACdef generate_sas_token(clientId, key, expiry=3600):ttl = time() + expirysign_key = "%s\\n%d" % ((parse.quote_plus(clientId)), int(ttl))signature = b64encode(HMAC(b64decode(key), sign_key.encode('utf-8'), sha256).digest())rawtoken = {'sr' : clientId,'sig': signature,'se' : str(int(ttl))}return 'SharedAccessSignature ' + parse.urlencode(rawtoken)
var generateSasToken = function(clientId, key) {resourceUri = encodeURIComponent(clientId);// Set the Token validity period to 3,600 secondsvar expires = (Date.now() / 1000) + 3600;expires = Math.ceil(expires);var toSign = resourceUri + '\\n' + expires;// Use cryptovar hmac = crypto.createHmac('sha256', Buffer.from(key, 'base64'));hmac.update(toSign);var base64UriEncoded = encodeURIComponent(hmac.digest('base64'));// Construct authorization stringvar token = "SharedAccessSignature sr=" + resourceUri + "&sig="+ base64UriEncoded + "&se=" + expires;return token;};
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan