firebase-admin-go icon indicating copy to clipboard operation
firebase-admin-go copied to clipboard

Proxy problem

Open xonio-x opened this issue 1 year ago • 1 comments
trafficstars

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
}

xonio-x avatar Nov 21 '24 04:11 xonio-x