You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';
constfs=require('fs');
constpath=require('path');
consthttp=require('http');
consturl=require('url');
constopn=require('open');
constdestroyer=require('server-destroy');
const{google}=require('googleapis');
constpeople=google.people('v1');
/**
* To use OAuth2 authentication, we need access to a CLIENT_ID, CLIENT_SECRET, AND REDIRECT_URI. To get these credentials for your application, visit https://console.cloud.google.com/apis/credentials.
* Create a new OAuth2 client with the configured keys.
*/
constoauth2Client=newgoogle.auth.OAuth2(
keys.client_id,
keys.client_secret,
keys.redirect_uris[0],
);
/**
* This is one of the many ways you can configure googleapis to use authentication credentials. In this method, we're setting a global reference for all APIs. Any other API you use here, like `google.drive('v3')`, will now use this auth client. You can also override the auth client at the service and method call levels.
*/
google.options({auth: oauth2Client});
/**
* Open an http server to accept the oauth callback. In this simple example, the only request to our webserver is to `/callback?code=<code>`
*/
asyncfunctionauthenticate(scopes){
returnnewPromise((resolve,reject)=>{
// grab the url that will be used for authorization