From ddb3d4fa5abcdb9b9894eab4229d862b366c16f8 Mon Sep 17 00:00:00 2001 From: Chris Grayson Date: Mon, 25 Mar 2024 11:18:02 -0500 Subject: [PATCH] address PR feedback --- CHANGELOG.md | 4 ++++ docs/outbound.token-authenticated.md | 7 +++++++ lib/authHelpers.js | 5 ++--- lib/ui/public/app/auth/Auth.vue | 18 +++++++++++++++++- test/authHelpers-spec.js | 12 +++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 docs/outbound.token-authenticated.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a7a10..771305a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org) +## [1.2.0] - 2024-03-25 +### Added +- added Token Authenticated integration ([sc-68589](https://app.shortcut.com/active-prospect/story/68589/new-integration-bearer-authentication-and-authorization-method)) + ## [1.1.0] - 2021-06-23 ### Added - added an RUI to assist with configuration diff --git a/docs/outbound.token-authenticated.md b/docs/outbound.token-authenticated.md new file mode 100644 index 0000000..01e5bba --- /dev/null +++ b/docs/outbound.token-authenticated.md @@ -0,0 +1,7 @@ +--- +name: Token-Authenticated JSON +tag: Code +integration_type: delivery +link: https://activeprospect.com/products/leadconduit/ +--- +Like the "plain" JSON integration, but allows configuration of an authentication token. That in turn is used to get and refresh access tokens during delivery as needed. diff --git a/lib/authHelpers.js b/lib/authHelpers.js index afe3eb0..7055a1a 100644 --- a/lib/authHelpers.js +++ b/lib/authHelpers.js @@ -21,7 +21,7 @@ const getTokenAttributes = (credential) => { const substituteHeaderTokens = (headers, credential) => { const tokenAttributes = getTokenAttributes(credential); - if (headers && tokenAttributes) { + if (headers && tokenAttributes.length) { // iterate over each header value (e.g., 'Bearer TOKEN') Object.keys(headers).forEach(property => { // looking for each tokenAttribute (e.g., 'token') @@ -48,8 +48,7 @@ const normalizeHeaders = (headers) => { const normalHeaders = {}; Object.keys(headers).forEach(key => { - const normalizePart = (part) => capitalize(part); - const normalField = key.split('-').map(normalizePart).join('-'); + const normalField = key.split('-').map(capitalize).join('-'); normalHeaders[normalField] = headers[key]; }); return normalHeaders; diff --git a/lib/ui/public/app/auth/Auth.vue b/lib/ui/public/app/auth/Auth.vue index 177a456..20c946b 100644 --- a/lib/ui/public/app/auth/Auth.vue +++ b/lib/ui/public/app/auth/Auth.vue @@ -43,7 +43,7 @@ - + @@ -65,6 +65,19 @@ export default { credential: existingCredential || credentialTemplate, }; }, + computed: { + disableNextButton() { + if(this.credential.type === 'token') { + return !this.credential.token; + } + else if(this.credential.type === 'user') { + return !this.credential.username || !this.credential.password; + } + else { + return false; + } + } + }, methods: { next() { if (this.credential.type === 'user') { @@ -74,6 +87,9 @@ export default { delete this.credential.username; delete this.credential.password; this.$store.dispatch('saveCredential', this.credential); + } else { + // must be 'none' + this.$store.state.ui.create({'redirect': 'config'}); } }, }, diff --git a/test/authHelpers-spec.js b/test/authHelpers-spec.js index bf47497..91eaf03 100644 --- a/test/authHelpers-spec.js +++ b/test/authHelpers-spec.js @@ -20,7 +20,7 @@ describe('Auth Helpers', function () { assert.deepEqual(getTokenAttributes(credential), ['token', 'accessToken', 'aSeeminglyRandomAttribute']); }); - it('substitute header tokens', function () { + it('substitutes header tokens', function () { const headers = { Authorization: "Bearer TOKEN", "X-Auth-Test-0": "Bearer token", @@ -37,6 +37,16 @@ describe('Auth Helpers', function () { assert.equal(actual["X-Auth-Test-3"], "What about bar"); }); + it('handles absence of credential token-ish values', function () { + const headers = { + Authorization: "Bearer TOKEN", + "X-Auth-Test-0": "Bearer token" + }; + + const actual = substituteHeaderTokens(headers, {}); + assert.deepEqual(actual, headers); + }); + it('converts auth config', function () { const vars = { authentication_url: 'https://auth.com',