如何将授权标头添加到grpc ruby​​客户端存根?

时间:2018-11-16 06:17:10

标签: ruby grpc

我需要向ruby grcp存根添加授权标头。存根定义如下:

stub = Sample::Stub.new(config.grpc_host, :this_channel_is_insecure)

1 个答案:

答案 0 :(得分:0)

可以使用“ grpc.default_authority”“ channel arg”在通道或级别上设置权限标头。参见https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h#L233

例如,您可以使用以下代码段调整“ greeter client”(https://github.com/grpc/grpc/blob/master/examples/ruby/greeter_client.rb)的自定义权限:

def main
  stub = Helloworld::Greeter::Stub.new('localhost:50051', :this_channel_is_insecure, channel_args: {'grpc.default_authority': 'my-authority'})
  user = ARGV.size > 0 ?  ARGV[0] : 'world'
  message = stub.say_hello(Helloworld::HelloRequest.new(name: user), metadata: {}).message
  p "Greeting: #{message}"
end