Refactor all auth adapters to reduce duplications (#4954)

* Refactor all auth adapters to reduce duplications

* Adds mocking and proper testing for all auth adapters

* Proper testing of the google auth adapter

* noit
This commit is contained in:
Florent Vilmart
2018-08-12 11:05:28 -04:00
committed by GitHub
parent f1b008388c
commit b9673da07b
16 changed files with 214 additions and 320 deletions

View File

@@ -1,32 +1,9 @@
const crypto = require('crypto');
const https = require('https');
const httpsRequest = require('./httpsRequest');
const Parse = require('parse/node').Parse;
const graphRequest = (path) => {
return new Promise((resolve, reject) => {
https.get(`https://graph.accountkit.com/v1.1/${path}`, (res) => {
var data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
data = JSON.parse(data);
if (data.error) {
// when something wrong with fb graph request (token corrupted etc.)
// instead of network issue
reject(data.error);
} else {
resolve(data);
}
} catch (e) {
reject(e);
}
});
}).on('error', function () {
reject('Failed to validate this access token with Facebook Account Kit.');
});
});
return httpsRequest.get(`https://graph.accountkit.com/v1.1/${path}`);
};
function getRequestPath(authData, options) {
@@ -60,6 +37,9 @@ function validateAppId(appIds, authData, options) {
function validateAuthData(authData, options) {
return graphRequest(getRequestPath(authData, options))
.then(data => {
if (data && data.error) {
throw data.error;
}
if (data && data.id == authData.id) {
return;
}