Proxy in Google Play Integrity Library

45 views
Skip to first unread message

Fawkes

unread,
Nov 7, 2024, 1:49:27 PMNov 7
to golang-nuts
Hi,
Im trying to pass a proxy URL into the Play integrity library, but for some reason the http transport which Im passing onto the client is not working as expected. It would be helpful if anyone can guide me in this. Thanks in advance.

Here is my code:
ctx := context.Background()
credentials, err := ioutil.ReadFile("../googlecredentialsfile.json")
if err != nil {
return nil, err
}

config, err := google.JWTConfigFromJSON(credentials, playintegrity.PlayintegrityScope)
if err != nil {
return nil, err
}

var client *http.Client
if viper.GetString("ENABLE_PROXY") == "TRUE" {
// Set up an HTTP transport that uses the proxy
proxyUrl := viper.GetString("PROXY_URL")
proxy, _ := url.Parse(proxyUrl)
transport := &http.Transport{
Proxy: http.ProxyURL(proxy),
}

// Create an OAuth2 token source using the JWT config
tokenSource := config.TokenSource(ctx)

// Create a new http.Client with custom transport for proxy and OAuth2
client = &http.Client{
Transport: &oauth2.Transport{
Base: transport,
Source: tokenSource,
},
}
else {
// No proxy, just use the default client with OAuth2
client = config.Client(ctx)
}

// Create the Play Integrity service with the HTTP client
playIntegrityService, err := playintegrity.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}
.....

The traffic is not going via the proxy URL which results in getting a server misbehaving error from the google's library. 
Reply all
Reply to author
Forward
0 new messages