Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass the authorization token as header information #424

Open
sharathchandramg opened this issue Aug 23, 2023 · 8 comments
Open

How to pass the authorization token as header information #424

sharathchandramg opened this issue Aug 23, 2023 · 8 comments

Comments

@sharathchandramg
Copy link

Hi,
I have my grpc service behind an API gateway. The gateway protects the service using an API key. I am able to use the above using grpcurl as follows:

grpcurl \
-H 'Authorization:<api_key>\
-d '{}' \
<endpoint>.cloudapp.azure.com:8080 \
<namespace>.HelloService/SayHello

I want to load test the same thing using ghz and I am facing issues in calling using the metadata

ghz \
-m '{"Authorization" : "<api_key>"}' \
--call <namespace>..HelloService/SayHello \
-d '{}' \
<endpoint>.cloudapp.azure.com:8080

I keep getting the error

rpc error: code = Unauthenticated desc = unexpected HTTP status code received from server: 401 (Unauthorized); transport: received unexpected content-type "application/json"
@KeganHollern
Copy link

Also having this issue

@is-jonreeves
Copy link

We are also running into the same issue. Requests work fine with grpcurl but not with ghz

Our Header format is Authorization: Bearer <token>.

@GoToCoding
Copy link

Try ghz --metadata="{\"authorization\": \"Bearer $TOKEN\"}"
It works fine for me.

@jwillker
Copy link

jwillker commented Aug 1, 2024

I have already tried many different ways to do that, and it still doesn't work with Ghz, but it perfectly works with grpcurl.

@softprops
Copy link

also seeing this what works grpcurl works with -H "Authorization: Bearer $TOKEN" but ghz does not with --metadata="{\"authorization\": \"Bearer $TOKEN\"}"

@softprops
Copy link

If it helps move things along here is what grpcurl does to tranform headers into metadata

@softprops
Copy link

I dug a little bit and found the issue is ghz only passes the metadata you provide with the requests you define. There is an explicit request it makes on your behalf if you do not provide an explicit proto or protoset to reflect over your service to get the info it needs to structure its requests called grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo.

ghz does not send the metadata you provide with the grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo request. In my case, this is what causes the cli to error out because authorization is needed for both that as well as the request I'm asking it to make.

@softprops
Copy link

there is however a work around which is to pass the same data passed with metadata with an additional reflect-metadata arg

ghz \
 --metadata="{\"authorization\": \"Bearer $TOKEN\"}"  \
 --reflect-metadata="{\"authorization\": \"Bearer $TOKEN\"}" \
 ...

I understand the value in having the flexibility but this is a bit of leaky abstraction for me and a detail callers shouldn't have to think about. I think the default should be to pass metadata in --metadata otherwise I assume this will just cause others the same confusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants