mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-964120721843948: Removed git erors from rebasing on another branch
This commit is contained in:
parent
b4b82d958c
commit
21e45aaf12
@ -30,7 +30,8 @@
|
||||
"phone": "^2.3.0",
|
||||
"request": "^2.88.0",
|
||||
"twilio": "^3.25.0",
|
||||
"uuid": "^3.3.2"
|
||||
"uuid": "^3.3.2",
|
||||
"oauth-1.0a": "^2.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.9.0",
|
||||
|
||||
@ -48,6 +48,31 @@
|
||||
"method": "POST"
|
||||
}
|
||||
}
|
||||
},
|
||||
"linkedIn": {
|
||||
"consumer": {
|
||||
"key": "77fpx2v0o6zqus",
|
||||
"secret": "7RfmnUs8amWvAoV8"
|
||||
},
|
||||
"token": {
|
||||
"key":"77fpx2v0o6zqus",
|
||||
"secret": "7RfmnUs8amWvAoV8"
|
||||
},
|
||||
"endpoints": {
|
||||
"request_token": {
|
||||
"url": "https://www.linkedin.com/oauth/v2/authorization",
|
||||
"method": "GET"
|
||||
},
|
||||
"access_token": {
|
||||
"url": "https://www.linkedin.com/oauth/v2/accessToken",
|
||||
"method": "POST"
|
||||
},
|
||||
"get_profile": {
|
||||
"url": "https://api.linkedin.com/v2/me",
|
||||
"method": "GET"
|
||||
}
|
||||
},
|
||||
"redirect_uri": "http://192.168.1.201:3000/auth/linkedin/token"
|
||||
}
|
||||
},
|
||||
"dbPath": {
|
||||
|
||||
@ -19,6 +19,10 @@ module.exports = {
|
||||
APP_NETWORK_TIMEOUT: 'app/network-timeout',
|
||||
APP_UNABLE_TO_PARSE_RESPONSE: 'app/unable-to-parse-response',
|
||||
APP_FIREBASE_DATABASE_ERROR: 'app/firebase-database-error',
|
||||
AUTH_LINKEDIN_REQUEST_HTML_FAILURE: 'auth/linkedin-request-html-failure',
|
||||
AUTH_LINKEDIN_REQUEST_TOKEN_FAILURE: 'auth/linkedin-request-token-failure',
|
||||
AUTH_LINKEDIN_ACCESS_TOKEN_FAILURE: 'auth/linkedin-access-token-failure',
|
||||
AUTH_LINKEDIN_PROFILE_REQUEST_FAILURE: 'auth/linkedin-profile-request-failure',
|
||||
//Request Errors
|
||||
MISSING_BODY_ATTRIBUTES: 'request/missing-body-attributes',
|
||||
//Profile Errors
|
||||
|
||||
@ -10,6 +10,9 @@ function router(app) {
|
||||
// Auth Endpoints
|
||||
app.get('/auth/twitter/token', AuthHandlers.getTwitterToken );
|
||||
app.get('/auth/twitter/username', AuthHandlers.getTwitterUsername );
|
||||
app.get('/auth/linkedin/login', AuthHandlers.getLinkedInLoginURL);
|
||||
app.get('/auth/linkedin/token', AuthHandlers.getLinkedInAccessToken);
|
||||
app.get('/auth/linkedin/get/profile', AuthHandlers.getLinkedInProfile);
|
||||
app.get('/auth/email/:email/exists', AuthHandlers.doesAttributeExist );
|
||||
app.get('/auth/tagferId/:tagferId/exists', AuthHandlers.doesAttributeExist );
|
||||
app.post('/auth/phone/code', AuthHandlers.sendPhoneCode);
|
||||
|
||||
@ -5,6 +5,7 @@ const errors = require('../../config/errors');
|
||||
const appConfig = require('../../config/app.json');
|
||||
const http = require('../../config/http');
|
||||
const twitter = require('../socials/twitter');
|
||||
const linkedin = require('../socials/linkedIn');
|
||||
|
||||
// Handlers
|
||||
/**
|
||||
@ -159,6 +160,48 @@ function getTwitterUsername(req, res) {
|
||||
twitter.getUsername(req.query, (result) => res.send(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint: auth/linkedin/html
|
||||
* Calls the linkedin endpoint to get the oauth url with clientId appended
|
||||
* @param {Object} req {}
|
||||
* @param {Object} res { result:{ uri: String} } | { error: String }
|
||||
*/
|
||||
function getLinkedInLoginURL(req, res) {
|
||||
if (!utils.isAppSecretValid(req,res)) {
|
||||
return;
|
||||
}
|
||||
linkedin.getOAuthLoginURL((result) => res.json(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint: auth/linkedin/token
|
||||
* Calls the linkedin endpoint from ui view in tagfer app, to get the `oauth access token`
|
||||
* @param {Object} req {}
|
||||
* @param {Object} res { String } | { error: String }
|
||||
*/
|
||||
function getLinkedInAccessToken(req, res) {
|
||||
const token = req.query.code;
|
||||
if (token) {
|
||||
linkedin.getOAuthAccessToken(token, (result) => res.send(result));
|
||||
} else {
|
||||
res.status(http.UNAUTHORIZED).json({ error: errors.AUTH_LINKEDIN_REQUEST_TOKEN_FAILURE });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint: auth/linkedin/get/profile
|
||||
* Calls the linkedin endpoint from
|
||||
* @param {Object} req {}
|
||||
* @param {Object} res { String } | { error: String }
|
||||
*/
|
||||
function getLinkedInProfile(req, res) {
|
||||
if (req.query.access_token && req.query.expires_in) {
|
||||
linkedin.getUserProfile(req.query.access_token, (result) => res.json(result));
|
||||
} else {
|
||||
res.status(http.UNAUTHORIZED).json({ error: errors.AUTH_LINKEDIN_PROFILE_REQUEST_FAILURE });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
doesAttributeExist,
|
||||
sendPhoneCode,
|
||||
@ -167,5 +210,7 @@ module.exports = {
|
||||
signup,
|
||||
sendPasswordResetEmail,
|
||||
getTwitterToken,
|
||||
getTwitterUsername
|
||||
getLinkedInLoginURL,
|
||||
getLinkedInAccessToken,
|
||||
getLinkedInProfile
|
||||
};
|
||||
68
src/ups/socials/linkedIn.js
Normal file
68
src/ups/socials/linkedIn.js
Normal file
@ -0,0 +1,68 @@
|
||||
const request = require('request');
|
||||
|
||||
const appConfig = require('../../config/app.json');
|
||||
const errors = require('../../config/errors');
|
||||
const utils = require('../utils/utils');
|
||||
const _ = require('lodash');
|
||||
|
||||
/**
|
||||
* Calls linkedin.com/oauth/v2/authorization
|
||||
*
|
||||
* @param {Function} Takes an object that either contains {`token`} or {`error`}
|
||||
*/
|
||||
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})
|
||||
}
|
||||
|
||||
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)}`
|
||||
request({
|
||||
url,
|
||||
headers: {
|
||||
'Content-Type':'application/x-www-form-urlencoded'
|
||||
}
|
||||
}, (error,result) => {
|
||||
if (!error) {
|
||||
callback(utils.passingHTML(result.body));
|
||||
} else {
|
||||
callback({ error: errors.AUTH_LINKEDIN_ACCESS_TOKEN_FAILURE });
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getUserProfile(token, callback) {
|
||||
let linkedIn = appConfig.keys.linkedIn;
|
||||
let linkedInRequest = linkedIn.endpoints.get_profile;
|
||||
let url = linkedInRequest.url;
|
||||
|
||||
request({
|
||||
url,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'X-RestLi-Protocol-Version': '2.0.0'
|
||||
}
|
||||
}, (error, result) => {
|
||||
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 })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getOAuthLoginURL,
|
||||
getOAuthAccessToken,
|
||||
getUserProfile
|
||||
};
|
||||
@ -77,4 +77,5 @@ module.exports = {
|
||||
getSessionIdFromAuthHeader,
|
||||
isProfileNumberValid,
|
||||
createOAuthHeader
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user