How to use the google-auth-library.auth.fromJSON 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 nytimes / library / server / auth.js View on Github external
return inflight('auth', async () => {
    // In Heroku environment, set GOOGLE_APPLICATION_CREDENTIALS as auth json object to be parsed
    try {
      const keys = JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS)
      authClient = nodeAuth.fromJSON(keys)
    } catch (err) {
      log.info('Couldn\'t get auth client credentials', err.message)
      const {credential} = await google.auth.getApplicationDefault()
      authClient = credential
    }

    if (authClient.createScopedRequired && authClient.createScopedRequired()) {
      authClient = authClient.createScoped([
        'https://www.googleapis.com/auth/drive',
        'https://www.googleapis.com/auth/cloud-platform',
        'https://www.googleapis.com/auth/datastore'
      ])
    }
    google.options({auth: authClient})
    log.info('Google API auth successfully retrieved.')
github nytimes / library / server / auth.js View on Github external
return inflight('auth', async () => {
    const credentialPath = process.env.GOOGLE_APPLICATION_CREDENTIALS

    // In Heroku environment, set GOOGLE_APPLICATION_CREDENTIALS to 'parse_json' to avoid introducing new file
    if (credentialPath === 'parse_json') {
      log.info('Trying to parse client credentials via GOOGLE_APPLICATION_JSON.')
      const keys = JSON.parse(process.env.GOOGLE_APPLICATION_JSON)
      authClient = nodeAuth.fromJSON(keys)
    } else {
      const {credential} = await google.auth.getApplicationDefault()
      authClient = credential
    }

    if (authClient.createScopedRequired && authClient.createScopedRequired()) {
      authClient = authClient.createScoped([
        'https://www.googleapis.com/auth/drive',
        'https://www.googleapis.com/auth/cloud-platform',
        'https://www.googleapis.com/auth/datastore'
      ])
    }
    google.options({auth: authClient})
    log.info('Google API auth successfully retrieved.')

    return authClient
github googleapis / google-auth-library-nodejs / samples / fromJSON.js View on Github external
async function main() {
  const client = auth.fromJSON(keys);
  client.scopes = ['https://www.googleapis.com/auth/cloud-platform'];
  const url = `https://www.googleapis.com/dns/v1/projects/${keys.project_id}`;
  const res = await client.request({url});
  console.log(res.data);
}