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 main() {
try {
// create an oAuth client to authorize the API call. Secrets are kept in a `keys.json` file,
// which should be downloaded from the Google Developers Console.
const client = new OAuth2Client(
keys.web.client_id,
keys.web.client_secret,
keys.web.redirect_uris[0]
);
client.on('tokens', tokens => {
// You'll get a refresh token the first time the user authorizes this app.
// You can always ask for another access_token using this long lived token.
// Make sure to store it somewhere safe!
if (tokens.refresh_token) {
// store me somewhere safe!
console.log(`Refresh Token: ${tokens.refresh_token}`);
}
// You'll also get new access tokens here! These tokens expire frequently,
// but as long as client.credentials.refresh_token is set, we can ask for
// another one.
async function authorizeWithoutLocalhost(
oAuth2ClientOptions: OAuth2ClientOptions,
oAuth2ClientAuthUrlOpts: GenerateAuthUrlOpts): Promise {
const client = new OAuth2Client({
...oAuth2ClientOptions,
redirectUri: REDIRECT_URI_OOB,
});
const authUrl = client.generateAuthUrl(oAuth2ClientAuthUrlOpts);
console.log(LOG.AUTHORIZE(authUrl));
// TODO Add spinner
const authCode = await new Promise((res, rej) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(LOG.AUTH_CODE, (code: string) => {
if (code && code.length) {
res(code);
} else {
rej('No authorization code entered.');
function authorize(credentials, callback) {
let clientSecret = credentials.web.client_secret;
let clientId = credentials.web.client_id;
let redirectUrl = "http://atomos.org.uk/ytcallback";
let oauth2Client = new OAuth2Client(clientId, clientSecret, redirectUrl);
// Check if we have previously stored a token.
fs.readFile(TOKEN_PATH, function (err, token) {
if (err) {
location.replace("file:///" + __dirname + "/home.html");
} else {
oauth2Client.credentials = JSON.parse(token);
callback(oauth2Client);
}
});
}
let subVideos = [];
function afterSheetGoogleId(
validatedUser,
sheetDbResult,
parsedSheet,
req,
res,
errorHandler
) {
// User data init
const sheets = google.sheets("v4"),
oAuth2Client = new googleAuthLib.OAuth2Client(
authConfig.google.clientID,
authConfig.google.clientSecret
);
oAuth2Client.setCredentials({
access_token: validatedUser.accessToken,
refresh_token: validatedUser.refreshToken
});
// POSTed data
const condition = req.body.condition,
toSet = req.body.set,
limit = req.body.limit ? req.body.limit : parsedSheet.length - 1;
// Loop through all rows, check if it matches. If it does, add the row number (range) to allRanges
const allRanges = [];
return new Promise((resolve, reject) => {
const oAuth2Client = new OAuth2Client(googleConfig.clientId, googleConfig.clientSecret)
oAuth2Client.verifyIdToken({
idToken: googleUserToken,
audience: googleConfig.clientId
}, (err, login) => {
if (err) {
log.warn(err)
return reject(err)
}
// If verified we can trust in the login.payload
return resolve(login.payload)
})
})
}
this.findOne({ googleId }, (err, result) => {
const now = new Date();
if (now.getTime() < result.expiresAt) {
const oauth2Client = new googleAuthLib.OAuth2Client(
googleOAuthConfig.clientID,
googleOAuthConfig.clientSecret,
googleOAuthConfig.callbackURL
);
oauth2Client.setCredentials({
refresh_token: result.refreshToken
});
oauth2Client.getAccessToken().then(response => {
this.findOneAndUpdate(
{ googleId },
{
$set: {
accessToken: response.token,
expiresAt: now.setTime(now.getTime() + 1000 * 3590) // A bit less than 1 hour
module.exports = (validUser, result, query, rowLimit = Infinity) => {
const sheets = google.sheets("v4"),
oauth2Client = new googleAuthLib.OAuth2Client(
googleOAuthConfig.clientID,
googleOAuthConfig.clientSecret,
googleOAuthConfig.callbackURL
);
oauth2Client.credentials = {
access_token: validUser.accessToken,
refresh_token: validUser.refreshToken
};
return new Promise((resolve, reject) => {
// Get data from spreadsheet
sheets.spreadsheets.values
.get({
auth: oauth2Client,
spreadsheetId: result.googleId,
function buildCredentials() {
const oauth2Client = new OAuth2Client('test', 'test', null);
oauth2Client.setCredentials({
'access_token':'abc',
'expires_in':3920,
'token_type':'Bearer'
});
return oauth2Client;
}
_context.next = 3;
return fsExtra.readJSON(config);
case 3:
credentials = _context.sent;
_context.next = 7;
break;
case 6:
if (_typeof(config) === 'object') {
credentials = config;
}
case 7:
_credentials$installe = credentials.installed, clientSecret = _credentials$installe.client_secret, clientId = _credentials$installe.client_id, redirectUris = _credentials$installe.redirect_uris;
this.client = new googleAuthLibrary.OAuth2Client(clientId, clientSecret, redirectUris[0]);
_context.next = 11;
return this.client.setCredentials(token);
case 11:
return _context.abrupt("return", this);
case 12:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
public async verifyProfile(): Promise {
const client = new OAuth2Client(this.platform.config.clientId);
const payload:
| TokenPayload
| undefined = await this.dialogflow.conv.user._verifyProfile(
client,
this.platform.config.clientId,
);
return payload;
}