-
ABP Framework version: v9.0.2
-
UI Type: MVC
-
Database System: EF Core (PostgreSQL, etc..)
-
Tiered (for MVC) or Auth Server Separated (for Angular): yes
-
Exception message and full stack trace: Details: 2 UNKNOWN: Received HTTP status code 500
-
Steps to reproduce the issue: Create a mew Microservice and add Grpc Service like in the example: https://abp.io/community/articles/using-grpc-with-the-abp-framework-2dgaxzw3
Hi Dear Friends,
I used the information on given example: https://abp.io/community/articles/using-grpc-with-the-abp-framework-2dgaxzw3
But when i try to send request from postman or any other client it gave :"Details: 2 UNKNOWN: Received HTTP status code 500"
And on server side below exceptions given:
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Routing.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Volo.Abp.AspNetCore.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Can you help me please*
10 Answer(s)
-
0
When application starts it gives below warnings
[14:37:29 DBG] Could not find bind method for Services.TrevaProfiles.ITrevaProfileAppService.
[14:37:32 WRN] Signature not recognized for Services.TrevaProfiles.ITrevaProfileAppService.GetAsync; method will not be bound
[14:37:32 DBG] No gRPC methods discovered for Services.TrevaProfiles.ITrevaProfileAppService.
[14:37:32 INF] Initialized all ABP modules.
[14:37:32 WRN] Overriding address(es) 'http://localhost:44360, http://localhost:44361'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
[14:37:32 WRN] HTTP/2 is not enabled for 127.0.0.1:44360. The endpoint is configured to use HTTP/1.1 and HTTP/2, but TLS is not enabled. HTTP/2 requires TLS application protocol negotiation. Connections to this endpoint will use HTTP/1.1.
[14:37:32 WRN] HTTP/2 is not enabled for [::1]:44360. The endpoint is configured to use HTTP/1.1 and HTTP/2, but TLS is not enabled. HTTP/2 requires TLS application protocol negotiation. Connections to this endpoint will use HTTP/1.1. -
0
I figured out the problem. Reflection package also need for grpc. Now, I can access the services and methods.
Now, i need to send accessToken to the grpc endpoint because it's authorized.
Is there any working sample for that?
-
0
Hi,
Sorry for late-response, it seems you already found the problem.
Now, i need to send accessToken to the grpc endpoint because it's authorized.
ABP Framework does not implements it currently. gRPC requests are planned to be used for communication between micro-service that is not open to world and in an internal network.
But still it's an ASP.NET Core application, you can follow Microsoft's guide:
https://learn.microsoft.com/en-us/aspnet/core/grpc/authn-and-authz?view=aspnetcore-9.0#authorize-users-to-access-services-and-service-methodsIn the ABP Framework, Each PermissionName is a policy in the authorization logic of ASP.NET Core application, you can directly use your permissions in the
[Authorize]
attribute. -
0
I tried with below way but could not authenticate
public virtual async Task TrevaGetProfileAsync(string accessToken) { var credentials = CallCredentials.FromInterceptor((context, metadata) => { metadata.Add("Authorization", accessToken); return Task.CompletedTask; }); if (CurrentTenant.IsAvailable) { credentials = CallCredentials.FromInterceptor((context, metadata) => { metadata.Add("__tenant", CurrentTenant.Name!); metadata.Add("Authorization", accessToken); return Task.CompletedTask; }); } var grpcProfileUrl = _configuration["GrpcEndpoints:ProfileUrl"]!; if (string.IsNullOrWhiteSpace(grpcProfileUrl)) { throw new BusinessException(message: L["GrpcEndpointCanNotBeNull", nameof(grpcProfileUrl)]); } using var channel = GrpcChannel.ForAddress(grpcProfileUrl, new GrpcChannelOptions { UnsafeUseInsecureChannelCallCredentials = true, HttpHandler = new GrpcWebHandler(new HttpClientHandler()), Credentials = ChannelCredentials.Create(ChannelCredentials.Insecure, credentials) }); var trevaProfileAppService = channel.CreateGrpcService(); var trevaProfileInput = new TrevaProfileInputDto { UserId = CurrentUser.Id!.Value, TenantId = CurrentTenant.Id }; var trevaProfileDto = await trevaProfileAppService.GetAsync(trevaProfileInput); return trevaProfileDto; }
it gives below exception
Status(StatusCode="Unknown", Detail="Exception was thrown by handler. AbpAuthorizationException: Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown.")
-
0
Hi,
ABP doesn't provide an authentication pipeline for gRPC by default, if you make the regular ASP.NET Core authentication mechanism, ABP policies can work together. In your case it seems ASP.NET Core can't execute its own properties.
Since gRPC requests does not have header like HTTP Requests by default, you may add and resolve them manually.
-
0
Can you make sure if AbpAuthorizationService works on your gRPC request?
-
0
Hi Enis,
How can I sure about if AbpAuthorizationService works on your gRPC request?
-
0
Enis is off today, so we'll answer on Monday. Thank you for your patience.
-
0
Hi Enis,
How can I sure about if AbpAuthorizationService works on your gRPC request?
You can override it in your application and check if it's triggered to make sure it's executed. It implements Microsoft's default
Microsoft.AspNetCore.Authorization.IAuthorizationService
and replaces it in the dependency injection. If it's not triggered you'll need to configure it properly by following Microsoft's documentation:
https://learn.microsoft.com/en-us/aspnet/core/grpc/authn-and-authz?view=aspnetcore-9.0using System; using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Volo.Abp.Authorization; using Volo.Abp.DependencyInjection; using Volo.Abp.Security.Claims; namespace YourComapnyName.YourProjetName.Web; [Dependency(ReplaceServices = true)] [ExposeServices(typeof(IAuthorizationService))] public class CustomAbpAuthorizationService : AbpAuthorizationService { public CustomAbpAuthorizationService(IAuthorizationPolicyProvider policyProvider, IAuthorizationHandlerProvider handlers, ILogger<DefaultAuthorizationService> logger, IAuthorizationHandlerContextFactory contextFactory, IAuthorizationEvaluator evaluator, IOptions<AuthorizationOptions> options, ICurrentPrincipalAccessor currentPrincipalAccessor, IServiceProvider serviceProvider) : base(policyProvider, handlers, logger, contextFactory, evaluator, options, currentPrincipalAccessor, serviceProvider) { } public override Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? resource, IEnumerable<IAuthorizationRequirement> requirements) { // debugger here Console.WriteLine("AuthorizeAsync is called"); return base.AuthorizeAsync(user, resource, requirements); } public override Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? resource, string policyName) { // debugger here Console.WriteLine("AuthorizeAsync is called"); return base.AuthorizeAsync(user, resource, policyName); } }
-
0
Hi Enis,
I'll try this and let you know about progress in a few days.
Thank you