{"size": 627, "ext": "js", "max_stars_repo_path": "api/app/modules/auth/google/validate-token.js", "max_stars_repo_name": "knightjdr/screenhits", "max_stars_repo_stars_event_min_datetime": "2018-02-21T18:48:44.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-08T04:19:42.000Z", "max_issues_repo_path": "api/app/modules/auth/google/validate-token.js", "max_issues_repo_name": "knightjdr/screenhits", "max_issues_repo_issues_event_min_datetime": "2018-02-23T22:02:35.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-20T19:56:02.000Z", "max_forks_repo_path": "api/app/modules/auth/google/validate-token.js", "max_forks_repo_name": "knightjdr/screenhits", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 25.08, "max_line_length": 62, "alphanum_fraction": 0.5821371611}
const config = require('../../../../config');
const GoogleAuth = require('google-auth-library');

const auth = new GoogleAuth();
const CLIENT_ID = config.settings().googleClientID;
const client = new auth.OAuth2(CLIENT_ID, '', '');

const Validate = (token) => {
  return new Promise((resolve, reject) => {
    client.verifyIdToken(
      token,
      CLIENT_ID,
      (err, login) => {
        if (err) {
          reject('User could not be authenticated by Google');
        } else {
          const payload = login.getPayload();
          resolve(payload.email);
        }
      }
    );
  });
};
module.exports = Validate;
