0

I've created a small GRPC service in .NET core. The service has authentication enabled:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
   .AddJwtBearer(options =>
    {
       options.Audience = config["AAD:Audience"];
       options.Authority = config["AAD:Authority"];
    });

I've also created a small client, that can connect to the service by adding a Bearer token, and it works fine. However if I call the service withour a token, I get an exception back, with the following message:

Status(StatusCode=Cancelled, Detail="Bad gRPC response. Expected HTTP status code 200. Got status code: 401")

Is there a (smart) way, to capture this server side and convert it into a GRPC payload, instead of getting an exception on the client??

TIA

smolesen
  • 1,153
  • 3
  • 11
  • 29
  • You may have a look here: https://stackoverflow.com/questions/40777189/can-i-send-a-custom-error-message-from-server-to-client-grpc – Tobias von Falkenhayn Dec 20 '19 at 11:14
  • I think the situation is a bit different here, since I'm not in control of the Authentication. So somehow I need to intercept the Authorization and return a "normal" GRPC result. – smolesen Dec 23 '19 at 10:17
  • As stated here, it might be best to just retrun the exception, eventhough its statuscode is cancelled https://github.com/grpc/grpc-dotnet/issues/264 – smolesen Dec 23 '19 at 12:19

0 Answers0