'Axios post with Google Service Account OAUTH2

I was wondering how to implement a google authentication when sending a post request in NodeJs to a Google Python App. I cannot seem to find a direct solution anywhere. I have the .json file in my Node project. My request looks like this:

let options = {
  method: "POST",
  url: mainUrl,
  data: payload,
  authentication: auth,
    //auth = const auth = new google.auth.GoogleAuth({
  keyFile: "PathToMyJson.json",
  scopes: ["https://www.googleapis.com/auth/cloud-platform"],

}
axios
  .request(mainUrl, options)

  .then(function (response) {
    console.log(response.status)
    console.log(response.data)
  })

  .catch(function (error) {
    console.error(error.response)
    console.trace(error)
  })

I am not sure if this is the right approach, however.

Any help is much appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source