T-964120721843948: add utility function to passHTML encoded data back to tagfer-app

This commit is contained in:
Okechi Onyeje 2019-01-08 20:30:52 -05:00
parent 21e45aaf12
commit 82d578b279
3 changed files with 30 additions and 8 deletions

View File

@ -210,6 +210,7 @@ module.exports = {
signup,
sendPasswordResetEmail,
getTwitterToken,
getTwitterUsername,
getLinkedInLoginURL,
getLinkedInAccessToken,
getLinkedInProfile

View File

@ -14,13 +14,13 @@ function getOAuthLoginURL(callback) {
let linkedIn = appConfig.keys.linkedIn;
let linkedInRequest = _.cloneDeep(linkedIn.endpoints.request_token);
linkedInRequest.url = `${linkedInRequest.url}?client_id=${linkedIn.consumer.key}&scope=r_fullprofile%20r_basicprofile%20r_emailaddress&redirect_uri=${encodeURIComponent(linkedIn.redirect_uri)}&response_type=code`;
callback({ uri: linkedInRequest.url})
callback({ uri: linkedInRequest.url});
}
function getOAuthAccessToken(token, callback) {
let linkedIn = appConfig.keys.linkedIn;
let linkedInRequest = _.cloneDeep(linkedIn.endpoints.access_token);
let url = `${linkedInRequest.url}?code=${token}&client_id=${linkedIn.consumer.key}&client_secret=${linkedIn.consumer.secret}&grant_type=authorization_code&redirect_uri=${encodeURIComponent(linkedIn.redirect_uri)}`
let url = `${linkedInRequest.url}?code=${token}&client_id=${linkedIn.consumer.key}&client_secret=${linkedIn.consumer.secret}&grant_type=authorization_code&redirect_uri=${encodeURIComponent(linkedIn.redirect_uri)}`;
request({
url,
headers: {
@ -32,7 +32,7 @@ function getOAuthAccessToken(token, callback) {
} else {
callback({ error: errors.AUTH_LINKEDIN_ACCESS_TOKEN_FAILURE });
}
})
});
}
function getUserProfile(token, callback) {
@ -50,15 +50,14 @@ function getUserProfile(token, callback) {
if (!error) {
var body = JSON.parse(result.body);
if(body.serviceErrorCode) {
console.log(body.serviceErrorCode)
callback({ error: errors.AUTH_LINKEDIN_PROFILE_REQUEST_FAILURE });
} else {
callback(body);
}
} else {
callback({ error: errors.AUTH_LINKEDIN_PROFILE_REQUEST_FAILURE })
callback({ error: errors.AUTH_LINKEDIN_PROFILE_REQUEST_FAILURE });
}
})
});
}
module.exports = {

View File

@ -1,6 +1,7 @@
const OAuth = require('oauth-1.0a');
const crypto = require('crypto');
const UUID = require('uuid/v4');
const firebase = require('firebase-admin');
const appConfig = require('../../config/app.json');
const http = require('../../config/http');
const errors = require('../../config/errors');
@ -71,11 +72,32 @@ function createOAuthHeader(request, app) {
return oauth.toHeader(oauth.authorize(request, app.token));
}
const passingHTML = (result) => `
<!DOCTYPE HTML>
<html>
<body>
<script>
function waitForBridge() {
if(window.postMessage.length !== 1){
setTimeout(waitForBridge, 200);
}
else {
window.postMessage('${result}');
}
}
window.onload = waitForBridge;
</script>
</body>
</html>
`;
module.exports = {
isAppSecretValid,
isBodyValid,
getSessionIdFromAuthHeader,
isProfileNumberValid,
createOAuthHeader
createOAuthHeader,
passingHTML
};