Skip to content

Proxy problem  #657

@xonio-x

Description

@xonio-x

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
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions