@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
48 lines (46 loc) • 2.21 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 request_promise_native_1 = require("request-promise-native");
class FacebookSignIn {
constructor(options) {
this._clientId = options.clientId;
this._secret = options.secret;
this._getRequest = options.get || request_promise_native_1.get;
}
verify(token, fields = 'email') {
return __awaiter(this, void 0, void 0, function* () {
const tokenResponse = yield this._getRequest(`${FacebookSignIn._RECAPTCHA_URL}/debug_token?input_token=${token}&access_token=${this._clientId}|${this._secret}`);
const tokenData = JSON.parse(tokenResponse);
if (tokenData.data.is_valid && String(tokenData.data.app_id) === this._clientId) {
const accountDataResponse = yield this._getRequest(`${FacebookSignIn._RECAPTCHA_URL}/${tokenData.data.user_id}?access_token=${token}&fields=${fields}`);
return JSON.parse(accountDataResponse);
}
return false;
});
}
}
FacebookSignIn._RECAPTCHA_URL = 'https://graph.facebook.com';
exports.FacebookSignIn = FacebookSignIn;
exports.default = FacebookSignIn;