From b3e65fca6153fd72dac0625f8f2ba653925d7dd5 Mon Sep 17 00:00:00 2001 From: Sayam Nasir Date: Thu, 10 Oct 2024 13:40:24 +0500 Subject: [PATCH] calendly (major update) Authorization updated from ApiKey to Oauth2 (#209) * Calendly oauth updated from ApiKey to Oauth2 * bundle.json * lint --- src/appmixer/calendly/auth.js | 28 ++++++++----------- src/appmixer/calendly/bundle.json | 5 +++- src/appmixer/calendly/calendly-commons.js | 4 +-- .../events/InviteeCanceled/InviteeCanceled.js | 4 +-- .../events/InviteeCreated/InviteeCreated.js | 4 +-- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/appmixer/calendly/auth.js b/src/appmixer/calendly/auth.js index 4d0d5d8e7..208ec4314 100644 --- a/src/appmixer/calendly/auth.js +++ b/src/appmixer/calendly/auth.js @@ -2,35 +2,31 @@ module.exports = { - type: 'apiKey', + type: 'oauth2', definition: { - accountNameFromProfileInfo: 'data.attributes.email', + accountNameFromProfileInfo: 'resource.email', - auth: { - apiKey: { - type: 'text', - name: 'API Key', - tooltip: 'Log into your calendly account and find integration page in settings. ' + - '
You have to have Premium or Pro Calendly subscription in order make Calendly components work. ' + - '
It also works with free 14 days trial.' - } - }, + authUrl: 'https://auth.calendly.com/oauth/authorize', + + requestAccessToken: 'https://auth.calendly.com/oauth/token', requestProfileInfo: { method: 'GET', - url: 'https://calendly.com/api/v1/users/me', + url: 'https://api.calendly.com/users/me', headers: { - 'X-TOKEN': '{{apiKey}}' + 'Authorization': 'Bearer {{accessToken}}' } }, - validate: { + refreshAccessToken: 'https://auth.calendly.com/oauth/token', + + validateAccessToken: { method: 'GET', - url: 'https://calendly.com/api/v1/users/me', + url: 'https://api.calendly.com/users/me', headers: { - 'X-TOKEN': '{{apiKey}}' + 'Authorization': 'Bearer {{accessToken}}' } } } diff --git a/src/appmixer/calendly/bundle.json b/src/appmixer/calendly/bundle.json index 824b7edb1..8b6c84638 100644 --- a/src/appmixer/calendly/bundle.json +++ b/src/appmixer/calendly/bundle.json @@ -1,12 +1,15 @@ { "name": "appmixer.calendly", - "version": "1.0.2", + "version": "1.0.3", "changelog": { "1.0.1": [ "Initial version" ], "1.0.2": [ "Provide friendly access to first 3 answers of custom questions." + ], + "1.0.3": [ + "Breaking Change: Updated authorization to Oauth2" ] } } diff --git a/src/appmixer/calendly/calendly-commons.js b/src/appmixer/calendly/calendly-commons.js index d5b1a303e..58fda514a 100644 --- a/src/appmixer/calendly/calendly-commons.js +++ b/src/appmixer/calendly/calendly-commons.js @@ -16,7 +16,7 @@ module.exports = { method: 'POST', url: 'https://calendly.com/api/v1/hooks', headers: { - 'X-TOKEN': token + 'Authorization': `Bearer ${token}` }, json: true, body: { @@ -38,7 +38,7 @@ module.exports = { method: 'DELETE', url: `https://calendly.com/api/v1/hooks/${webhookId}`, headers: { - 'X-TOKEN': token + 'Authorization': `Bearer ${token}` } }); } diff --git a/src/appmixer/calendly/events/InviteeCanceled/InviteeCanceled.js b/src/appmixer/calendly/events/InviteeCanceled/InviteeCanceled.js index 203009a6e..2e27e2e93 100644 --- a/src/appmixer/calendly/events/InviteeCanceled/InviteeCanceled.js +++ b/src/appmixer/calendly/events/InviteeCanceled/InviteeCanceled.js @@ -46,7 +46,7 @@ module.exports = { return this.unregisterWebhook(context) .then(() => { - return commons.registerWebhookSubscription(context.auth.apiKey, 'invitee.canceled', url); + return commons.registerWebhookSubscription(context.auth.accessToken, 'invitee.canceled', url); }).then(response => { return context.saveState({ webhookId: response.id }); }); @@ -64,6 +64,6 @@ module.exports = { return Promise.resolve(); } - return commons.removeWebhookSubscription(webhookId, context.auth.apiKey); + return commons.removeWebhookSubscription(webhookId, context.auth.accessToken); } }; diff --git a/src/appmixer/calendly/events/InviteeCreated/InviteeCreated.js b/src/appmixer/calendly/events/InviteeCreated/InviteeCreated.js index 99fa53ed9..e905c28df 100644 --- a/src/appmixer/calendly/events/InviteeCreated/InviteeCreated.js +++ b/src/appmixer/calendly/events/InviteeCreated/InviteeCreated.js @@ -48,7 +48,7 @@ module.exports = { return this.unregisterWebhook(context) .then(() => { - return commons.registerWebhookSubscription(context.auth.apiKey, 'invitee.created', url); + return commons.registerWebhookSubscription(context.auth.accessToken, 'invitee.created', url); }).then(response => { return context.saveState({ webhookId: response.id }); }); @@ -66,6 +66,6 @@ module.exports = { return Promise.resolve(); } - return commons.removeWebhookSubscription(webhookId, context.auth.apiKey); + return commons.removeWebhookSubscription(webhookId, context.auth.accessToken); } };