Skip to content

Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.

fix(zoominfo): authenticate private keys with signed PKI assertions

Rudy Celekli88973d874b04
diff --git a/tests/clis/zoominfo-auth.test.cjs b/tests/clis/zoominfo-auth.test.cjs
new file mode 100644
index 0000000..968fff0
--- /dev/null
+++ b/tests/clis/zoominfo-auth.test.cjs
@@ -0,0 +1,75 @@
+const { test } = require('node:test')
+const assert = require('node:assert/strict')
+const { spawnSync } = require('node:child_process')
+const { generateKeyPairSync } = require('node:crypto')
+const path = require('node:path')
+const cli = path.resolve(__dirname, '../../tools/clis/zoominfo.js')
+const keys = generateKeyPairSync('rsa', { modulusLength: 2048,
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' }, publicKeyEncoding: { type: 'spki', format: 'pem' } })
+function run(args, env = {}, mode = 'pki') {
+ const source = `
+ const assert = require('node:assert/strict'); const crypto = require('node:crypto');
+ const calls = [];
+ global.fetch = async (url, options) => {
+ calls.push({url, ...options});
+ if (${JSON.stringify(mode)} === 'none') throw new Error('Unexpected network request');
+ if (url.endsWith('/authenticate')) {
+ if (${JSON.stringify(mode)} === 'pki') {
+ assert.equal(options.body, undefined, 'PKI must not send the private key as a password');
+ const assertion = options.headers.Authorization.slice('Bearer '.length);
+ const [header, payload, signature] = assertion.split('.');
+ assert.equal(JSON.parse(Buffer.from(header, 'base64url')).alg, 'RS256');
+ const claims = JSON.parse(Buffer.from(payload, 'base64url'));
+ assert.equal(claims.aud, 'enterprise_api'); assert.equal(claims.iss, '[email protected]');
+ assert.equal(claims.username, '[email protected]'); assert.equal(claims.client_id, 'fixture-client');
+ assert.ok(Math.abs(claims.iat - Math.floor(Date.now()/1000)) < 10); assert.equal(claims.exp - claims.iat, 300);
+ assert.ok(crypto.verify('RSA-SHA256', Buffer.from(header+'.'+payload), ${JSON.stringify(keys.publicKey)}, Buffer.from(signature, 'base64url')));
+ } else {
+ assert.deepEqual(JSON.parse(options.body), {username:'[email protected]', password:'fixture-password'});
+ }
+ return {ok:true,status:200,text:async()=>JSON.stringify({jwt:'fixture-server-token'})};
+ }
+ return {ok:true,status:200,text:async()=>JSON.stringify({calls})};
+ };
+ process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)});`
+ return spawnSync(process.execPath, ['-e', source], { encoding: 'utf8', timeout: 5000,
+ env: { ...process.env, ZOOMINFO_ACCESS_TOKEN: '', ZOOMINFO_USERNAME: '', ZOOMINFO_PASSWORD: '',
+ ZOOMINFO_PRIVATE_KEY: '', ZOOMINFO_CLIENT_ID: '', ...env } })
+}
+function output(result) { assert.equal(result.status, 0, result.stderr); return JSON.parse(result.stdout) }
+const pki = { ZOOMINFO_USERNAME: '[email protected]', ZOOMINFO_CLIENT_ID: 'fixture-client', ZOOMINFO_PRIVATE_KEY: keys.privateKey }
+test('PKI signs the documented assertion locally, then uses the returned server JWT', () => {
+ const result = output(run(['companies','search','--name','Acme'], pki))
+ assert.equal(result.calls.length, 2)
+ assert.equal(result.calls[0].url, 'https://api.zoominfo.com/authenticate')
+ assert.equal(result.calls[1].headers.Authorization, 'Bearer fixture-server-token')
+ assert.equal(result.calls[1].url, 'https://api.zoominfo.com/search/company')
+ assert.equal(JSON.stringify(result).includes(keys.privateKey), false)
+})
+test('explicit password authentication remains available independently of private keys', () => {
+ const result = output(run(['companies','search'], {ZOOMINFO_USERNAME:'[email protected]',ZOOMINFO_PASSWORD:'fixture-password'}, 'password'))
+ assert.equal(result.calls.length, 2)
+ assert.equal(result.calls[1].headers.Authorization, 'Bearer fixture-server-token')
+})
+test('an existing access token bypasses authentication', () => {
+ const result = output(run(['companies','search'], {ZOOMINFO_ACCESS_TOKEN:'existing-token'}))
+ assert.equal(result.calls.length, 1)
+ assert.equal(result.calls[0].headers.Authorization, 'Bearer existing-token')
+})
+test('missing client ID cannot downgrade a private key to password authentication', () => {
+ const result = run(['companies','search'], {...pki,ZOOMINFO_CLIENT_ID:'',ZOOMINFO_PASSWORD:'fixture-password'}, 'none')
+ assert.equal(result.status, 1)
+ assert.match(result.stderr, /ZOOMINFO_CLIENT_ID/)
+ assert.equal(result.stderr.includes(keys.privateKey), false)
+})
+test('invalid signing key fails before any network request', () => {
+ const result = run(['companies','search'], {...pki,ZOOMINFO_PRIVATE_KEY:'not-a-key'}, 'none')
+ assert.equal(result.status, 1)
+ assert.match(result.stderr, /private key|signing key/i)
+})
+test('PKI dry run never transmits or prints signing credentials', () => {
+ const result = output(run(['companies','search','--dry-run'], pki, 'none'))
+ assert.equal(result.headers.Authorization, 'Bearer ***')
+ assert.equal(JSON.stringify(result).includes(keys.privateKey), false)
+})
+test('no-credential help remains usable', () => { assert.ok(output(run([], {}, 'none')).usage) })
diff --git a/tools/clis/zoominfo.js b/tools/clis/zoominfo.js
index 7c2c40a..45c583d 100755
--- a/tools/clis/zoominfo.js
+++ b/tools/clis/zoominfo.js
@@ -6,21 +6,46 @@ const BASE_URL = 'https://api.zoominfo.com'
let ACCESS_TOKEN = process.env.ZOOMINFO_ACCESS_TOKEN
if ((!ACCESS_TOKEN && !process.env.ZOOMINFO_USERNAME) && rawArgs.length > 0) {
- console.error(JSON.stringify({ error: 'ZOOMINFO_ACCESS_TOKEN or ZOOMINFO_USERNAME + ZOOMINFO_PRIVATE_KEY environment variables required' }))
+ console.error(JSON.stringify({ error: 'ZOOMINFO_ACCESS_TOKEN, or ZOOMINFO_USERNAME with ZOOMINFO_PASSWORD or ZOOMINFO_PRIVATE_KEY + ZOOMINFO_CLIENT_ID required' }))
process.exit(1)
}
async function authenticate() {
if (ACCESS_TOKEN) return ACCESS_TOKEN
const username = process.env.ZOOMINFO_USERNAME
- const password = process.env.ZOOMINFO_PRIVATE_KEY
- if (!username || !password) {
- throw new Error('ZOOMINFO_USERNAME and ZOOMINFO_PRIVATE_KEY required for authentication')
+ if (!username) throw new Error('ZOOMINFO_USERNAME required for authentication')
+ const privateKey = process.env.ZOOMINFO_PRIVATE_KEY
+ const headers = { 'Content-Type': 'application/json', Accept: 'application/json' }
+ let body
+ if (privateKey) {
+ const clientId = process.env.ZOOMINFO_CLIENT_ID
+ if (!clientId) throw new Error('ZOOMINFO_CLIENT_ID required for private-key authentication')
+ const crypto = require('node:crypto')
+ let key
+ try {
+ key = crypto.createPrivateKey(privateKey)
+ if (key.asymmetricKeyType !== 'rsa') throw new Error('RS256 requires an RSA key')
+ } catch {
+ throw new Error('ZOOMINFO_PRIVATE_KEY must be a valid RSA private key')
+ }
+ const now = Math.floor(Date.now() / 1000)
+ const header = Buffer.from(JSON.stringify({ alg: 'RS256', typ: 'JWT' })).toString('base64url')
+ const payload = Buffer.from(JSON.stringify({
+ aud: 'enterprise_api', iss: '[email protected]', iat: now, exp: now + 300,
+ client_id: clientId, username,
+ })).toString('base64url')
+ const signingInput = `${header}.${payload}`
+ const signature = crypto.sign('RSA-SHA256', Buffer.from(signingInput), key).toString('base64url')
+ headers.Authorization = `Bearer ${signingInput}.${signature}`
+ } else {
+ const password = process.env.ZOOMINFO_PASSWORD
+ if (!password) throw new Error('ZOOMINFO_PASSWORD or ZOOMINFO_PRIVATE_KEY + ZOOMINFO_CLIENT_ID required for authentication')
+ body = JSON.stringify({ username, password })
}
const res = await fetch(`${BASE_URL}/authenticate`, {
method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ username, password }),
+ headers,
+ body,
})
const text = await res.text()
if (!res.ok) {
diff --git a/tools/integrations/zoominfo.md b/tools/integrations/zoominfo.md
index 697d9cf..b3fdf2a 100644
--- a/tools/integrations/zoominfo.md
+++ b/tools/integrations/zoominfo.md
@@ -14,9 +14,10 @@ B2B contact database and intent data platform with 100M+ business contacts and c
## Authentication
- **Type**: JWT Token (Bearer)
-- **Flow**: POST `/authenticate` with username + password, receive JWT token
+- **Flow**: POST `/authenticate` using either username/password or a locally signed PKI assertion; receive the API JWT
- **Header**: `Authorization: Bearer {jwt_token}`
-- **Env vars**: `ZOOMINFO_USERNAME` + `ZOOMINFO_PRIVATE_KEY` or `ZOOMINFO_ACCESS_TOKEN`
+- **Env vars**: `ZOOMINFO_ACCESS_TOKEN`, or `ZOOMINFO_USERNAME` + `ZOOMINFO_PASSWORD`, or `ZOOMINFO_USERNAME` + `ZOOMINFO_CLIENT_ID` + `ZOOMINFO_PRIVATE_KEY`
+- **PKI**: Set `ZOOMINFO_PRIVATE_KEY` to the multiline RSA PEM issued for your API client. The CLI signs a five-minute RS256 assertion locally and sends it as `Authorization: Bearer ...` to `/authenticate`. It never sends the key as a password. A configured private key requires its client ID and cannot fall back to password authentication.
- **Get credentials**: Contact ZoomInfo sales or admin portal at https://app.zoominfo.com
## Common Agent Operations
@@ -28,10 +29,12 @@ POST https://api.zoominfo.com/authenticate
{
"username": "[email protected]",
- "password": "private-key-here"
+ "password": "account-password-here"
}
```
+The JSON example above is the password flow. PKI instead sends the signed assertion in the header with no credentials in the body. The assertion uses the claims documented by [ZoomInfo's official authentication client](https://github.com/Zoominfo/api-auth-python-client/blob/master/zi_api_auth_client/zi_api_auth_client.py). API calls then use the returned JWT, not the short-lived client assertion. Dry runs mask authorization and make no authentication request.
+
### Contact Search
```bash