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

transport/grpc: support option.WithAPIKey #485

Closed
broady opened this issue Sep 20, 2019 · 5 comments · Fixed by #2326
Closed

transport/grpc: support option.WithAPIKey #485

broady opened this issue Sep 20, 2019 · 5 comments · Fixed by #2326
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@broady
Copy link
Contributor

broady commented Sep 20, 2019

google.golang.org/ap/option says:

API Keys can only be used for JSON-over-HTTP APIs, including those under the import path google.golang.org/api/....

Not true, though, API keys can be used with gRPC.

Need to use the x-api-key metadata key:

ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs("x-api-key", ...))
@codyoss codyoss self-assigned this May 12, 2020
@codyoss codyoss transferred this issue from googleapis/google-cloud-go May 18, 2020
@codyoss codyoss added the type: docs Improvement to the documentation for an API. label May 18, 2020
@broady broady added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed type: docs Improvement to the documentation for an API. labels May 18, 2020
@broady
Copy link
Contributor Author

broady commented May 18, 2020

sorry, reading this now it doesn't look like a doc bug.

@broady broady changed the title option: incorrect doc about API keys transport/grpc: support option.WithAPIKey May 18, 2020
@broady
Copy link
Contributor Author

broady commented May 18, 2020

if o.APIKey != "" {
log.Print("API keys are not supported for gRPC APIs. Remove the WithAPIKey option from your client-creating call.")
}

@broady
Copy link
Contributor Author

broady commented Oct 25, 2022

Workaround for "API keys are not supported for gRPC APIs. Remove the WithAPIKey option from your client-creating call."

Append the API key to the context used for the request (not for client creation).

ctx = metadata.AppendToOutgoingContext(ctx, "x-goog-api-key", key)

Then provide some dummy authentication:

option.WithTokenSource(oauth2.StaticTokenSource(&oauth2.Token{}))

@zhoub
Copy link

zhoub commented May 8, 2023

Any better fix for this issue ?

@codyoss
Copy link
Member

codyoss commented May 8, 2023

@zhoub As of right now, I think this is still the best solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants