Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrayson committed Mar 25, 2024
1 parent 96a70c1 commit ddb3d4f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/outbound.token-authenticated.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 2 additions & 3 deletions lib/authHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion lib/ui/public/app/auth/Auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</ul>
</form>
</section>
<Navigation :onNext="next" :disableNext="(credential.type === 'token' && !credential.token) || (credential.type === 'user' && (!credential.username || !credential.password))" />
<Navigation :onNext="next" :disableNext="disableNextButton" />
</div>
</template>

Expand All @@ -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') {
Expand All @@ -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'});
}
},
},
Expand Down
12 changes: 11 additions & 1 deletion test/authHelpers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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',
Expand Down

0 comments on commit ddb3d4f

Please sign in to comment.