How to use the google-auth-library.auth function in google-auth-library

To help you get started, we’ve selected a few google-auth-library examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ONEARMY / community-platform / functions / src / Firebase / databaseBackup.ts View on Github external
export const BackupDatabase = async () => {
  console.log('executing database backup')
  // TODO - no longer using util auth, should revise code to see if still relevant or not
  const auth = await google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/datastore'],
  })
  const accessTokenResponse = await auth.getAccessToken()
  const accessToken = accessTokenResponse.token
  const headers = {
    'Content-Type': 'application/json',
    Authorization: 'Bearer ' + accessToken,
  }

  console.log('access token received', accessToken)
  const PROJECT_ID = SERVICE_ACCOUNT_CONFIG.project_id

  const url = `https://firestore.googleapis.com/v1beta1/projects/${PROJECT_ID}/databases/(default):exportDocuments`
  // use axios to send post request as promise
  console.log('posting', url)
  const timestamp = dateformat(Date.now(), 'yyyy-mm-dd-HH-MM-ss')