unAuthorize
It is to remove user data from our database when user chooses to log out. Some CRMs have token invalidation mechanism, if so, please implement that as well.
Request parameters
Parameter | Description | |
---|---|---|
user |
An object describing the Chrome extension user associated with the action that triggered this interface. |
Return value(s)
Parameter | Description |
---|---|
returnMessage |
message , messageType and ttl |
Example
{
returnMessage:{
message: 'Successfully unauthorized',
messageType: 'success', // 'success', 'warning' or 'danger'
ttl: 30000 // in miliseconds
}
}
Reference
async function unAuthorize({ user }) {
// -----------------------------------------------------------------
// ---TODO.2: Implement token revocation if CRM platform requires---
// -----------------------------------------------------------------
// const revokeUrl = 'https://api.crm.com/oauth/unauthorize';
// const revokeBody = {
// token: user.accessToken
// }
// const accessTokenRevokeRes = await axios.post(
// revokeUrl,
// revokeBody,
// {
// headers: { 'Authorization': `Basic ${getBasicAuth({ apiKey: user.accessToken })}` }
// });
await user.destroy();
return {
returnMessage: {
messageType: 'success',
message: 'Successfully logged out from TestCRM account.',
ttl: 3000
}
}
async function unAuthorize({ user }) {
const revokeUrl = 'https://oauth.pipedrive.com/oauth/revoke';
const basicAuthHeader = Buffer.from(`${process.env.PIPEDRIVE_CLIENT_ID}:${process.env.PIPEDRIVE_CLIENT_SECRET}`).toString('base64');
const refreshTokenParams = new url.URLSearchParams({
token: user.refreshToken
});
const refreshTokenRevokeRes = await axios.post(
revokeUrl,
refreshTokenParams,
{
headers: { 'Authorization': `Basic ${basicAuthHeader}` }
});
const accessTokenParams = new url.URLSearchParams({
token: user.accessToken
});
const accessTokenRevokeRes = await axios.post(
revokeUrl,
accessTokenParams,
{
headers: { 'Authorization': `Basic ${basicAuthHeader}` }
});
await user.destroy();
return {
returnMessage: {
messageType: 'success',
message: 'Successfully logged out from Pipedrive account.',
ttl: 3000
}
}
}