Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getMetadata() {
// Get the project information from GCP
if (!dryRunMode) projectId = await google.auth.getProjectId();
if (!dryRunMode) zone_name = await getZoneName();
if (!dryRunMode) cluster_name = await getClusterName();
}
) {
throw new JovoError(
'Please add a valid keyFile object to the GoogleAssistant transaction config',
ErrorCode.ERR,
'jovo-platform-googleassistant',
);
}
/**
* DigitalGoods.ts needs the googleapis package to function.
* To reduce overall package size, googleapis wasn't added as a dependency.
* googleapis has to be manually installed
*/
try {
const googleapis = require('googleapis').google;
return googleapis.auth
.getClient({
keyFile: this.googleAssistant.config.transactions!.keyFile,
scopes: ['https://www.googleapis.com/auth/actions.purchases.digital'],
})
.then((client: any) => client.authorize()) // tslint:disable-line
.then((authorization: any) => authorization.access_token as string); // tslint:disable-line
} catch (e) {
console.log(e);
console.log(e.stack);
if (e.message === "Cannot find module 'googleapis'") {
return Promise.reject(
new JovoError(
e.message,
ErrorCode.ERR,
'jovo-platform-googleassistant',
undefined,
async function listVMs() {
// [START auth]
const authClient = await google.auth.getClient({
scopes: [
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/compute',
'https://www.googleapis.com/auth/compute.readonly',
],
});
// [END auth]
// [START list]
const projectId = await google.auth.getProjectId();
const result = await compute.instances.aggregatedList({
auth: authClient,
project: projectId,
});
const vms = result.data;
console.log('VMs:', vms);
function getUser(authorizationCode, callback) {
var client = new google.auth.OAuth2(
config.oauth2.clientId,
config.oauth2.clientSecret,
config.oauth2.redirectUrl
);
// With the code returned from OAuth flow, get an access token
client.getToken(authorizationCode, function(err, tokens) {
if (err) return callback(err);
// Configure this Google API client to use the access token
client.setCredentials(tokens);
// Call the Google+ API to get the profile of the user who authenticated
google.plus('v1').people.get({ userId: 'me', auth: client }, function(err, profile) {
if (err) return callback(err);
var user = {
id: profile.data.id,
name: profile.data.displayName,
imageUrl: profile.data.image.url
async function runSample() {
// acquire an authentication client using a service account
const auth = await google.auth.getClient({
keyFile: path.join(__dirname, '../jwt.keys.json'),
scopes: [
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member',
],
});
// obtain the admin client
const admin = google.admin({
version: 'directory_v1',
auth,
});
// Delete member from Google group
const res = await admin.members.delete({
groupKey: 'my_group@example.com',
function getAuthenticationUrl() {
var client = new google.auth.OAuth2(
config.oauth2.clientId,
config.oauth2.clientSecret,
config.oauth2.redirectUrl
);
// Use 'profile' scope to authorize fetching the user's profile
return client.generateAuthUrl({ scope: ['profile'] });
}
export function getOAuthClient() {
// Authorize a client with credentials, then call the Google Sheets API.
const credentials = {
installed: {
client_id: process.env.GOOGLE_SHEETS_CLIENT_ID,
project_id: process.env.GOOGLE_SHEETS_PROJECT_ID,
auth_uri: "https://accounts.google.com/o/oauth2/auth",
token_uri: "https://oauth2.googleapis.com/token",
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
client_secret: process.env.GOOGLE_SHEETS_SECRET,
redirect_uris: ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
}
};
const { client_secret, client_id, redirect_uris } = credentials.installed;
const oAuth2Client = new google.auth.OAuth2(
client_id,
client_secret,
redirect_uris[0]
);
oAuth2Client.on("tokens", tokens => {
if (tokens.refresh_token) {
// store the refresh_token in my database!
App.googleSheetsTokens.refresh_token = tokens.refresh_token;
}
});
if (App.googleSheetsTokens && App.googleSheetsTokens.access_token) {
oAuth2Client.setCredentials(App.googleSheetsTokens);
}
return oAuth2Client;
}
import Bootstrap from 'R/Bootstrap'
import querystring from 'querystring'
import { google } from 'googleapis'
import FetchService from 'shared/FetchService'
const gmail = google.gmail('v1')
const oauth2 = google.oauth2('v2')
const OAuth2 = google.auth.OAuth2
const { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET } = Bootstrap.credentials
class GoogleHTTP {
/* **************************************************************************/
// Utils
/* **************************************************************************/
/**
* Rejects a call because the mailbox has no authentication info
* @param info: any information we have
* @return promise - rejected
*/
static _rejectWithNoAuth (info) {
return Promise.reject(new Error('Mailbox missing authentication information'))
}
function mockRequests() {
simple.mock(googleapis.auth.JWT.prototype, "authorize").resolveWith({
access_token: "access_token",
});
}
async function initialize() {
if (!pubsub) {
const auth = await google.auth.getClient({
scopes: ["https://www.googleapis.com/auth/cloud-platform"]
});
google.options({
auth,
retryConfig: {
retry: 3,
noResponseRetries: 3,
shouldRetry: shouldRetryRequest(console.log)
}
});
pubsub = google.pubsub("v1");
}
}