Skip to content

Commit

Permalink
fix: oauth callback error message
Browse files Browse the repository at this point in the history
  • Loading branch information
DaKingKong committed Jul 1, 2024
1 parent 26866e8 commit ad1c70b
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 285 deletions.
2 changes: 2 additions & 0 deletions src/adapters/bullhorn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function getUserInfo({ authHeader, tokenUrl, apiUrl, username }) {
bhRestToken
}
return {
successful: true,
platformUserInfo: {
id,
name,
Expand All @@ -49,6 +50,7 @@ async function getUserInfo({ authHeader, tokenUrl, apiUrl, username }) {
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'Failed to get user info.',
Expand Down
57 changes: 35 additions & 22 deletions src/adapters/clio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,42 @@ function getOauthInfo() {
}

async function getUserInfo({ authHeader }) {
const userInfoResponse = await axios.get('https://app.clio.com/api/v4/users/who_am_i.json?fields=id,name,time_zone', {
headers: {
'Authorization': authHeader
}
});
const id = userInfoResponse.data.data.id.toString();
const name = userInfoResponse.data.data.name;
const timezoneName = userInfoResponse.data.data.time_zone;
const timezoneOffset = 0;
return {
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: {}
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Clio.',
ttl: 3000
try {
const userInfoResponse = await axios.get('https://app.clio.com/api/v4/users/who_am_i.json?fields=id,name,time_zone', {
headers: {
'Authorization': authHeader
}
});
const id = userInfoResponse.data.data.id.toString();
const name = userInfoResponse.data.data.name;
const timezoneName = userInfoResponse.data.data.time_zone;
const timezoneOffset = 0;
return {
successful: true,
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: {}
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Clio.',
ttl: 3000
}
};
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'Failed to get user info.',
ttl: 3000
}
}
};
}
}
async function unAuthorize({ user }) {
const revokeUrl = 'https://app.clio.com/oauth/deauthorize';
Expand Down
63 changes: 38 additions & 25 deletions src/adapters/insightly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,45 @@ function getBasicAuth({ apiKey }) {
}

async function getUserInfo({ authHeader, additionalInfo }) {
additionalInfo.apiUrl = additionalInfo.apiUrl.split('/v')[0];
const userInfoResponse = await axios.get(`${additionalInfo.apiUrl}/${process.env.INSIGHTLY_API_VERSION}/users/me`, {
headers: {
'Authorization': authHeader
}
});;
// Insightly timezone = server location + non-standard tz area id (eg.'Central Standard Time')
// We use UTC here for now
const id = userInfoResponse.data.USER_ID.toString();
const name = `${userInfoResponse.data.FIRST_NAME} ${userInfoResponse.data.LAST_NAME}`;
const timezoneOffset = null;
const timezoneName = userInfoResponse.data.TIMEZONE_ID;
return {
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: additionalInfo
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Insightly.',
ttl: 3000
try {
additionalInfo.apiUrl = additionalInfo.apiUrl.split('/v')[0];
const userInfoResponse = await axios.get(`${additionalInfo.apiUrl}/${process.env.INSIGHTLY_API_VERSION}/users/me`, {
headers: {
'Authorization': authHeader
}
});;
// Insightly timezone = server location + non-standard tz area id (eg.'Central Standard Time')
// We use UTC here for now
const id = userInfoResponse.data.USER_ID.toString();
const name = `${userInfoResponse.data.FIRST_NAME} ${userInfoResponse.data.LAST_NAME}`;
const timezoneOffset = null;
const timezoneName = userInfoResponse.data.TIMEZONE_ID;
return {
successful: true,
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: additionalInfo
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Insightly.',
ttl: 3000
}
};
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'Failed to get user info.',
ttl: 3000
}
}
};
}
}

async function unAuthorize({ user }) {
Expand Down
65 changes: 39 additions & 26 deletions src/adapters/pipedrive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,47 @@ function getOauthInfo() {
}

async function getUserInfo({ authHeader, hostname }) {
const userInfoResponse = await axios.get('https://api.pipedrive.com/v1/users/me', {
headers: {
'Authorization': authHeader
}
});
const id = userInfoResponse.data.data.id.toString();
const name = userInfoResponse.data.data.name;
const timezoneName = userInfoResponse.data.data.timezone_name;
const timezoneOffset = userInfoResponse.data.data.timezone_offset;
return {
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: {
companyId: userInfoResponse.data.data.company_id,
companyName: userInfoResponse.data.data.company_name,
companyDomain: userInfoResponse.data.data.company_domain,
try {
const userInfoResponse = await axios.get('https://api.pipedrive.com/v1/users/me', {
headers: {
'Authorization': authHeader
}
});
const id = userInfoResponse.data.data.id.toString();
const name = userInfoResponse.data.data.name;
const timezoneName = userInfoResponse.data.data.timezone_name;
const timezoneOffset = userInfoResponse.data.data.timezone_offset;
return {
successful: true,
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: {
companyId: userInfoResponse.data.data.company_id,
companyName: userInfoResponse.data.data.company_name,
companyDomain: userInfoResponse.data.data.company_domain,
},
overridingHostname: hostname == 'temp' ? `${userInfoResponse.data.data.company_domain}.pipedrive.com` : null
},
overridingHostname: hostname == 'temp' ? `${userInfoResponse.data.data.company_domain}.pipedrive.com` : null
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Pipedrive.',
ttl: 3000
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Pipedrive.',
ttl: 3000
}
};
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'Failed to get user info.',
ttl: 3000
}
}
};
}
}

