@nooks-ai/nooks-zoominfo-api-auth-client 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +23 -0
- package/index.js +76 -0
- package/package.json +16 -0
package/README.MD
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Zoominfo API Auth Client
|
|
2
|
+
|
|
3
|
+
An API Authentication client to generate access token for Zoominfo API
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
```
|
|
7
|
+
npm i zoominfo-api-auth-client
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### Usage
|
|
11
|
+
|
|
12
|
+
#### Get access token using client id and private key
|
|
13
|
+
```
|
|
14
|
+
var authClient = require('zoominfo-api-auth-client');
|
|
15
|
+
var pkiAuthPromise = authClient.getAccessTokenViaPKI("username", "clientId", "privateKey");
|
|
16
|
+
pkiAuthPromise.then(token => console.log(token));
|
|
17
|
+
```
|
|
18
|
+
#### Get access token using username and password
|
|
19
|
+
```
|
|
20
|
+
var authClient = require('zoominfo-api-auth-client');
|
|
21
|
+
var basicAuthPromise = authClient.getAccessTokenViaBasicAuth("username", "password");
|
|
22
|
+
basicAuthPromise.then(token => console.log(token));
|
|
23
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zoominfo API Authentication Client
|
|
3
|
+
*
|
|
4
|
+
* Get JWT access token using one of the following ways
|
|
5
|
+
* - PKI Auth flow using username, client id and private key
|
|
6
|
+
* - Username and Password
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const axios = require('axios');
|
|
10
|
+
const rs = require('jsrsasign');
|
|
11
|
+
const AUTH_URL = 'https://api.zoominfo.com/authenticate';
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
getAccessTokenViaPKI: getAccessTokenViaPKI,
|
|
15
|
+
getAccessTokenViaBasicAuth: getAccessTokenViaBasicAuth
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getAccessTokenViaBasicAuth(username, password) {
|
|
19
|
+
return axios.post(AUTH_URL,
|
|
20
|
+
{
|
|
21
|
+
username: username,
|
|
22
|
+
password: password
|
|
23
|
+
})
|
|
24
|
+
.then(res => {
|
|
25
|
+
return res.data.jwt;
|
|
26
|
+
})
|
|
27
|
+
.catch(err => {
|
|
28
|
+
return err
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getAccessTokenViaPKI(username, clientId, privateKey) {
|
|
33
|
+
const dtNow = Date.now();
|
|
34
|
+
let alg = "RS256";
|
|
35
|
+
let iss = "zoominfo-api-auth-client-nodejs";
|
|
36
|
+
let aud = "enterprise_api";
|
|
37
|
+
let header = {
|
|
38
|
+
"typ": "JWT",
|
|
39
|
+
"alg": alg
|
|
40
|
+
};
|
|
41
|
+
let data = {
|
|
42
|
+
"aud": aud,
|
|
43
|
+
"iss": iss,
|
|
44
|
+
"username": username,
|
|
45
|
+
"client_id": clientId,
|
|
46
|
+
"iat": getIAT(dtNow),
|
|
47
|
+
"exp": getEXP(dtNow)
|
|
48
|
+
};
|
|
49
|
+
let sHeader = JSON.stringify(header);
|
|
50
|
+
let sPayload = JSON.stringify(data);
|
|
51
|
+
|
|
52
|
+
let clientJWT = rs.jws.JWS.sign(header.alg, sHeader, sPayload, privateKey);
|
|
53
|
+
return axios.post(AUTH_URL,
|
|
54
|
+
{},
|
|
55
|
+
{
|
|
56
|
+
headers: {
|
|
57
|
+
'Authorization': 'Bearer ' + clientJWT
|
|
58
|
+
}
|
|
59
|
+
}).then(res => {
|
|
60
|
+
return res.data.jwt;
|
|
61
|
+
}).catch(err => {
|
|
62
|
+
return err
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getIAT(dtNow) {
|
|
67
|
+
let iat = Math.floor(dtNow / 1000);
|
|
68
|
+
iat = iat - 60;
|
|
69
|
+
return iat;
|
|
70
|
+
}
|
|
71
|
+
function getEXP(dtNow) {
|
|
72
|
+
let exp = Math.floor(dtNow / 1000) + (5 * 60);
|
|
73
|
+
exp = exp - 60;
|
|
74
|
+
return exp;
|
|
75
|
+
}
|
|
76
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nooks-ai/nooks-zoominfo-api-auth-client",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Zoominfo API Authentication Client (Nooks fork)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "Nooks",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"axios": "^0.28.0",
|
|
13
|
+
"jsrsasign": "^10.2.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {}
|
|
16
|
+
}
|