authly-me 0.0.2 → 0.0.4
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 +30 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,11 +4,11 @@ class Authly {
|
|
|
4
4
|
|
|
5
5
|
constructor(server_url, key, options={}) {
|
|
6
6
|
|
|
7
|
-
if (!server_url) {
|
|
7
|
+
if (!server_url || server_url === '' || server_url.trim() === '') {
|
|
8
8
|
throw new Error('Server is required');
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
if (!key) {
|
|
11
|
+
if (!key || key === '' || key.trim() === '') {
|
|
12
12
|
throw new Error('Key is required');
|
|
13
13
|
}
|
|
14
14
|
this.key = key;
|
|
@@ -16,6 +16,7 @@ class Authly {
|
|
|
16
16
|
this.callback_url = options?.callback_url ?? null;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// Generate App Auth Link
|
|
19
20
|
async generateAppAuthLink() {
|
|
20
21
|
const payload = {
|
|
21
22
|
key: this.key
|
|
@@ -27,13 +28,39 @@ class Authly {
|
|
|
27
28
|
|
|
28
29
|
let response;
|
|
29
30
|
try {
|
|
30
|
-
response = await axios.post(`${this.server_url}/auth/app/generate-link`, payload);
|
|
31
|
+
response = await axios.post(`${this.server_url}/v1/auth/app/generate-link`, payload);
|
|
31
32
|
return response.data;
|
|
32
33
|
} catch (error) {
|
|
33
34
|
return error.response.data;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
// Verify Token
|
|
39
|
+
async verifyToken(token) {
|
|
40
|
+
if (!token || token === '' || token.trim() === '') {
|
|
41
|
+
throw new Error('Token is required');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const payload = {
|
|
45
|
+
key: this.key,
|
|
46
|
+
token: token
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let response;
|
|
50
|
+
try {
|
|
51
|
+
response = await axios.post(`${this.server_url}/v1/auth/app/verify-token`, payload);
|
|
52
|
+
return response.data;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return error.response.data;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// TODO : Get available credits ( company level )
|
|
59
|
+
|
|
60
|
+
// TODO : Get credits used ( app level )
|
|
61
|
+
|
|
62
|
+
// TODO : Logout ( given the token )
|
|
63
|
+
|
|
37
64
|
}
|
|
38
65
|
|
|
39
66
|
module.exports = Authly;
|