Open Closed

Dynamic C# API Clients / IHttpClientProxy - Authorization Failed - SignalR #1022


User avatar
0
BringerOD created
  • ABP Framework version: v4.0.2
  • UI type: Angular - But using custom client with Aurelia
  • DB provider: EF Core
  • Identity Server Separated (Angular):
  • Exception message and stack trace:
[14:36:55 INF] CORS policy execution successful.
[14:36:55 INF] Successfully validated the token.
[14:36:55 INF] Authorization was successful.
[14:36:55 INF] Executing endpoint '/signalr-hubs/chat'
[14:37:02 INF] Start processing HTTP request GET https://localhost:44321/api/abp/api-definition
[14:37:02 INF] Sending HTTP request GET https://localhost:44321/api/abp/api-definition
[14:37:02 INF] Received HTTP response headers after 38.2684ms - 200
[14:37:02 INF] End processing HTTP request after 44.7509ms - 200
[14:37:02 WRN] Could not find IdentityClientConfiguration for . Either define a configuration for  or set a default configuration.
[14:37:02 INF] Start processing HTTP request GET https://localhost:44321/api/app/users?SkipCount=0&MaxResultCount=10&api-version=1.0
[14:37:02 INF] Sending HTTP request GET https://localhost:44321/api/app/users?SkipCount=0&MaxResultCount=10&api-version=1.0
[14:37:03 INF] Received HTTP response headers after 1243.9026ms - 401
[14:37:03 INF] End processing HTTP request after 1244.0301ms - 401
[14:37:04 ERR] Failed to invoke hub method 'SendMessage'.
Volo.Abp.Http.Client.AbpRemoteCallException: Authorization failed! Given policy has not granted.
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.ThrowExceptionForResponseAsync(HttpResponseMessage response)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.MakeRequestAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.MakeRequestAndGetResultAsync[T](IAbpMethodInvocation invocation)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.GetResultAsync(Task task, Type resultType)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at MyProject.Web.ChatHub.SendMessage(Guid to, Guid messageId, String message) in C:\src\CZ\_prj\Abp\aspnet-core\MyProject.Web\ChatHub.cs:line 54
   at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.ExecuteMethod(ObjectMethodExecutor methodExecutor, Hub hub, Object[] arguments)
   at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.<>c__DisplayClass16_0.<<Invoke>g__ExecuteInvocation|0>d.MoveNext()
  • Steps to reproduce the issue:
    • Solution was genered by the abp suite and initially looked like this:
    • We have a requirement to use chat, so I mannually added a MyProject.Web project to host singalR
      • This new project is called MyProject.Web but it does not host any web pages / ui
      • Now the solution looks like this:
      • These are the dependecies I'm using for the MyProject.Web Module [DependsOn( typeof(AbpAutofacModule), typeof(MyProjectHttpApiClientModule), typeof(MyProjectApplicationContractsModule), typeof(AbpHttpClientIdentityModelModule), typeof(AbpFeatureManagementWebModule), typeof(AbpAspNetCoreSerilogModule), typeof(AbpAspNetCoreSignalRModule), typeof(AbpEventBusRabbitMqModule) )]
      • I added the following to Configure Services: context.Services.AddHttpClientProxies( typeof(MyProjectApplicationContractsModule).Assembly );
        • I added authentication like this:
        • OnAppInitialization is configured like this:
        • The chat hub is trying to call the MyProject.HttpApi.Host userAppService using a Dynamic Api Client
        • Using a normal HttpClient and setting the Authorization header works normally, but using the IHttpClientProxy client fails with error: Authorization failed! Given policy has not granted.
      • Comments We have it configured this way because we are using other tools to scale and load balace the services I would like to use a IHttpClientProxy for my SignalR hub to call the services from my HttpApi.Host project. As I understand it is supposed to intercept the HttpContext and set the authorization header on the client. Is there some configuration that I am missing?

2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi BringerOD

    Can you share the project? liming.ma@volosoft.com

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09