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.

Way to add call credentials to insecure grpc channel without using DI factory

See original GitHub issue

There 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:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, Jul 1, 2022

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.

0reactions
JamesNKcommented, Jul 1, 2022

Fix here: https://github.com/grpc/grpc-dotnet/pull/1802

There is a behavior change here that needs to be discussed before merging.

Read more comments on GitHub >

github_iconTop 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 >

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