title: How to use Azure.Identity.ClientSecretCredential to access a Azure Queue?
body: <p>I've created an App Registration in Azure and added access to Azure Storage (user_impersonation):
  <a href="https://i.stack.imgur.com/WPdyj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WPdyj.png" alt="enter image description here" /></a></p>
  <p>The console app uses these packages:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;PackageReference Include=&quot;Azure.Identity&quot; Version=&quot;1.2.0-preview.6&quot; /&gt;
  &lt;PackageReference Include=&quot;Azure.Storage.Queues&quot; Version=&quot;12.4.0-preview.5&quot; /&gt;
  </code></pre>
  <p>And the code looks like:</p>
  <pre class="lang-cs prettyprint-override"><code>var tc = new ClientSecretCredential(&quot;{tenant-id}&quot;, &quot;{client-id}&quot;, &quot;{client-secret}&quot;);
  var client = new QueueClient(new Uri(&quot;https://{storage-name}.queue.core.windows.net/example-q&quot;), tc);
  
  // this fails with error
  client.SendMessage(&quot;msg&quot;);
  </code></pre>
  <p>The error message is like:</p>
  <pre><code>Unhandled exception. Azure.RequestFailedException: This request is not authorized to perform this operation using this permission.
  RequestId:13f45216-9003-0061-49cf-616632000000
  Time:2020-07-24T15:32:44.9586872Z
  Status: 403 (This request is not authorized to perform this operation using this permission.)
  ErrorCode: AuthorizationPermissionMismatch
  
  Headers:
  Server: Windows-Azure-Queue/1.0,Microsoft-HTTPAPI/2.0
  x-ms-request-id: 13f45216-9003-0061-49cf-616632000000
  x-ms-version: 2018-11-09
  x-ms-error-code: AuthorizationPermissionMismatch
  Date: Fri, 24 Jul 2020 15:32:44 GMT
  Content-Length: 279
  Content-Type: application/xml
  
     at Azure.Storage.Queues.QueueRestClient.Messages.EnqueueAsync_CreateResponse(ClientDiagnostics clientDiagnostics, Response response)
     at Azure.Storage.Queues.QueueRestClient.Messages.EnqueueAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri resourceUri, QueueSendMessage message, String version, Nullable`1 visibilitytimeout, Nullable`1 messageTimeToLive, Nullable`1 timeout, String requestId, Boolean async, String operationName, CancellationToken cancellationToken)
     at Azure.Storage.Queues.QueueClient.SendMessageInternal(String messageText, Nullable`1 visibilityTimeout, Nullable`1 timeToLive, Boolean async, CancellationToken cancellationToken)
     at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](Task`1 task)
     at Azure.Storage.Queues.QueueClient.SendMessage(String messageText, Nullable`1 visibilityTimeout, Nullable`1 timeToLive, CancellationToken cancellationToken)
     at Azure.Storage.Queues.QueueClient.SendMessage(String messageText)
  </code></pre>