firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.13k stars 244 forks source link

WithCredentialsJSON and WithHTTPClient options doesn't work together #400

Closed asidorochev closed 3 years ago

asidorochev commented 3 years ago

Environments

The problem

Steps to reproduce:

If I use only WithCredentialsJSON option to create Firebase App, it works with no problem. But if I use both WithCredentialsJSON and WithHTTPClient options, I got error while sending message: "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."

Working code:

opt := []option.ClientOption{
    option.WithCredentialsJSON(credentials),
}

app, _ := firebase.NewApp(ctx, config, opt...)
client, _ := app.Messaging(ctx)
_, err := client.Send(ctx, message)

Not working code:

opt := []option.ClientOption{
    option.WithCredentialsJSON(credentials),
    option.WithHTTPClient(&http.Client{}),
}

app, _ := firebase.NewApp(ctx, config, opt...)
client, _ := app.Messaging(ctx)
_, err := client.Send(ctx, message)
google-oss-bot commented 3 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

hiranya911 commented 3 years ago

Unfortunately that's by design. The documentation mentions this:

When used, the WithHTTPClient option takes precedent over all other supplied options.

If you think this behavior should change I'd advise filing an issue at https://github.com/googleapis/google-api-go-client

The only other alternative is to initialize an oauth2.Transport instance with the right credentials, and pass that into your http.Client. See the examples in https://github.com/firebase/firebase-admin-go/issues/397#issuecomment-676856380