async function unAuthorize({ user }) {
Expand Down
63 changes: 38 additions & 25 deletions src/adapters/redtail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,45 @@ function getAuthHeader({ userKey }) {
}

async function getUserInfo({ authHeader, additionalInfo }) {
const overrideAPIKey = `${process.env.REDTAIL_API_KEY}:${additionalInfo.username}:${additionalInfo.password}`;
const overrideAuthHeader = `Basic ${getBasicAuth({ apiKey: overrideAPIKey })}`;
const authResponse = await axios.get(`${process.env.REDTAIL_API_SERVER}/authentication`, {
headers: {
'Authorization': overrideAuthHeader
try {
const overrideAPIKey = `${process.env.REDTAIL_API_KEY}:${additionalInfo.username}:${additionalInfo.password}`;
const overrideAuthHeader = `Basic ${getBasicAuth({ apiKey: overrideAPIKey })}`;
const authResponse = await axios.get(`${process.env.REDTAIL_API_SERVER}/authentication`, {
headers: {
'Authorization': overrideAuthHeader
}
});
additionalInfo['userResponse'] = authResponse.data.authenticated_user;
delete additionalInfo.password;
const id = additionalInfo.username;
const name = additionalInfo.username;
const timezoneName = '';
const timezoneOffset = null;
return {
successful: false,
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
overridingApiKey: additionalInfo.userResponse.user_key,
platformAdditionalInfo: additionalInfo
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Redtail.',
ttl: 3000
}
}
});
additionalInfo['userResponse'] = authResponse.data.authenticated_user;
delete additionalInfo.password;
const id = additionalInfo.username;
const name = additionalInfo.username;
const timezoneName = '';
const timezoneOffset = null;
return {
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
overridingApiKey: additionalInfo.userResponse.user_key,
platformAdditionalInfo: additionalInfo
},
returnMessage: {
messageType: 'success',
message: 'Successfully connceted to Redtail.',
ttl: 3000
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'Failed to get user info.',
ttl: 3000
}
}
}
}
Expand Down
75 changes: 43 additions & 32 deletions src/adapters/testCRM/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,52 @@ async function getUserInfo({ authHeader, additionalInfo }) {
// ------------------------------------------------------
// ---TODO.1: Implement API call to retrieve user info---
// ------------------------------------------------------

// API call to get logged in user info
// const userInfoResponse = await axios.get('https://api.crm.com/user/me', {
// headers: {
// 'Authorization': authHeader
// }
// });
const mockUserInfoResponse = {
data: {
id: 'testUserId',
name: 'Test User',
time_zone: 'America/Los_Angeles',
time_zone_offset: 0
try {
// API call to get logged in user info
// const userInfoResponse = await axios.get('https://api.crm.com/user/me', {
// headers: {
// 'Authorization': authHeader
// }
// });
const mockUserInfoResponse = {
data: {
id: 'testUserId',
name: 'Test User',
time_zone: 'America/Los_Angeles',
time_zone_offset: 0
}
}
}

const id = mockUserInfoResponse.data.id;
const name = mockUserInfoResponse.data.name;
const timezoneName = mockUserInfoResponse.data.time_zone ?? ''; // Optional. Whether or not you want to log with regards to the user's timezone
const timezoneOffset = mockUserInfoResponse.data.time_zone_offset ?? null; // Optional. Whether or not you want to log with regards to the user's timezone. It will need to be converted to a format that CRM platform uses,
return {
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: {} // this should save whatever extra info you want to save against the user
},
returnMessage: {
messageType: 'success',
message: 'Successfully connected to TestCRM.',
ttl: 3000
const id = mockUserInfoResponse.data.id;
const name = mockUserInfoResponse.data.name;
const timezoneName = mockUserInfoResponse.data.time_zone ?? ''; // Optional. Whether or not you want to log with regards to the user's timezone
const timezoneOffset = mockUserInfoResponse.data.time_zone_offset ?? null; // Optional. Whether or not you want to log with regards to the user's timezone. It will need to be converted to a format that CRM platform uses,
return {
successful: true,
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
platformAdditionalInfo: {} // this should save whatever extra info you want to save against the user
},
returnMessage: {
messageType: 'success',
message: 'Successfully connected to TestCRM.',
ttl: 3000
}
};
}
catch (e) {
return {
successful: false,
returnMessage: {
messageType: 'warning',
message: 'Failed to get user info.',
ttl: 3000
}
}
};

}
//---------------------------------------------------------------------------------------------------
//---CHECK.1: Open db.sqlite (might need to install certain viewer) to check if user info is saved---
//---------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ad1c70b

Please sign in to comment.