knox-auth 1.0.0
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/index.js +41 -0
- package/package.json +12 -0
package/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
const fetch = require('node-fetch');
|
|
3
|
+
|
|
4
|
+
class KnoxAuth {
|
|
5
|
+
constructor(appId, secret, version) {
|
|
6
|
+
this.appId = appId;
|
|
7
|
+
this.secret = secret;
|
|
8
|
+
this.version = version;
|
|
9
|
+
this.baseUrl = "https://knoxauth.dev/api/v1";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async authenticate(licenseKey, hwid) {
|
|
13
|
+
try {
|
|
14
|
+
const response = await fetch(`${this.baseUrl}/authenticate`, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: { 'Content-Type': 'application/json' },
|
|
17
|
+
body: JSON.stringify({
|
|
18
|
+
application_id: this.appId,
|
|
19
|
+
secret: this.secret,
|
|
20
|
+
version: this.version,
|
|
21
|
+
license_key: licenseKey,
|
|
22
|
+
hwid: hwid
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
return { success: false, message: `Server error: ${response.statusText}` };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const data = await response.json();
|
|
31
|
+
return data.success
|
|
32
|
+
? { success: true, user: data.user, message: "Authenticated" }
|
|
33
|
+
: { success: false, message: data.error || "Unknown error" };
|
|
34
|
+
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return { success: false, message: `Connection error: ${error.message}` };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = KnoxAuth;
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "knox-auth",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Knox Auth SDK for Node.js",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"author": "Worek The Sami",
|
|
11
|
+
"license": "MIT"
|
|
12
|
+
}
|