feat(vtiger-crm): add vtiger crm integration
This commit is contained in:
44
packages/backend/src/apps/vtiger-crm/auth/index.js
Normal file
44
packages/backend/src/apps/vtiger-crm/auth/index.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'username',
|
||||
label: 'Username',
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: 'Email address of your Vtiger CRM account',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'accessKey',
|
||||
label: 'Access Key',
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: 'Access Key of your Vtiger CRM account',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'domain',
|
||||
label: 'Domain',
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description:
|
||||
'For example: acmeco.od1 if your dashboard url is https://acmeco.od1.vtiger.com. (Unfortunately, we are not able to offer support for self-hosted instances at this moment.)',
|
||||
clickToCopy: false,
|
||||
},
|
||||
],
|
||||
|
||||
verifyCredentials,
|
||||
isStillVerified,
|
||||
};
|
@@ -0,0 +1,8 @@
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -0,0 +1,32 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
const verifyCredentials = async ($) => {
|
||||
const params = {
|
||||
operation: 'getchallenge',
|
||||
username: $.auth.data.username,
|
||||
};
|
||||
|
||||
const { data } = await $.http.get('/webservice.php', { params });
|
||||
|
||||
const accessKey = crypto
|
||||
.createHash('md5')
|
||||
.update(data.result.token + $.auth.data.accessKey)
|
||||
.digest('hex');
|
||||
|
||||
const body = {
|
||||
operation: 'login',
|
||||
username: $.auth.data.username,
|
||||
accessKey,
|
||||
};
|
||||
|
||||
const { data: result } = await $.http.post('/webservice.php', body);
|
||||
|
||||
const response = await $.http.get('/restapi/v1/vtiger/default/me');
|
||||
|
||||
await $.auth.set({
|
||||
screenName: `${response.data.result?.first_name} ${response.data.result?.last_name}`,
|
||||
sessionName: result.result.sessionName,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
Reference in New Issue
Block a user