question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] EventHubProducerClient.SendAsync using TokenCredential fails with AADSTS70011 ... The scope Send is not valid

See original GitHub issue

Describe the bug EventHubProducerClient.SendAsync with TokenProvider fails with: “error”:“invalid_scope”, “error_description”:"AADSTS70011: The provided request must include a ‘scope’ input parameter. The provided value for the input parameter ‘scope’ is not valid. The scope Send is not valid.

Exception or Stack Trace

at Azure.Identity.AadIdentityClient.SendAuthRequestAsync(Request request, CancellationToken cancellationToken)
   at Azure.Identity.AadIdentityClient.AuthenticateAsync(String tenantId, String clientId, String clientSecret, String[] scopes, CancellationToken cancellationToken)
   at Azure.Identity.ClientSecretCredential.GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Azure.Identity.ExtendedAccessToken.GetTokenOrThrow()
   at Azure.Identity.EnvironmentCredential.GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
   at Azure.Messaging.EventHubs.Amqp.CbsTokenProvider.GetTokenAsync(Uri namespaceAddress, String appliesTo, String[] requiredClaims)
   at Microsoft.Azure.Amqp.TaskHelpers.EndAsyncResult(IAsyncResult asyncResult)
   at Microsoft.Azure.Amqp.IteratorAsyncResult`1.<>c.<CallTask>b__24_1(TIteratorAsyncResult thisPtr, IAsyncResult r)
   at Microsoft.Azure.Amqp.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.Amqp.ExceptionDispatcher.Throw(Exception exception)
   at Microsoft.Azure.Amqp.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.Azure.Amqp.AsyncResult`1.End(IAsyncResult asyncResult)
   at Microsoft.Azure.Amqp.AmqpCbsLink.EndSendToken(IAsyncResult result)
   at Microsoft.Azure.Amqp.AmqpCbsLink.<>c__DisplayClass4_0.<SendTokenAsync>b__1(IAsyncResult a)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Azure.Messaging.EventHubs.Amqp.AmqpConnectionScope.CreateSendingLinkAsync(AmqpConnection connection, Uri endpoint, TimeSpan timeout, CancellationToken cancellationToken)
   at Azure.Messaging.EventHubs.Amqp.AmqpConnectionScope.OpenProducerLinkAsync(String partitionId, TimeSpan timeout, CancellationToken cancellationToken)
   at Azure.Messaging.EventHubs.Amqp.AmqpProducer.CreateLinkAndEnsureProducerStateAsync(String partitionId, TimeSpan timeout, CancellationToken cancellationToken)
   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.OnCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Azure.Messaging.EventHubs.Amqp.AmqpProducer.SendAsync(Func`1 messageFactory, String partitionKey, CancellationToken cancellationToken)
   at Azure.Messaging.EventHubs.Amqp.AmqpProducer.SendAsync(Func`1 messageFactory, String partitionKey, CancellationToken cancellationToken)
   at Azure.Messaging.EventHubs.Amqp.AmqpProducer.SendAsync(IEnumerable`1 events, SendOptions sendOptions, CancellationToken cancellationToken)
   at Azure.Messaging.EventHubs.EventHubProducerClient.SendAsync(IEnumerable`1 events, SendOptions options, CancellationToken cancellationToken)

To Reproduce

  1. Credentials with the “Azure Event Hubs Data Owner” role for configured EventHub.
  2. Successful call client.GetEventHubPropertiesAsync()
  3. Exception when trying to send data.

Code Snippet

var creds = new EnvironmentCredential();
await using (var client = new EventHubProducerClient(
  "<<myNs>>.servicebus.windows.net",
  "<<MyEh>>",
  creds))
{
  // This call works
  var properties = await client.GetEventHubPropertiesAsync();
  Console.WriteLine($"*** Hub \"{ properties.Name }\" reached successfully.");

  var bytes = await File.ReadAllBytesAsync(@"<<some bytes to send>>");
  var ed = new EventData(bytes);                
  await client.SendAsync(new[] {ed});
}

Expected behavior Data sent to Event Hub.

Setup (please complete the following information): Win10 dotnet core 3.0 Azure.Identity 1.0.0 Azure.Messaging.EventHubs 5.0.0-preview.5

Additional context I can send the data via Microsoft.Azure.EventHubs 4.1.0, EventHubClient.CreateWithManagedIdentity() using the same credentials

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jsquirecommented, Dec 4, 2019

The preview 6 package of Azure.Messaging.EventHubs has been published. The fix that I spoke of is included there, and I’ve verified that our identity-based tests for inspecting the Event Hub, publishing events, and reading events are consistently passing.

Closing this out as resolved. Please let us know if you experience any further issues.

0reactions
stefandocommented, Nov 26, 2019

I closed it before by mistake. It’s just for tracking purposes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The provided value for the input parameter 'scope' is not ...
I tried User.Read.All and it gave me this error :AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope...
Read more >
EventHubProducerClient.SendAsync Method
SendAsync (EventDataBatch, CancellationToken)​​ Sends a set of events to the associated Event Hub using a batched approach.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found