title: ASP.NET Core grpc client : configuring HTTP authorization
body: <p>Following the documentation at <a href="https://docs.microsoft.com/fr-fr/aspnet/core/grpc/authn-and-authz?view=aspnetcore-3.0#bearer-token-authentication" rel="nofollow noreferrer">https://docs.microsoft.com/fr-fr/aspnet/core/grpc/authn-and-authz?view=aspnetcore-3.0#bearer-token-authentication</a>, I try to configure my GRPC client to automatically inject a JWT token.        </p>
  
  <pre><code>    private static GrpcChannel CreateAuthenticatedChannel(string address)
      {
          var _token = "xxx"; //using some hardcoded JWT token for testing
          var credentials = CallCredentials.FromInterceptor((context, metadata) =&gt;
          {
              if (!string.IsNullOrEmpty(_token))
              {
                  metadata.Add("Authorization", $"Bearer {_token}");
              }
              return Task.CompletedTask;
          });
  
          var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions
          {
              Credentials = ChannelCredentials.Create(ChannelCredentials.Insecure, credentials)
          });
          return channel;
      }
  </code></pre>
  
  <p>But it chokes on an exception "Supplied channel credentials do not allow composition" in Grpc.Core</p>
  
  <pre><code>System.ArgumentException
    HResult=0x80070057
    Message=Supplied channel credentials do not allow composition.
    Source=Grpc.Core.Api
    StackTrace:
     at Grpc.Core.Utils.GrpcPreconditions.CheckArgument(Boolean condition, String errorMessage)
     at Grpc.Core.ChannelCredentials.CompositeChannelCredentials..ctor(ChannelCredentials channelCredentials, CallCredentials callCredentials)
     at Grpc.Core.ChannelCredentials.Create(ChannelCredentials channelCredentials, CallCredentials callCredentials)
     at Service2.StartupCommon.CreateAuthenticatedChannel(String address) in xxx\Service2\StartupCommon.cs:line 32
  </code></pre>
  
  <p>What does this mean ? How am I suppose to provide the HTTP Authorization header ?</p>