@ziqx/auth 0.0.1 → 0.0.3
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/.gitattributes +2 -0
- package/README.md +60 -5
- package/dist/index.d.mts +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.js +41 -2
- package/dist/index.mjs +39 -1
- package/package.json +1 -1
package/.gitattributes
ADDED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ziqx/auth
|
|
2
2
|
|
|
3
|
-
A lightweight authentication SDK for ZIQX platforms. Provides an easy interface to trigger the authentication flow from your frontend.
|
|
3
|
+
A lightweight authentication SDK for ZIQX platforms. Provides an easy interface to trigger the authentication flow and validate tokens from your frontend.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -46,6 +46,26 @@ auth.login(true); // Redirects to dev auth environment
|
|
|
46
46
|
|
|
47
47
|
---
|
|
48
48
|
|
|
49
|
+
## Token Validation
|
|
50
|
+
|
|
51
|
+
You can use the `ZAuthTokenService` class to validate authentication tokens issued by ZIQX.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { ZAuthTokenService } from "@ziqx/auth";
|
|
55
|
+
|
|
56
|
+
const tokenService = new ZAuthTokenService();
|
|
57
|
+
|
|
58
|
+
const isValid = await tokenService.validate("your-jwt-token");
|
|
59
|
+
|
|
60
|
+
if (isValid) {
|
|
61
|
+
console.log("Token is valid");
|
|
62
|
+
} else {
|
|
63
|
+
console.log("Invalid or expired token");
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
49
69
|
## API Reference
|
|
50
70
|
|
|
51
71
|
### Class: `ZAuthClient`
|
|
@@ -79,16 +99,50 @@ auth.login(true); // Redirects to development portal
|
|
|
79
99
|
|
|
80
100
|
---
|
|
81
101
|
|
|
102
|
+
### Class: `ZAuthTokenService`
|
|
103
|
+
|
|
104
|
+
#### Methods
|
|
105
|
+
|
|
106
|
+
##### `validate(token: string): Promise<boolean>`
|
|
107
|
+
|
|
108
|
+
Validates a given authentication token with the ZIQX Auth API.
|
|
109
|
+
|
|
110
|
+
| Parameter | Type | Required | Description |
|
|
111
|
+
| --------- | ------ | -------- | ------------------------------------------ |
|
|
112
|
+
| `token` | string | ✅ Yes | The authentication token (JWT or similar). |
|
|
113
|
+
|
|
114
|
+
**Example:**
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const tokenService = new ZAuthTokenService();
|
|
118
|
+
const isValid = await tokenService.validate("your-jwt-token");
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Returns `true` if the token is valid and authorized, otherwise `false`.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
82
125
|
## Example Implementation
|
|
83
126
|
|
|
84
127
|
```typescript
|
|
85
|
-
import { ZAuthClient } from "@ziqx/auth";
|
|
128
|
+
import { ZAuthClient, ZAuthTokenService } from "@ziqx/auth";
|
|
86
129
|
|
|
87
130
|
const auth = new ZAuthClient({ authKey: "12345-xyz" });
|
|
88
131
|
|
|
89
|
-
|
|
132
|
+
// Login
|
|
133
|
+
const loginBtn = document.getElementById("loginBtn");
|
|
134
|
+
loginBtn?.addEventListener("click", () => {
|
|
90
135
|
auth.login();
|
|
91
136
|
});
|
|
137
|
+
|
|
138
|
+
// Token validation example
|
|
139
|
+
const tokenService = new ZAuthTokenService();
|
|
140
|
+
const token = localStorage.getItem("ziqx_token");
|
|
141
|
+
|
|
142
|
+
if (token) {
|
|
143
|
+
const isValid = await tokenService.validate(token);
|
|
144
|
+
console.log("Token valid:", isValid);
|
|
145
|
+
}
|
|
92
146
|
```
|
|
93
147
|
|
|
94
148
|
---
|
|
@@ -96,8 +150,9 @@ document.getElementById("loginBtn")?.addEventListener("click", () => {
|
|
|
96
150
|
## Notes
|
|
97
151
|
|
|
98
152
|
- Make sure your `authKey` is valid and corresponds to your environment.
|
|
99
|
-
-
|
|
100
|
-
-
|
|
153
|
+
- Use `auth.login(true)` in development mode (e.g., on localhost or staging).
|
|
154
|
+
- The `ZAuthTokenService` uses `https://ziqx.cc/api/auth/validate-token` internally.
|
|
155
|
+
- This SDK is for **client-side use** only.
|
|
101
156
|
|
|
102
157
|
---
|
|
103
158
|
|
package/dist/index.d.mts
CHANGED
|
@@ -44,4 +44,39 @@ declare class ZAuthClient {
|
|
|
44
44
|
login(isDev?: boolean): void;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* ZAuthTokenService - A simple token validation service for ZIQX Auth.
|
|
49
|
+
*
|
|
50
|
+
* This class provides a method to validate authentication tokens issued by ZIQX.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { ZAuthTokenService } from "@ziqx/auth";
|
|
55
|
+
*
|
|
56
|
+
* const tokenService = new ZAuthTokenService();
|
|
57
|
+
* const isValid = await tokenService.validate("your-jwt-token");
|
|
58
|
+
*
|
|
59
|
+
* if (isValid) {
|
|
60
|
+
* console.log("Token is valid");
|
|
61
|
+
* } else {
|
|
62
|
+
* console.log("Invalid or expired token");
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class ZAuthTokenService {
|
|
67
|
+
/**
|
|
68
|
+
* Validates a given authentication token with the ZIQX Auth API.
|
|
69
|
+
*
|
|
70
|
+
* @param token - The authentication token (JWT or similar) to validate.
|
|
71
|
+
* @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const tokenService = new ZAuthTokenService();
|
|
76
|
+
* const isValid = await tokenService.validate("your-jwt-token");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
validate(token: string): Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { ZAuthClient, ZAuthTokenService };
|
package/dist/index.d.ts
CHANGED
|
@@ -44,4 +44,39 @@ declare class ZAuthClient {
|
|
|
44
44
|
login(isDev?: boolean): void;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* ZAuthTokenService - A simple token validation service for ZIQX Auth.
|
|
49
|
+
*
|
|
50
|
+
* This class provides a method to validate authentication tokens issued by ZIQX.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { ZAuthTokenService } from "@ziqx/auth";
|
|
55
|
+
*
|
|
56
|
+
* const tokenService = new ZAuthTokenService();
|
|
57
|
+
* const isValid = await tokenService.validate("your-jwt-token");
|
|
58
|
+
*
|
|
59
|
+
* if (isValid) {
|
|
60
|
+
* console.log("Token is valid");
|
|
61
|
+
* } else {
|
|
62
|
+
* console.log("Invalid or expired token");
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class ZAuthTokenService {
|
|
67
|
+
/**
|
|
68
|
+
* Validates a given authentication token with the ZIQX Auth API.
|
|
69
|
+
*
|
|
70
|
+
* @param token - The authentication token (JWT or similar) to validate.
|
|
71
|
+
* @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const tokenService = new ZAuthTokenService();
|
|
76
|
+
* const isValid = await tokenService.validate("your-jwt-token");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
validate(token: string): Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { ZAuthClient, ZAuthTokenService };
|
package/dist/index.js
CHANGED
|
@@ -20,12 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
ZAuthClient: () => ZAuthClient
|
|
23
|
+
ZAuthClient: () => ZAuthClient,
|
|
24
|
+
ZAuthTokenService: () => ZAuthTokenService
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(src_exports);
|
|
26
27
|
|
|
27
28
|
// src/constants.ts
|
|
28
29
|
var ZAUTH_BASE_URL = "https://ziqx.cc/zauth";
|
|
30
|
+
var VALIDATION_URL = "https://ziqx.cc/api/auth/validate-token";
|
|
29
31
|
|
|
30
32
|
// src/ZAuthClient.ts
|
|
31
33
|
var ZAuthClient = class {
|
|
@@ -60,7 +62,44 @@ var ZAuthClient = class {
|
|
|
60
62
|
window.location.href = loginUrl;
|
|
61
63
|
}
|
|
62
64
|
};
|
|
65
|
+
|
|
66
|
+
// src/ZAuthTokenService.ts
|
|
67
|
+
var ZAuthTokenService = class {
|
|
68
|
+
/**
|
|
69
|
+
* Validates a given authentication token with the ZIQX Auth API.
|
|
70
|
+
*
|
|
71
|
+
* @param token - The authentication token (JWT or similar) to validate.
|
|
72
|
+
* @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const tokenService = new ZAuthTokenService();
|
|
77
|
+
* const isValid = await tokenService.validate("your-jwt-token");
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
async validate(token) {
|
|
81
|
+
if (!token) {
|
|
82
|
+
throw new Error("ZAuthTokenService: token is required for validation.");
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const response = await fetch(VALIDATION_URL, {
|
|
86
|
+
method: "GET",
|
|
87
|
+
headers: {
|
|
88
|
+
Authorization: token
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (response.status !== 200)
|
|
92
|
+
return false;
|
|
93
|
+
const data = await response.json();
|
|
94
|
+
return data.success === true;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("ZAuthTokenService: Validation failed:", error);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
63
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
102
|
0 && (module.exports = {
|
|
65
|
-
ZAuthClient
|
|
103
|
+
ZAuthClient,
|
|
104
|
+
ZAuthTokenService
|
|
66
105
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
2
|
var ZAUTH_BASE_URL = "https://ziqx.cc/zauth";
|
|
3
|
+
var VALIDATION_URL = "https://ziqx.cc/api/auth/validate-token";
|
|
3
4
|
|
|
4
5
|
// src/ZAuthClient.ts
|
|
5
6
|
var ZAuthClient = class {
|
|
@@ -34,6 +35,43 @@ var ZAuthClient = class {
|
|
|
34
35
|
window.location.href = loginUrl;
|
|
35
36
|
}
|
|
36
37
|
};
|
|
38
|
+
|
|
39
|
+
// src/ZAuthTokenService.ts
|
|
40
|
+
var ZAuthTokenService = class {
|
|
41
|
+
/**
|
|
42
|
+
* Validates a given authentication token with the ZIQX Auth API.
|
|
43
|
+
*
|
|
44
|
+
* @param token - The authentication token (JWT or similar) to validate.
|
|
45
|
+
* @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const tokenService = new ZAuthTokenService();
|
|
50
|
+
* const isValid = await tokenService.validate("your-jwt-token");
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
async validate(token) {
|
|
54
|
+
if (!token) {
|
|
55
|
+
throw new Error("ZAuthTokenService: token is required for validation.");
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(VALIDATION_URL, {
|
|
59
|
+
method: "GET",
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: token
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (response.status !== 200)
|
|
65
|
+
return false;
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
return data.success === true;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error("ZAuthTokenService: Validation failed:", error);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
37
74
|
export {
|
|
38
|
-
ZAuthClient
|
|
75
|
+
ZAuthClient,
|
|
76
|
+
ZAuthTokenService
|
|
39
77
|
};
|