我正在尝试调用GRPC端点,但我想提供一个客户身份验证标头。我在哪里指定这个?
var client = new proto.Publisher('127.0.0.1:50051',
grpc.credentials.createInsecure());
var customHeader = {
'authorization': 'secret'
}
client.publish(data, function (err, response) {
console.log('Sent');
});
答案 0 :(得分:7)
您需要创建一个grpc.Metadata
对象,然后将其作为可选参数传递给该方法:
var client = new proto.Publisher('127.0.0.1:50051',
grpc.credentials.createInsecure());
var metadata = new grpc.Metadata();
metadata.add('authorization', 'secret')
client.publish(data, metadata, function (err, response) {
console.log('Sent');
});