How to use the googleapis.oauth2 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 mattkrick / meatier / src / server / graphql / models / User / oauthGoogle.js View on Github external
import promisify from 'es6-promisify';
import google from 'googleapis';
import Schema from '../../rootSchema';
import {graphql} from 'graphql';

const OAuth2 = google.auth.OAuth2;
const oauth = google.oauth2('v2'); // v3 should come out soonish

export const oauth2Client = new OAuth2(process.env.GOOGLE_CLIENTID, process.env.GOOGLE_SECRET, process.env.GOOGLE_CALLBACK);
const getToken = promisify(oauth2Client.getToken.bind(oauth2Client));
const getUserInfo = promisify(oauth.userinfo.get.bind(oauth.userinfo));

export const googleAuthUrl = oauth2Client.generateAuthUrl({
  // approval_prompt: "force", //get the refresh_token every time (for debugging only)
  // access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
  scope: ['email', 'profile'] // If you only need one scope you can pass it as string
});

const userWithAuthToken = `
{
  user {
    id,
    email,
github letsdoitworld / World-Cleanup-Day / backend-auth / modules / social-auth / google.js View on Github external
'use strict';
const google = require('googleapis');

const auth = google.oauth2('v2');
const OAuth2 = google.auth.OAuth2;

const getUserData = token => {
    const authClient = new OAuth2();
    authClient.setCredentials({
        // eslint-disable-next-line camelcase
        access_token: token,
    });

    return new Promise((resolve, reject) => {
        auth.userinfo.v2.me.get(
            {
                fields: 'email,id,name,picture',
                auth: authClient,
            },
            function (err, res) {
github salrashid123 / gcpsamples / auth / service / nodeapp / app.js View on Github external
authClient.authorize(function(err, tokens) {
  if (err) {
    console.log(err);
    return;
  }    
  var service = google.oauth2({ version: 'v2', auth: authClient });    

  service.userinfo.get(function(err, info) {
   if (err) {
      logger.error(err);
      return;
   }      
   logger.info(info.email);
  });

});
github salrashid123 / gcpsamples / auth / userflow / nodeapp / app.js View on Github external
authClient.getToken(code, function(err, token) {
      if (err) {
        console.log('Error while trying to retrieve access token', err);
        return;
      }
      authClient.credentials = token;

      var service = google.oauth2('v2');

      service.userinfo.get({auth: authClient}, function(err, info) {
			logger.info(info.email);      
		});
    });
  });
github salrashid123 / gcpsamples / auth / compute / nodeapp / app.js View on Github external
//authClient.setCredentials({ access_token: 'abc123' });

var log4js = require("log4js");
var GoogleAuth = require('google-auth-library');
var google = require('googleapis');

var logger = log4js.getLogger();

var authClient = new google.auth.Compute();

if (authClient.createScopedRequired && authClient.createScopedRequired()) {
   authClient = authClient.createScoped(['https://www.googleapis.com/auth/userinfo.email']);
}

var service = google.oauth2({ version: 'v2', auth: authClient });
service.userinfo.get(function(err, info) {
   if (err) {
        logger.error(err);
        return;
   }
   logger.info(info.email);
});



const Storage = require('@google-cloud/storage');
const storage = new Storage({
  projectId: 'your-project',
});

storage.getBuckets(function(err, buckets) {
github dockerx / dockerbox / routes / gauth.js View on Github external
function setSessionData(req, oauth2Client, tokens, cb) {
  oauth2Client.setCredentials(tokens);
  gapi.oauth2("v2").userinfo.get({auth:oauth2Client}, function(err, results){
      req.session.user = results;
      cb();
  });
};
github mozilla / persona-gmail-bridge / lib / google.js View on Github external
function getUserInfo (oauthClient, callback) {
  if (!oauthClient.credentials) {
    return callback(new Error('missing Google OAuth client credentials'));
  }

  var userInfo = googleapis.oauth2('v2').userinfo;

  userInfo.get({ auth: oauthClient }, callback);
}
github bmathews / menubar-calendar / server / api / ProfileAPI.js View on Github external
import Q from 'q';
import google from 'googleapis';
const gauth = google.oauth2('v2');

export default class Profile {


  /*
   * Store the auth client to use with api calls
   */

  setAuth(oauth) {
    this.oauth = oauth;
  }


  /*
   * Use the oauth api to grab the current userinfo
   */