@ziqx/auth 0.0.1 → 0.0.2
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/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
|
|