How to connect gRPC server with bearer token using client.connect() method?

while connecting to gRPC server i cannot able to pass the bearer token

Hi @tjishant10

Welcome to the community forum :wave:

Based on the documentation for Client.connect(address [,params]), I don’t think you’ll be able to pass the bearer token there. The connectParams object does not allow it.

Could you provide more information, a sanitized version of your script, and more details on the error you get? Have you tried using Client.invoke(url, request [,params])? This has a Params object that accepts metadata. However, I’m not sure if what we would need here is headers.

We’ll try to look into it if you can provide more information. If the feature is not supported, it might make a good feature request.


1 Like

Hi @eyeveebee

I have started learning k6 for testing the our grpc apis ,

i am using client.connect and client.invoke like this

client.connect("__ENV.SERVER_URL, {reflect:true});

const response = client.invoke(`${__ENV.SERVICE_URL}.Package_Name/Method_Name `, message,params);

const params = { metadata :
{authorization : bearer token }

Hi @tjishant10,

can you confirm whether this happens on connect or on the invoke call.

I see that you use reflect:true and if this happens on the reflect call - you should send the bearer token with the connect.

This is/was not supported until the currently ongoing v0.47.0 release, which will hopefully finish tomorrow.

You can try to compile from source on top of adding reflectMetadata to the connect call (docs in progress).

Hope this helps you, and if it isn’t on the connect, can you please show the full error and give us the result of k6 vesion


Thanks @mstoykov , This is happening on connect , currently I am waiting for the reflectmetadata feature release , hopefully it will solve the problem… Thanks again


Hi @mstoykov , version 0.47.0 has been released, and I am using the {reflectMetadata} feature. It is exactly what we needed, and it is working well. Thank you!