-
Notifications
You must be signed in to change notification settings - Fork 4
/
VerifyKit.js
77 lines (72 loc) · 2.2 KB
/
VerifyKit.js
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
77
const request = require('request');
function VerifyKit(server_key) {
this.server_key = server_key;
this.api_version = "v1.0";
this.api_url = "https://api.verifykit.com/";
this.validate_api_path = "/result";
this.web_access_token_api_path = "/access-token";
}
VerifyKit.prototype.setApiVersion = function (api_version) {
this.api_version = api_version;
};
VerifyKit.prototype.validate = function (sessionId) {
const options = {
method: 'POST',
uri: this.api_url + this.api_version + this.validate_api_path,
json: true,
headers: {
"X-Vfk-Server-Key": this.server_key,
},
body: {
"sessionId": sessionId
}
};
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if (error) {
reject({
requestId: '',
httpStatusCode: 0,
errorMessage: 'Failed to validate this session id with VerifyKit.',
errorCode: '0'
});
return;
}
if (response.statusCode !== 200) {
reject(body.meta);
} else {
resolve(body.result);
}
});
});
};
VerifyKit.prototype.getWebAccessToken = function () {
const options = {
method: 'GET',
uri: this.api_url + this.api_version + this.web_access_token_api_path,
json: true,
headers: {
"X-Vfk-Server-Key": this.server_key,
}
};
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if (error) {
console.log(error);
reject({
requestId: '',
httpStatusCode: 0,
errorMessage: 'Failed to get web access token from VerifyKit.',
errorCode: '0'
});
return;
}
if (response.statusCode !== 200) {
reject(body.meta);
} else {
resolve(body.result);
}
});
});
};
module.exports = VerifyKit;