Exemple #1
0
 public SasDeviceTokenAuthenticationHeaderProvider(IotHubConnectionString iotHubConnectionString)
 {
     if (iotHubConnectionString.CredentialScope == CredentialScope.Device &&
         iotHubConnectionString.CredentialType == CredentialType.SharedAccessKey)
     {
         // Http Authorization header will not accept only a key as a value. It must have a prefix
         this.sasSignatureOrSharedAccessKey = SecurityConstants.SharedAccessKeyFullFieldName
                                              + iotHubConnectionString.GetPassword();
     }
     else
     {
         this.sasSignatureOrSharedAccessKey = iotHubConnectionString.GetPassword();
     }
 }
 public SasDeviceTokenAuthenticationHeaderProvider(IotHubConnectionString iotHubConnectionString)
 {
     if (iotHubConnectionString.CredentialScope == CredentialScope.Device
         && iotHubConnectionString.CredentialType == CredentialType.SharedAccessKey)
     {
         // Http Authorization header will not accept only a key as a value. It must have a prefix
         this.sasSignatureOrSharedAccessKey = SecurityConstants.SharedAccessKeyFullFieldName
                                              + iotHubConnectionString.GetPassword();
     }
     else
     {
         this.sasSignatureOrSharedAccessKey = iotHubConnectionString.GetPassword();
     }
     
 }
        public void ServiceClient_ConnectionString_ModuleIdentity_SharedAccessKeyCredentialType_Test()
        {
            string connectionString = "HostName=testhub.azure-devices-int.net;DeviceId=edgecapabledevice1;ModuleId=testModule;SharedAccessKey=dGVzdFN0cmluZzE=;GatewayHostName=edgehub1.ms.com";
            var    serviceClient    = (AmqpServiceClient)ServiceClient.CreateFromConnectionString(connectionString);

            Assert.IsNotNull(serviceClient.Connection);
            IotHubConnectionString iotHubConnectionString = (IotHubConnectionString)serviceClient.Connection.Credential;

            Assert.IsNotNull(iotHubConnectionString);
            Assert.AreEqual("testhub.azure-devices-int.net", iotHubConnectionString.Audience);
            Assert.AreEqual("testhub.azure-devices-int.net", iotHubConnectionString.HostName);
            Assert.AreEqual("dGVzdFN0cmluZzE=", iotHubConnectionString.SharedAccessKey);
            Assert.IsNotNull(iotHubConnectionString.GetPassword());
        }
        public MqttIotHubAdapter Create(
            IMqttIotHubEventHandler mqttIotHubEventHandler,
            IotHubConnectionString iotHubConnectionString,
            MqttTransportSettings mqttTransportSettings)
        {
            IWillMessage willMessage = mqttTransportSettings.HasWill ? this.settings.WillMessage : null;

            return(new MqttIotHubAdapter(
                       iotHubConnectionString.DeviceId,
                       iotHubConnectionString.HostName,
                       mqttTransportSettings.ClientCertificate != null ? null : iotHubConnectionString.GetPassword(),
                       mqttTransportSettings,
                       willMessage,
                       mqttIotHubEventHandler));
        }
        public void ServiceClient_ConnectionString_ModuleIdentity_SharedAccessKeyCredentialType_Test()
        {
            string connectionString = "HostName=testhub.azure-devices-int.net;DeviceId=edgecapabledevice1;ModuleId=testModule;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8=;GatewayHostName=edgehub1.ms.com";
            var    serviceClient    = (AmqpServiceClient)ServiceClient.CreateFromConnectionString(connectionString);

            Assert.IsNotNull(serviceClient.Connection);
            IotHubConnectionString iotHubConnectionString = serviceClient.Connection.ConnectionString;

            Assert.IsNotNull(iotHubConnectionString);
            Assert.AreEqual("testhub.azure-devices-int.net", iotHubConnectionString.Audience);
            Assert.AreEqual("edgehub1.ms.com", iotHubConnectionString.HostName);
            Assert.AreEqual("edgecapabledevice1", iotHubConnectionString.DeviceId);
            Assert.AreEqual("testModule", iotHubConnectionString.ModuleId);
            Assert.AreEqual("CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8=", iotHubConnectionString.SharedAccessKey);
            Assert.AreEqual("edgehub1.ms.com", iotHubConnectionString.GatewayHostName);
            Assert.IsNotNull(iotHubConnectionString.GetPassword());
        }
 public MqttIotHubAdapter Create(
     Action onConnected, 
     Action<Message> onMessageReceived,
     Action<Exception> onError, 
     IotHubConnectionString iotHubConnectionString, 
     MqttTransportSettings mqttTransportSettings)
 {
     IWillMessage willMessage = mqttTransportSettings.HasWill ? this.settings.WillMessage : null;
     
     return new MqttIotHubAdapter(
         iotHubConnectionString.DeviceId,
         iotHubConnectionString.HostName,
         mqttTransportSettings.ClientCertificate != null ? null : iotHubConnectionString.GetPassword(),
         mqttTransportSettings,
         willMessage,
         onConnected,
         onMessageReceived,
         onError);
 }
        public MqttIotHubAdapter Create(
            Action onConnected,
            Action <Message> onMessageReceived,
            Action <Exception> onError,
            IotHubConnectionString iotHubConnectionString,
            MqttTransportSettings mqttTransportSettings)
        {
            IWillMessage willMessage = mqttTransportSettings.HasWill ? this.settings.WillMessage : null;

            return(new MqttIotHubAdapter(
                       iotHubConnectionString.DeviceId,
                       iotHubConnectionString.HostName,
                       iotHubConnectionString.GetPassword(),
                       mqttTransportSettings,
                       willMessage,
                       onConnected,
                       onMessageReceived,
                       onError));
        }