Way to add call credentials to insecure grpc channel without using DI factory
See original GitHub issueThere is a documented way to create a gRPC client using the dependency injection framework that allows the usage of call credentials on insecure channels:
builder.Services.AddGrpcClient<Greeter.GreeterClient>(o =>
{
o.Address = new Uri("http://localhost:5060");
o.ChannelOptionsActions.Add((opt) =>
{
opt.UnsafeUseInsecureChannelCallCredentials = true;
});
}).AddCallCredentials((context, metadata) =>
{
metadata.Add("Authorization",
"Bearer ...");
return Task.CompletedTask;
});
I have not found a way to do the same if I manually create a channel. It seems the classes I would need to use are all internal/private classes. Is this by design or is there simply a way I’m missing to do this?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Authentication and authorization in gRPC for ASP.NET Core
Authentication is centrally configured on the channel. The token doesn't need to be manually provided to the gRPC call. · The CallCredentials.
Read more >Authentication
Call credentials, which are attached to a call (or ClientContext in C++). ... be set in the SslCredentialsOptions parameter passed to the factory...
Read more >c# - How can I add Metadata to a GRPC channel using ...
The grpc api that I am subscribing to expects metadata with a user name. It works fine when configuring using a Channel and...
Read more >Securing gRPC-based Microservices in .NET Core
TL;DR: This tutorial will show you how to integrate authentication and authorization in a .NET Core microservice scenario based on gRPC.
Read more >CallCredentials on "Insecure" Channels (in C-based ...
In case (1). grpc core and wrapping languages only allow call credentials on a secure channel. gRPC Go and Java allow developers to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got it. I just discovered the same thing in a test.
Using insecure + channel credentials (i.e. not passed as an argument to a
CallOptions.Credentials
) wasn’t considered. I’ll see whether there is a way to fix this.Fix here: https://github.com/grpc/grpc-dotnet/pull/1802
There is a behavior change here that needs to be discussed before merging.