How to use azure-iot-security-symmetric-key - 5 common examples

To help you get started, we’ve selected a few azure-iot-security-symmetric-key examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-iot-sdk-node / digitaltwins / samples / iot_central_device / sample_device.js View on Github external
async function main() {
  const provisioningClient = ProvisioningDeviceClient.create(
    provisioningEndpoint,
    idScope,
    new ProvisioningTransport(),
    new SymmetricKeySecurityClient(registrationId, symmetricKey)
  );

  // IoT Central requires a special payload to be sent when the device is provisioned
  provisioningClient.setProvisioningPayload({
    '__iot:interfaces': {
      CapabilityModelId: capabilityModel
    }
  });

  const registrationResult = await provisioningClient.register();
  const deviceConnectionString = `HostName=${registrationResult.assignedHub};DeviceId=${registrationResult.deviceId};SharedAccessKey=${symmetricKey}`;

  const propertyUpdateHandler = (interfaceInstance, propertyName, reportedValue, desiredValue, version) => {
    console.log('Received an update for ' + propertyName + ': ' + JSON.stringify(desiredValue));
    interfaceInstance[propertyName].report(desiredValue, {
      code: 200,
github Azure / azure-iot-sdk-node / provisioning / device / samples / register_symkey.js View on Github external
//
var provisioningHost = process.env.PROVISIONING_HOST;

//
// You can find your idScope in the portal overview section for your dps instance.
//
var idScope = process.env.PROVISIONING_IDSCOPE;

//
// The registration id of the device to be registered.
//
var registrationId = process.env.PROVISIONING_REGISTRATION_ID;

var symmetricKey = process.env.PROVISIONING_SYMMETRIC_KEY;

var provisioningSecurityClient = new SymmetricKeySecurityClient(registrationId, symmetricKey);

var provisioningClient = ProvisioningDeviceClient.create(provisioningHost, idScope, new ProvisioningTransport(), provisioningSecurityClient);
// Register the device.
provisioningClient.setProvisioningPayload({a: 'b'});
provisioningClient.register(function(err, result) {
  if (err) {
    console.log("error registering device: " + err);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
    console.log('payload=' + JSON.stringify(result.payload));
    var connectionString = 'HostName=' + result.assignedHub + ';DeviceId=' + result.deviceId + ';SharedAccessKey=' + symmetricKey;
    var hubClient = Client.fromConnectionString(connectionString, iotHubTransport);

    hubClient.open(function(err) {
github Azure / azure-iot-sdk-node / provisioning / device / ts-samples / src / register_symkey.ts View on Github external
//
const provisioningHost = process.env.PROVISIONING_HOST;

//
// You can find your idScope in the portal overview section for your dps instance.
//
const idScope = process.env.PROVISIONING_IDSCOPE;

//
// The registration id of the device to be registered.
//
const registrationId = process.env.PROVISIONING_REGISTRATION_ID;

const symmetricKey = process.env.PROVISIONING_SYMMETRIC_KEY;

let provisioningSecurityClient = new SymmetricKeySecurityClient(registrationId, symmetricKey);

let provisioningClient = ProvisioningDeviceClient.create(provisioningHost, idScope, new ProvisioningTransport(), provisioningSecurityClient);
// Register the device.
provisioningClient.setProvisioningPayload({a: 'b'});
provisioningClient.register((err, result) => {
  if (err) {
    console.log('error registering device: ' + err);
  } else {
    console.log('registration succeeded');
    console.log('assigned hub=' + result.assignedHub);
    console.log('deviceId=' + result.deviceId);
    console.log('payload=' + JSON.stringify(result.payload));
    let connectionString = 'HostName=' + result.assignedHub + ';DeviceId=' + result.deviceId + ';SharedAccessKey=' + symmetricKey;
    let hubClient = Client.fromConnectionString(connectionString, iotHubTransport);

    hubClient.open((err) => {
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.js View on Github external
this.initialize = function (callback) {
    var id = uuid.v4();
    self.deviceId = 'deleteMe_provisioning_node_e2e_' + id;
    self.registrationId = 'reg-' + id;
    self.primaryKey = Buffer.from(uuid.v4()).toString('base64');
    securityClient = new SymmetricKeySecurityClient(self.registrationId, self.primaryKey);
    callback();
  };
github Azure / azure-iot-sdk-node / provisioning / e2e / _provisioning_e2e.js View on Github external
this.register = function (Transport, callback) {
    var transport = new Transport();
    securityClient = new SymmetricKeySecurityClient(self.registrationId, computeDerivedSymmetricKey(self.primaryKey, self.registrationId));
    var provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningHost, idScope, transport, securityClient);
    provisioningDeviceClient.register(function (err, result) {
      callback(err, result);
    });
  };

azure-iot-security-symmetric-key

Azure IoT Symmetric Key Security Client

MIT
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis

Popular azure-iot-security-symmetric-key functions

Similar packages