-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (69 loc) · 2.09 KB
/
index.js
File metadata and controls
76 lines (69 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const axios = require("axios");
const bodyParser = require("body-parser");
const cors = require("cors");
const express = require("express");
const app = express();
const port = 5000;
const {
PassbaseClient,
PassbaseConfiguration,
ResponseFormats,
} = require("@passbase/node");
app.use(bodyParser.json());
app.use(cors());
const apiKey = "SECRET_API_KEY";
// call the Passbase API getIdentity endpoint with Passbase Node.js server-side library
const config = new PassbaseConfiguration({
apiKey,
format: ResponseFormats.Json,
});
const callPassbaseAPI = async (identityAccessKey) => {
const client = new PassbaseClient(config);
const identity = await client.getIdentityById(identityAccessKey);
console.log("IDENTITY INFO HERE: ", identity);
console.log(identity.resources)
};
// call the Passbase API getIdentity endpoint with Axios
// const callWithAxios = (id) => {
// var config = {
// method: 'get',
// url: `https://api.passbase.com/verification/v1/identities/${id}`,
// headers: {
// 'X-API-KEY': apiKey
// }
// };
// return new Promise((resolve, reject) => {
// axios(config)
// .then((response) => {
// resolve(response.data)
// })
// .catch((error) => {
// console.log(error);
// reject(error)
// });
// });
// }
// Receive Passbase webhook events
app.post("/passbase-webhooks", async (req, res) => {
const webhook = req.body;
switch (webhook.event) {
case "VERIFICATION_REVIEWED":
console.log("VERIFICATION_REVIEWED");
callPassbaseAPI(webhook.key);
break;
case "IDENTITY_AUTHENTICATED":
console.log("IDENTITY_AUTHENTICATED");
callPassbaseAPI(webhook.key);
break;
case "VERIFICATION_COMPLETED":
console.log("VERIFICATION_COMPLETED");
callPassbaseAPI(webhook.key);
break;
default:
console.log("Couldn't process webhook event");
}
res.status(200).send("Success");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});