I have a gRPC service running like this:
server.addService(PassportService, implementation);
server.bind(mfeConfig().grpc.passport, grpc.ServerCredentials.createInsecure());
server.start();
I can call my service from a client like this:
const request = new GetConsoleUserRequest();
const meta = new grpc.Metadata();
meta.add('__.grpc.exchanged-token', token);
this.client.getConsoleUser(
request,
meta,
(err: grpc.ServiceError, val: GetConsoleUserResponse) => {
But I can't figure out how to read the metadata in my service implementation. Now matter which overloads I define for getConsoleUser
, the metadata is never one of the arguments. Here's getConsoleUser
, which just returns some fake data:
getConsoleUser: (_req: GetConsoleUserRequest, callback: Function) => {
const response = new GetConsoleUserResponse();
const user = new ConsoleUser();
user.setName('Bob Loblaw');
// Change me to userStatus.GUEST to simulate anonymous user access
user.setState(userStatus.REGISTERED);
user.setEmail('bob@loblaw.com');
response.setConsoleUser(user);
callback(null, response);
},
I've tried changing that signature to this:
getConsoleUser: (_req: GetConsoleUserRequest, meta: grpc.Metadata, callback: Function) => {
But if I do that, the second argument is actually the callback function, and the third argument is undefined.
Is there a way to read the metadata from my service implementation? Or is there some other class that I have to attach my service to so that I can listen for incoming metadata?