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.

Wrong error message when missing proper access while using `DefaultAzureCredential`

See original GitHub issue

Describe the bug

I have used management api to connect to signalr service with DefaultAzureCredential. I have a service principal set up in the env variables. I have forgotten to give “SignalR Service Owner” role access to that SP and the error that I got when trying to connect was this:

Azure SignalR Service is not connected yet, please try again later.

This is a quite misleading error as the real error should be Forbidden/Unauthorized somewhere deep.

To Reproduce

Register service manager like this:

var serviceManager = new ServiceManagerBuilder()
    .WithOptions(o =>
    {
        o.ServiceTransportType = ServiceTransportType.Persistent;
        o.ServiceEndpoints = new[]
        {
            new ServiceEndpoint(new Uri("real url"), new DefaultAzureCredential())
        };
    })
    .BuildServiceManager();

Then create a hub context and try to negotiate:

var response = await serviceHubContext.NegotiateAsync(new NegotiationOptions
{
    UserId = "some id"
});

Exceptions (if any)

Microsoft.Azure.SignalR.Common.AzureSignalRNotConnectedException: Azure SignalR Service is not connected yet, please try again later. at Microsoft.Azure.SignalR.DefaultEndpointRouter.GetNegotiateEndpoints(IEnumerable1 endpoints) at Microsoft.Azure.SignalR.DefaultEndpointRouter.GetNegotiateEndpoint(HttpContext context, IEnumerable1 endpoints) at Microsoft.Azure.SignalR.Management.NegotiateProcessor.NegotiateAsync(String hubName, NegotiationOptions negotiationOptions, CancellationToken cancellationToken) at SignalRManager.Api.Web.Controllers.NegotiateController.Negotiate(String hub) in C:\Source.…\NegotiateController.cs:line 32 at lambda_method73(Closure , Object ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Authentication.Middleware.ExceptionHandlerMiddleware.InvokeAsync(HttpContext context, IHostingEnvironment environment) at Authentication.Middleware.ExceptionHandlerMiddleware.InvokeAsync(HttpContext context, IHostingEnvironment environment) at SignalRManager.Api.Web.Middleware.ExceptionHandlerMiddleware.InvokeAsync(HttpContext context, IWebHostEnvironment environment) in C:\Source.…\Web\Middleware\ExceptionHandlerMiddleware.cs:line 39 at SignalRManager.Api.Web.Middleware.ExceptionHandlerMiddleware.InvokeAsync(HttpContext context, IWebHostEnvironment environment) in C:\Source.…\Web\Middleware\ExceptionHandlerMiddleware.cs:line 50 at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Further technical details

  • Your Azure SignalR SDK version: 1.10.0

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Y-Sindocommented, Sep 8, 2021

AzureSignalRNotConnectedException with error message "Azure SignalR Service is not connected yet, please try again later.“ is thrown because every negotiation will check whether SignalR Service is connected in version 1.10.0. This behaviour is initially designed for multiple SignalR Service instances scenario where we can choose the healthy SignalR instance for users. But it was also introduced into single SignalR instance scenario in version 1.10.0 by mistake. We will remove this confusing behaviour for single SignalR instance in the next release.

0reactions
terencefancommented, Sep 13, 2021

#1435

1.11.0 released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure error: DefaultAzureCredential authentication failed
In this sample, the DefaultAzureCredential() actually uses the EnvironmentCredential() in local, so if you run the code in local, make sure you ...
Read more >
DefaultAzureCredential failed to retrieve a token from the ...
When using the below, it fails to retrieve any credentials. I am logged into var cred = new DefaultAzureCredential(); Expected behavior What ...
Read more >
Azure Blob Storage fails to authenticate: "Make sure the ...
Hi I am trying to upload a binary file (a blob for an excel file, actually) to my storage account but the client...
Read more >
Azure AD authentication for Application Insights
The client failed to authenticate with the given credential. This error usually occurs when the credential used doesn't have the correct role ......
Read more >
azure-identity
ClientAuthenticationError has a message attribute, which describes why authentication failed. When raised by DefaultAzureCredential or ChainedTokenCredential , ...
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