Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sc 68589/new integration bearer authentication and #13

Merged
merged 7 commits into from
Mar 26, 2024

Conversation

cgrayson
Copy link
Contributor

Description of the change

Adds new token-authenticated JSON integration. See my comments on sc-68589 from 5/7 & 5/15 for details on the approach taken here.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Configuration change
  • Technical Debt
  • Documentation

Related tickets

https://app.shortcut.com/active-prospect/story/68589/new-integration-bearer-authentication-and-authorization-method

Checklists

Development and Testing

  • Lint rules pass locally.
  • The code changed/added as part of this pull request has been covered with tests, or this PR does not alter production code.
  • All tests related to the changed code pass in development, or tests are not applicable.

Code Review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached.
  • At least two engineers have been added as "Reviewers" on the pull request.
  • Changes have been reviewed by at least two other engineers who did not write the code.
  • This branch has been rebased off master to be current.

Tracking

  • Issue from Shortcut/Jira has a link to this pull request.
  • This PR has a link to the issue in Shortcut.

QA

  • This branch has been deployed to staging and tested.

Copy link

@cgrayson cgrayson requested a review from ericyd March 22, 2024 18:55
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<head>
<title>Leadconduit Integration</title>
<link href="/lc-client.css" rel="stylesheet">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not a big deal but this should never have been checked in this way.)

@@ -1,267 +1,284 @@
// Generated by CoffeeScript 1.10.0
Copy link
Contributor Author

@cgrayson cgrayson Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only real change here was to add PATCH as a valid verb (L233) to fix a test failure from upstream changes; everything else is just reformatting from an old CoffeeScript conversion that never got cleaned up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much appreciate this comment, I would have been so lost 🙏🏻

ericyd
ericyd previously approved these changes Mar 22, 2024
Copy link
Member

@ericyd ericyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! All my comments are just nits and don't need to be addressed. Thanks for the detailed notes in the ticket and the thorough tests!

@@ -1,5 +1,6 @@
module.exports = {
outbound: {
token_authenticated: require('./lib/authjson'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, I don't know the point of the /docs directory, but should we add an entry there too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These markdown files are the source of the descriptions in-app and on the "catalog" pages. Absolutely need one here, thanks!

@@ -1,267 +1,284 @@
// Generated by CoffeeScript 1.10.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much appreciate this comment, I would have been so lost 🙏🏻

<button v-on:click="$store.dispatch('cancel')">Cancel</button>
<button v-on:click="next" class="primary">{{ (credential.username && credential.password) ? 'Continue' : 'Skip' }}</button>
</footer>
<Navigation :onNext="next" :disableNext="(credential.type === 'token' && !credential.token) || (credential.type === 'user' && (!credential.username || !credential.password))" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a computed property for the :disableNext prop might be a little easier to read, but certainly not a blocker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. And I went ahead & made that property function a little more verbose; feedback welcome on that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! The more verbose version is a bit easier to reason about I think 👍🏻

const substituteHeaderTokens = (headers, credential) => {
const tokenAttributes = getTokenAttributes(credential);

if (headers && tokenAttributes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but tokenAttributes will always be truthy so it isn't doing anything in this conditional. You could use tokenAttributes.length, but ultimately it won't matter much so I'll leave it to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call; though the result is the same without, I added .length because I felt checking both here is a tiny bit more descriptive.

Comment on lines 51 to 52
const normalizePart = (part) => capitalize(part);
const normalField = key.split('-').map(normalizePart).join('-');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but normalizePart is identical to capitalize, you could just map(capitalize) and have the same behavior I believe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice specs! 👏🏻

Comment on lines +79 to +81
const pending = nock.pendingMocks();
assert.equal(pending.length, 1);
assert.isTrue(pending.includes(`POST ${baseAuthUrl}:443/login`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about pendingMocks(), that's pretty handy!

Comment on lines +79 to +82
// update vars.credential with the new token, using the user-configured (or default) attribute
const tokenPath = vars.authentication_token_path || 'accessToken';
const tokenName = tokenPath.split('.').at(-1); // use the name after the final '.', if there are any
vars.credential[tokenName] = get(tokenResponse, tokenPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a stupid question but I've been meaning to ask and I keep forgetting.

Are credentials saved back to the DB after integrations run? I've been wondering how the token gets persisted between integration invocations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a stupid question at all; saving updated credentials is one of the many things send does. See https://github.com/activeprospect/leadconduit-api/blob/59c0a7a3dd966e99bf8dd9c1d20a08283c42bf6e/lib/handler/util/send.js#L291-L316 (& ff.)

@cgrayson
Copy link
Contributor Author

(fyi - still some QA feedback to address before re-review)

@cgrayson cgrayson requested a review from ericyd March 26, 2024 18:37
Copy link
Member

@ericyd ericyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@cgrayson cgrayson merged commit 67c5a42 into master Mar 26, 2024
3 checks passed
@cgrayson cgrayson deleted the sc-68589/new-integration-bearer-authentication-and branch March 26, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants