title: Microsoft.Azure.Devices.Client.Exceptions.UnauthorizedException: 'CONNECT failed: RefusedNotAuthorized'
body: <p>I have successfully configured my Azure IoT Dev Kit MXChip and I am able to send the data to the IoT Hub. I have also created a logic app with a router in it to receive a mail when the temperature is more than expected and a SQL server to save the Stream Analytics Job data. Basically, I followed the tutorial and till this point, everything was working fine, now I am just creating a simulator device where I can simulate events as mentioned in this <a href="https://docs.microsoft.com/en-gb/azure/iot-hub/tutorial-routing#run-simulated-device-app" rel="nofollow noreferrer">tutorial</a>. But whenever I run the application, I am always getting an error as below.</p>
  
  <blockquote>
    <p>Microsoft.Azure.Devices.Client.Exceptions.UnauthorizedException:
    'CONNECT failed: RefusedNotAuthorized'</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/doG5u.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/doG5u.jpg" alt="enter image description here"></a></p>
  
  <p>I am not sure what I am missing here though I understand it is an authentication issue, and I have already changed my Hub Uri and device key as mentioned in the tutorial. </p>
  
  <pre><code>private readonly static string s_iotHubUri = "";
  // This is the primary key for the device. This is in the portal. 
  // Find your IoT hub in the portal &gt; IoT devices &gt; select your device &gt; copy the key. 
  private readonly static string s_deviceKey = "";
  </code></pre>