Developer time: CometD on Windows Server + JWT Token Auth Flows

There are many ways that Salesforce can communicate with external systems. One of the most powerful is through Platform Events, allowing for complex and robust event-driven architectures to be built with mostly clicks, not code. However, when it comes to external systems listening for those events, usually some programmatic development is needed. 

In this small, developer-focused post, I’ll cover some learnings regarding CometD clients, deployments to Windows Server, and how to set up Salesforce Connected Apps. 

CometD & Windows

In 2022, just as the more robust, gRPC-based Pub/Sub API was making its way into general availability, we worked with a client that needed to have an external service listen for Platform Events emitted from their Salesforce instance. They asked us to write a small Node.js-based client as a listener, and deploy it to a Windows 2019 server running in their Azure instance. Given the timing of the Pub/Sub API, we opted for using the CometD-based Streaming API, and got to work! 

As I worked through the various issues that we faced, I noted the steps needed to run this client, and eventually published a step-by-step guide on my personal blog, which can be found here. Feel free to review it there. 

Salesforce Connected App Setup

Building the CometD client is one thing, but authenticating to the Salesforce APIs is an entirely separate beast. The recommendation from Salesforce for server-to-server communications via API (at the time of writing this) is the JWT Bearer Token OAuth2.0 flow, which can be tricky to set up if you haven’t done it before. We put together a small open-source Github repo that includes example code for a lightweight Node-based CometD client. More importantly, this repo contains instructions and screen shots covering how to create a correctly-configured Salesforce Connected App, including a shell script for generating the certificate needed to enable the JWT-based OAuth2.0 flow. There is also a small lib file for connecting to the Salesforce APIs to retrieve an access token that you can turn around and use for standard REST API calls. 


Are you facing an issue connecting one or more systems with Salesforce? At SOLVD, we’re passionate about providing robust solutions that empower Salesforce users and connect your critical business applications. If you’ve found this content helpful or would like to talk more about development in general, feel free to reach out to SOLVD here to learn more about our consulting services.

yellow cloud solvd logo

Our clients say

From my initial call with Spencer through project implementation with John and Evan, my experience with the SOLVD team was excellent. They were quick to understand our business needs, clear when explaining the reasoning behind proposed solutions, transparent when reporting on progress and timeline, and all around enjoyable to work with. Would highly recommend and looking forward to continue working with them in the future!

Veronica Wong Director of Operations at Pathstream

SOLVD was very straight forward with everything needed to complete the project. No surprises, no issues, and cost was aligned with the estimate. They made implementation easy and quick.

Matt Benzaquen Sr Manager, Sales Strategy at Instabug

As a rule, I'm pretty stingy with my recommendations. So it's a pleasure for me to recommend Solvd as a top-flight Salesforce consultancy. Solvd recently led our company's conversion to the Lightning interface and did it on time, on budget and made it easy for me and my team. I know I'll use their services again, and am confident they can do the same for you.

Tim Tuttle CFO at Relevate Health Group