Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if the login token is not verified, returns an error reason
// CouldNotVerifyToken
// if the user is not registered, return a reason NoUser
import util from 'util';
import GoogleAuth from 'google-auth-library';
import mongoose from 'mongoose';
import credentialsClient from '../credentials-client';
import { makeError }
from '../_common/express-helpers';
let User;
const googleAuth = new GoogleAuth();
const client
= new googleAuth.OAuth2(credentialsClient.googleClientId, '', '');
export default async function authUserGoogle(idToken, isProduction = true) {
if (!User) {
User = mongoose.model('User');
}
return new Promise((resolve, _) => {
// the only reference to the function verifyIdToken I could find is at
// https://developers.google.com/identity/sign-in/web/backend-auth
client.verifyIdToken(
idToken,
credentialsClient.googleClientId,
// I assume e is for errors
export const getOauth2Client = ({ accessToken, refreshToken } = {}) => {
const credentials = CREDENTIALS.web || CREDENTIALS.installed;
if (!credentials) {
throw new Error("client-secret.json doesn't exist in root folder!");
}
const clientId = credentials.client_id;
const clientSecret = credentials.client_secret;
const redirectUrl = credentials.redirect_uris[0];
const auth = new googleAuth();
const oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
oauth2Client.credentials = {
...(accessToken ? { access_token: accessToken } : undefined),
...(refreshToken ? { refresh_token: refreshToken } : undefined)
};
return oauth2Client;
};
import googleAuth from 'google-auth-library';
import * as cache from './utils/cache';
let config;
try {
config = require(path.join(process.cwd(), '.blessedstanduprc'));
} catch(e) {
throw new Error(
'blessed-standup requires a `.blessedstanduprc` file containing a Google ' +
'OAuth `CLIENT_ID` and `CLIENT_SECRET`.'
);
}
const PERMISSION_SCOPE = 'https://spreadsheets.google.com/feeds';
const OAuth2Client = new googleAuth().OAuth2;
const client = new OAuth2Client(
config.CLIENT_ID,
config.CLIENT_SECRET,
'urn:ietf:wg:oauth:2.0:oob'
);
const url = client.generateAuthUrl({
access_type: 'offline',
scope: PERMISSION_SCOPE
});
class Login extends Component {
constructor(props, context) {
super(props, context);
this._onFocus = this._onFocus.bind(this);
constructor(ssKey, authId, options) {
this._ssKey = ssKey
this._authId = authId
this._googleAuth = null
this._visibility = 'public'
this._projection = 'values'
this._authMode = 'anonymous'
this._authClient = new GoogleAuth()
this._options = options || {}
this._xmlParser = new xml2js.Parser({
explicitArray: false,
explicitRoot: false
})
if (!ssKey) {
throw new Error('Spreadsheet key not provided')
}
this._setAuthAndDependencies(authId)
}