Skip to content

Commit

Permalink
Merge branch 'BullhornHeartbeat'
Browse files Browse the repository at this point in the history
  • Loading branch information
DaKingKong committed Dec 31, 2024
2 parents 7263030 + 709397e commit 7a2908b
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/adapters/bullhorn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,56 @@ function getAuthType() {
return 'oauth';
}

async function authValidation({ user }) {
let commentActionListResponse;
try {
commentActionListResponse = await axios.get(
`${user.platformAdditionalInfo.restUrl}settings/commentActionList`,
{
headers: {
BhRestToken: user.platformAdditionalInfo.bhRestToken
}
});
return {
successful: true
}
}
catch (e) {
if (isAuthError(e.response.status)) {
user = await refreshSessionToken(user);
try {
commentActionListResponse = await axios.get(`${user.platformAdditionalInfo.restUrl}settings/commentActionList`,
{
headers: {
BhRestToken: user.platformAdditionalInfo.bhRestToken
}
});
return {
successful: true
}
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'It seems like your Bullhorn session has expired. Please re-authenticate.',
ttl: 3000
}
}
}
}
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'It seems like your Bullhorn session has expired. Please re-authenticate.',
ttl: 3000
}
}
}
}

async function getOauthInfo({ tokenUrl }) {
return {
clientId: process.env.BULLHORN_CLIENT_ID,
Expand Down Expand Up @@ -758,6 +808,7 @@ function upsertTranscript({ body, transcript }) {
}

exports.getAuthType = getAuthType;
exports.authValidation = authValidation;
exports.getOauthInfo = getOauthInfo;
exports.getOverridingOAuthOption = getOverridingOAuthOption;
exports.getUserInfo = getUserInfo;
Expand Down
29 changes: 28 additions & 1 deletion src/core/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,32 @@ async function saveUserInfo({ platformUserInfo, platform, hostname, accessToken,
};
}

async function authValidation({ platform, userId }) {
const existingUser = await UserModel.findOne({
where: {
[Op.and]: [
{
id: userId,
platform
}
]
}
});
if (!!existingUser) {
const platformModule = require(`../adapters/${platform}`);
const { successful, returnMessage } = await platformModule.authValidation({ user: existingUser });
return {
successful,
returnMessage
}
}
else {
return {
successful: false
}
}
}

exports.onOAuthCallback = onOAuthCallback;
exports.onApiKeyLogin = onApiKeyLogin;
exports.onApiKeyLogin = onApiKeyLogin;
exports.authValidation = authValidation;
47 changes: 45 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,51 @@ app.get('/crmManifest', (req, res) => {
app.get('/is-alive', (req, res) => {
res.send(`OK`);
});

app.get('/authValidation', async (req, res) => {
const requestStartTime = new Date().getTime();
let platformName = null;
let success = false;
let validationPass = false;
const { hashedExtensionId, hashedAccountId, userAgent, ip, author } = getAnalyticsVariablesInReqHeaders({ headers: req.headers })
try {
const jwtToken = req.query.jwtToken;
if (!!jwtToken) {
const { id: userId, platform } = jwt.decodeJwt(jwtToken);
platformName = platform;
const { successful, returnMessage } = await authCore.authValidation({ platform, userId });
success = true;
validationPass = successful;
res.status(200).send({ successful, returnMessage });
}
else {
res.status(400).send('Please go to Settings and authorize CRM platform');
success = false;
}
}
catch (e) {
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
const requestEndTime = new Date().getTime();
analytics.track({
eventName: 'Auth validation',
interfaceName: 'authValidation',
adapterName: platformName,
accountId: hashedAccountId,
extensionId: hashedExtensionId,
success,
requestDuration: (requestEndTime - requestStartTime) / 1000,
userAgent,
ip,
author,
extras: {
validationPass
}
});
});

app.get('/serverVersionInfo', (req, res) => {
const defaultCrmManifest = require('./adapters/manifest.json');
res.send({ version: defaultCrmManifest.version });
Expand Down Expand Up @@ -112,7 +157,6 @@ app.delete('/pipedrive-redirect', async function (req, res) {

app.post('/admin/settings', async function (req, res) {
const requestStartTime = new Date().getTime();
let platformName = null;
let success = false;
const { hashedExtensionId, hashedAccountId, userAgent, ip, author } = getAnalyticsVariablesInReqHeaders({ headers: req.headers })
try {
Expand All @@ -136,7 +180,6 @@ app.post('/admin/settings', async function (req, res) {
analytics.track({
eventName: 'Set admin settings',
interfaceName: 'setAdminSettings',
adapterName: platformName,
accountId: hashedAccountId,
extensionId: hashedExtensionId,
success,
Expand Down

0 comments on commit 7a2908b

Please sign in to comment.