How to use the googleapis.auth function in googleapis

To help you get started, we’ve selected a few googleapis 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 fluidtrends / chunky / cli / src / providers.js View on Github external
return new Promise((resolve, reject) => {
    if (!config.google || !config.google.serviceAccount) {
      // reject(new Error('Invalid Google secure configuration'))
      resolve()
      return
    }

    let googleAuth = new google.auth.JWT(
           config.google.serviceAccount.client_email,
           null,
           config.google.serviceAccount.private_key,
           config.google.services.map(service => `https://www.googleapis.com/auth/${service}`))

    googleAuth.authorize((error, tokens) => {
      if (error) {
        reject(error)
        return
      }

      coreutils.logger.ok(`Connected to Google`)
      resolve({ name: 'google', provider: {
        api: google,
        options: config.google,
        auth: googleAuth
github angular / angular / tools / benchpress / src / cloud_reporter.es6 View on Github external
function authenticate(authConfig, retryCount) {
  var authClient = new google.auth.JWT(
    authConfig['client_email'],
    null,
    authConfig['private_key'],
    ['https://www.googleapis.com/auth/bigquery'],
    // User to impersonate (leave empty if no impersonation needed)
    null);

  var defer = webdriver.promise.defer();
  authClient.authorize(makeNodeJsResolver(defer));
  var resultPromise = defer.promise.then(function() {
    return authClient;
  });
  resultPromise = retryIfNeeded(resultPromise, retryCount, function(newRetryCount) {
    return authenticate(authConfig, newRetryCount);
  });
  return resultPromise;
github mplacona / twilio-pa / app.js View on Github external
var config = require('./config');
var getConnection = require('./connection');

// Dependency setup
var express = require('express'),
  google = require('googleapis'),
  date = require('datejs'),
  twilio = require('twilio');

// Initialization
var app = express(),
  calendar = google.calendar('v3'),
  oAuthClient = new google.auth.OAuth2(config.googleConfig.clientID, config.googleConfig.clientSecret, config.googleConfig.redirectURL),
  tokenUtils = require('./token-utils')(oAuthClient);

// Schedule setup
var jobSchedule = require('./job-schedule.js'),
  smsJob = require('./jobs/send-sms.js'),
  callJob = require('./jobs/start-call.js');

// Event object
var CalendarEvent = function(id, description, location, startTime) {
  this.id = id;
  this.eventName = description;
  this.number = location;
  this.eventTime = Date.parse(startTime);
  this.smsTime = Date.parse(startTime).addMinutes(-5);
};
github rosshinkley / headless-google-auth / index.js View on Github external
var http = require('http'),
    google = require('googleapis'),
    spawn = require('child_process')
    .spawn,
    path = require('path'),
    OAuth2 = google.auth.OAuth2;

module.exports = exports = function(options, cb) {
    //ensure all of the required parts have been passed
    options.callbackUri = options.callbackUri || 'http://localhost:5678';
    options.port = options.port || 5678;
    options.accessType = options.accessType || 'online';
    if (!options.clientId) {
        return cb('No Google client ID specified.');
    }
    if (!options.clientSecret) {
        return cb('No Google client secret specified.');
    }
    if (!options.username) {
        return cb('No Google username specified.');
    }
    if (!options.password) {
github sfarthin / ga-analytics / module.js View on Github external
"\n Path to Private Key: " + settings.key +
					"\n Google Analytics view: " + GOOGLEAPI_ANALYTICS_TABLE;
		
		final_callback(new Error(error));
		return;
	}

	if(!settings.startDate)
		settings.startDate = moment().subtract(moment.duration(1, 'M')).format('YYYY-MM-DD');
	
	if(!settings.endDate)
		settings.endDate = moment(settings.startDate).add(moment.duration(1, 'M')).format('YYYY-MM-DD')


	var oauth2Client = new OAuth2(GOOGLEAPI_CLIENTID, null, 'postmessage'),
		jwt 		 = new googleapis.auth.JWT(GOOGLEAPI_EMAIL, GOOGLEAPI_KEY, null, ['https://www.googleapis.com/auth/analytics.readonly']);

	var authorize = function(callback) {
		fs.exists(sessionFile, function(exists) {
			if(exists) {
				fs.readFile(sessionFile, function(err, res) {
					if(err) {
						jwt.authorize(callback);
						return;
					}
					
					try {
						var json = JSON.parse(res);
					} catch(e) {
						jwt.authorize(callback);
						return;
					}
github soixantecircuits / altruist / actions / googledrive.js View on Github external
const google = require('googleapis')

const mmmagic = require('mmmagic')
const magic = new mmmagic.Magic(mmmagic.MAGIC_MIME_TYPE)

var driveSession = JSON.parse(localStorage.getItem('googledrive-session')) || { accessToken: '', refreshToken: '' }
var userProfile = JSON.parse(localStorage.getItem('googledrive-profile')) || {}
var uploadDirectoryID = settings.actions.googledrive.uploadDirectoryID ? settings.actions.googledrive.uploadDirectoryID : ''

const loginURL = settings.actions.googledrive.loginURL || '/login/gdrive'
const callbackURL = settings.actions.googledrive.callbackURL || '/login/gdrive/return'
const failureURL = settings.actions.googledrive.failureURL || '/?failure=drive'
const successURL = settings.actions.googledrive.successURL || '/?success=drive'
const profileURL = settings.actions.googledrive.profileURL || '/profile/gdrive'

var OAuth2 = google.auth.OAuth2
var googleAuth = new OAuth2(
  settings.actions.googledrive.clientID,
  settings.actions.googledrive.clientSecret,
  settings.actions.googledrive.callbackURL
)
var drive = google.drive({ version: 'v3', auth: googleAuth })

function storeTokens (atoken, rtoken) {
  driveSession.accessToken = atoken
  driveSession.refreshToken = rtoken
  localStorage.setItem('googledrive-session', JSON.stringify(driveSession))
}

function storeProfile (profile) {
  userProfile = profile
  localStorage.setItem('googledrive-profile', JSON.stringify(userProfile))
github wireapp / wire-desktop / electron / src / js / lib / googleAuth.ts View on Github external
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 *
 */

import {BrowserWindow} from 'electron';
import * as google from 'googleapis';
import * as qs from 'querystring';
import * as request from 'request';

import {GoogleAccessTokenResult} from '../../interfaces';

const OAuth2 = google.auth.OAuth2;

const authorizeApp = (url: string): Promise => {
  return new Promise((resolve, reject) => {
    const win = new BrowserWindow({
      title: '',
      useContentSize: true,
    });

    win.setMenuBarVisibility(false);
    win.loadURL(url);

    win.on('closed', () => reject(new Error('User closed the window')));

    win.on('page-title-updated', () => {
      setImmediate(() => {
        const title = win.getTitle();
github mozilla-frontend-infra / firefox-health-dashboard / src / perf.js View on Github external
const getSpreadsheetValues = async ({ id, range }) => {
  if (!jwtClient) {
    const jwtKey = JSON.parse(process.env.GAUTH_JSON);
    jwtClient = new google.auth.JWT(
      jwtKey.client_email,
      null,
      jwtKey.private_key,
      'https://spreadsheets.google.com/feeds',
      null,
    );
    await new Promise(resolve => jwtClient.authorize(resolve));
  }
  const { values } = await new Promise((resolve) => {
    const sheets = google.sheets('v4');
    sheets.spreadsheets.values.get(
      {
        auth: jwtClient,
        spreadsheetId: id,
        range: range,
      },
github SC5 / mozaik-ext-analytics / src / analyzer.js View on Github external
constructor(opts) {
    this.jwtClient = new googleapis.auth.JWT(
      opts.serviceEmail, null, opts.serviceKey, [
        'https://www.googleapis.com/auth/analytics',
        'https://www.googleapis.com/auth/analytics.readonly'
      ]
    );
  }