@coolgk/utils
Version:
javascript, typescript utility and wrapper functions and classes: array, string, base64, ampq, bcrypt, cache, captcha, csv, email, jwt, number, pdf, tmp, token, unit conversion, url params, session, form data, google sign in, facebook sign in
53 lines (51 loc) • 1.99 kB
JavaScript
/*!
* @package @coolgk/utils
* @version 3.1.4
* @link https://github.com/coolgk/node-utils
* @license MIT
* @author Daniel Gong <daniel.k.gong@gmail.com>
*
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
;
/*!
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const google_auth_library_1 = require("google-auth-library");
class GoogleSignIn {
constructor(options) {
this._clientId = options.clientId;
this._oAuth2Client = options.oAuth2Client || new google_auth_library_1.OAuth2Client(this._clientId);
}
verify(token) {
return __awaiter(this, void 0, void 0, function* () {
try {
const ticket = yield this._oAuth2Client.verifyIdToken({
idToken: token,
audience: this._clientId
});
if (ticket) {
const payload = ticket.getPayload();
return payload || false;
}
return false;
}
catch (error) {
return false;
}
});
}
}
exports.GoogleSignIn = GoogleSignIn;
exports.default = GoogleSignIn;