firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.16k stars 248 forks source link

Proxy problem #657

Open xonio-x opened 1 day ago

xonio-x commented 1 day ago

Hi, i try my code to running inside our internal server, after i add the proxy i got error Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential

i already double check and try the env is same and correct like my local and is running without proxy

package firebase

import (
  "context"
  "encoding/base64"
  firebase "firebase.google.com/go/v4"
  google "google.golang.org/api/option"
  "net/http"
  "net/url"

  "github.com/bytedance/sonic"

  "go.brimola.bri.co.id/libs/config"
)

type (
  Client struct {
    *firebase.App
  }
)

func NewClient(config *config.Config) (*Client, error) {
  decodedPrivateKey, err := base64.StdEncoding.DecodeString(config.Message.FCM.PrivateKey)
  if err != nil {
    return nil, err
  }

  config.Message.FCM.PrivateKey = string(decodedPrivateKey)
  serviceAccount, err := sonic.Marshal(config.Message.FCM)
  if err != nil {
    return nil, err
  }

  proxyURL, err := url.Parse(config.Message.FCM.Proxy)
  if err != nil {
    return nil, err
  }

  httpClient := &http.Client{
    Transport: &http.Transport{
      Proxy: http.ProxyURL(proxyURL),
    },
  }

  firebaseAdmin, err := firebase.NewApp(context.Background(), nil, google.WithHTTPClient(httpClient), google.WithCredentialsJSON(serviceAccount))
  if err != nil {
    return nil, err
  }

  return &Client{firebaseAdmin}, nil
}
google-oss-bot commented 1 day ago

I found a few problems with this issue: