How to use the google-auth-library.JWT 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 googleapis / google-auth-library-nodejs / system-test / fixtures / kitchen / src / index.ts View on Github external
import {GoogleAuth, JWT} from 'google-auth-library';
// uncomment the line below during development
// import {GoogleAuth} from '../../../../build/src/index';
const jwt = new JWT();
const auth = new GoogleAuth();
async function getToken() {
  const token = await jwt.getToken('token');
  const projectId = await auth.getProjectId();
  const creds = await auth.getApplicationDefault();
  return token;
}
getToken();
github googleapis / google-auth-library-nodejs / samples / jwt.js View on Github external
async function main(
  // Full path to the sevice account credential
  keyFile = process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
  const keys = require(keyFile);
  const client = new JWT({
    email: keys.client_email,
    key: keys.private_key,
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  const url = `https://dns.googleapis.com/dns/v1/projects/${keys.project_id}`;
  const res = await client.request({url});
  console.log('DNS Info:');
  console.log(res.data);

  // After acquiring an access_token, you may want to check on the audience, expiration,
  // or original scopes requested.  You can do that with the `getTokenInfo` method.
  const tokenInfo = await client.getTokenInfo(client.credentials.access_token);
  console.log(tokenInfo);
}
github dpa99c / cordova-plugin-firebasex-test / scripts / sendMessage.js View on Github external
reject(messageFileName+'  not found in messages/ - please use the --message parameter to specify a message file in the messages/ directory');
            return;
        }

        if(!isTopicMessage){
            message.token = deviceToken;
        }
        message = {
            message: message,
            validate_only: false
        };

        const googleAuth = require('google-auth-library');

        _projectId = serviceAccount.project_id;
        _jwtClient = new googleAuth.JWT(
            serviceAccount.client_email,
            null,
            serviceAccount.private_key,
            ['https://www.googleapis.com/auth/firebase.messaging'],
            null
        );

        _jwtClient.authorize(function(error, tokens) {
            if (error) {
                reject(error);
                return;
            }
            resolve();
        });
    });
};
github googleapis / google-auth-library-nodejs / samples / iap.js View on Github external
async function main() {
  const clientId = oauth2Keys.web.client_id;
  const client = new JWT({
    email: keys.client_email,
    key: keys.private_key,
    additionalClaims: {target_audience: clientId},
  });
  const url = `https://iap-demo-dot-el-gato.appspot.com`;
  const res = await client.request({url});
  console.log(res.data);
}
github cloudsploit / scans / helpers / google / index.js View on Github external
var authenticate = async function(GoogleConfig) {
    const client = new JWT({
        email: GoogleConfig.client_email,
        key: GoogleConfig.private_key,
        scopes: ['https://www.googleapis.com/auth/cloud-platform'],
    });
    return client;
};
github yuanqing / cuba / src / get-access-token.js View on Github external
module.exports = async function (serviceAccountCredentials) {
  const jwtClient = new JWT({
    email:
      serviceAccountCredentials.clientEmail ||
      serviceAccountCredentials.client_email,
    key:
      serviceAccountCredentials.privateKey ||
      serviceAccountCredentials.private_key,
    scopes
  })
  const authorize = promisify(jwtClient.authorize).bind(jwtClient)
  const accessToken = await authorize()
  return accessToken.access_token
}
github The-Politico / gootenberg / dist / module.js View on Github external
credentials = _context.sent;
            _context.next = 7;
            break;

          case 6:
            if (_typeof(config) === 'object') {
              credentials = config;
            } else if (config === undefined) {
              credentials = {
                client_email: process.env.GAPI_CLIENT_EMAIL,
                private_key: process.env.GAPI_PRIVATE_KEY.replace(/\\n/g, '\n')
              };
            }

          case 7:
            this.client = new JWT({
              email: credentials['client_email'],
              key: credentials['private_key'],
              scopes: ['https://www.googleapis.com/auth/drive']
            });
            _context.next = 10;
            return this.client.authorize();

          case 10:
            return _context.abrupt("return", this);

          case 11:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
github jovotech / jovo-framework / jovo-integrations / jovo-nlu-dialogflow / src / DialogflowNlu.ts View on Github external
}
    }

    const fileExists = await exists(this.config.credentialsFile);
    if (!fileExists) {
      if (this.config.requireCredentialsFile === false) {
        return;
      } else {
        throw new Error(`Credentials file doesn't exist in ${this.config.credentialsFile}`);
      }
    }

    const results = await readFile(this.config.credentialsFile);
    const keyFileObject = JSON.parse(results.toString());

    const jwtClient = new JWT(
      keyFileObject.client_email,
      undefined,
      keyFileObject.private_key,
      ['https://www.googleapis.com/auth/dialogflow'],
      undefined,
    );
    jwtClient.projectId = keyFileObject.project_id;

    return jwtClient;
  }
github The-Politico / gootenberg / src / auth / jwt.js View on Github external
export default async function(config) {
  let credentials;

  if (typeof config === 'string') {
    credentials = await readJSON(config);
  } else if (typeof config === 'object') {
    credentials = config;
  } else if (config === undefined) {
    credentials = {
      client_email: process.env.GAPI_CLIENT_EMAIL,
      private_key: process.env.GAPI_PRIVATE_KEY.replace(/\\n/g, '\n'),
    };
  }

  this.client = new JWT({
    email: credentials['client_email'],
    key: credentials['private_key'],
    scopes: ['https://www.googleapis.com/auth/drive'],
  });

  await this.client.authorize();
  return this;
};
github The-Politico / gootenberg / dist / auth / jwt.js View on Github external
exports.default = async function (config) {
  let credentials;

  if (typeof config === 'string') {
    credentials = await (0, _fsExtra.readJSON)(config);
  } else if (typeof config === 'object') {
    credentials = config;
  } else if (config === undefined) {
    credentials = {
      client_email: process.env.GAPI_CLIENT_EMAIL,
      private_key: process.env.GAPI_PRIVATE_KEY.replace(/\\n/g, '\n')
    };
  }

  this.client = new _googleAuthLibrary.JWT({
    email: credentials['client_email'],
    key: credentials['private_key'],
    scopes: ['https://www.googleapis.com/auth/drive']
  });
  await this.client.authorize();
  return this;
};