How to use the azure-iothub.SharedAccessSignature function in azure-iothub

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

github Azure / azure-iot-sdks / node / e2etests / eh / eventhubclient.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var amqp10 = require('amqp10');
var Promise = require('bluebird');

var anHourFromNow = require('azure-iot-common').anHourFromNow;
var ConnectionString = require('azure-iot-common').ConnectionString;
var EventHubReceiver = require('./eventhubreceiver.js');
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;

var managementEndpoint = '$management';

function createConfig(connectionString, entityPath) {
  var cn = ConnectionString.parse(connectionString);
  var host = cn.HostName || (cn.Endpoint || '').slice('sb://'.length);
  return {
    host: host,
    namespace: host.split('.')[0],
    keyName: cn.SharedAccessKeyName,
    key: cn.SharedAccessKey,
    eventHubName: entityPath
  };
}

/**
github Azure / iothub-explorer / lib / eventhubclient.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var amqp10 = require('amqp10');
var Promise = require('bluebird');

var anHourFromNow = require('azure-iot-common').anHourFromNow;
var ConnectionString = require('azure-iot-common').ConnectionString;
var EventHubReceiver = require('./eventhubreceiver.js');
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;

var managementEndpoint = '$management';

function createConfig(connectionString, entityPath) {
  var cn = ConnectionString.parse(connectionString);
  var host = cn.HostName || (cn.Endpoint || '').slice('sb://'.length);
  return {
    host: host,
    namespace: host.split('.')[0],
    keyName: cn.SharedAccessKeyName,
    key: cn.SharedAccessKey,
    eventHubName: entityPath
  };
}

/**
github Azure / iothub-explorer / common.js View on Github external
'use strict';

// node native modules
var fs = require('fs');

// external dependencies
var chalk = require('chalk');
var prettyjson = require('prettyjson');
var uuid = require('uuid');
var _ = require('lodash');

// sdk dependencies
var errors = require('azure-iot-common').errors;
var Message = require('azure-iot-common').Message;
var ConnectionString = require('azure-iothub').ConnectionString;
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;

function createDeviceConnectionString(deviceInfo, hubHostName) {
  var cs = 'HostName=' + hubHostName + ';DeviceId=' + deviceInfo.deviceId;
  if (deviceInfo.authentication.SymmetricKey.primaryKey) {
    cs += ';SharedAccessKey=' + deviceInfo.authentication.SymmetricKey.primaryKey;
  } else if (deviceInfo.authentication.SymmetricKey.secondaryKey) {
    cs += ';SharedAccessKey=' + deviceInfo.authentication.SymmetricKey.secondaryKey;
  } else if (deviceInfo.authentication.x509Thumbprint.primaryThumbprint || deviceInfo.authentication.x509Thumbprint.secondaryThumbprint || (deviceInfo.authentication.type === 'certificateAuthority')) {
    cs += ';x509=true';
  } else {
    cs = null;
  }

  return cs;
}
github Azure / iothub-explorer / iothub-explorer-login.js View on Github external
// Native node modules
var fs = require('fs');
var path = require('path');

// External dependencies
var program = require('commander');

// Local dependencies
var inputError = require('./common.js').inputError;
var printSuccess = require('./common.js').printSuccess;
var configLoc = require('./common.js').configLoc;

// Azure IoT SDK dependencies
var ConnectionString = require('azure-iothub').ConnectionString;
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;
var showDeprecationText = require('./common.js').showDeprecationText;

showDeprecationText('az login');

program
  .description('Create a temporary session on your IoT hub')
  .option('-d, --duration <duration-in-seconds>', 'time to keep the session open for (in seconds): if not specified, the default is one hour', parseInt)
  .parse(process.argv);

if(!program.args[0]) inputError('You must specify a connection string.');

var connString = program.args[0];
var nowInSeconds = Math.floor(Date.now() / 1000);
var expiry = program.duration ? nowInSeconds + program.duration : nowInSeconds + 3600;
var cn = ConnectionString.parse(connString);
var sas = SharedAccessSignature.create(cn.HostName, cn.SharedAccessKeyName, cn.SharedAccessKey, expiry);