@ziqx/auth 0.0.4 → 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/README.md CHANGED
@@ -27,6 +27,11 @@ import { ZAuthClient } from "@ziqx/auth";
27
27
 
28
28
  const auth = new ZAuthClient({
29
29
  authKey: "YOUR_AUTH_KEY",
30
+ redirectUrl: "YOUR_REDIRECT_URL",
31
+ codeChallenge: "YOUR_CODE_CHALLENGE",
32
+ // Optional parameters
33
+ // codeChallengeMethod: "S256",
34
+ // state: "YOUR_STATE_STRING"
30
35
  });
31
36
  ```
32
37
 
@@ -41,11 +46,29 @@ auth.login(); // Redirects to live auth environment
41
46
  If you're working in a development environment, enable dev mode:
42
47
 
43
48
  ```typescript
44
- auth.login(true); // Redirects to dev auth environment
49
+ auth.login(true); // Redirects to dev auth environment (http://localhost:3000/zauth)
45
50
  ```
46
51
 
47
52
  ---
48
53
 
54
+ ## Access Token Exchange
55
+
56
+ You can use the `ZAuthTokenService` class to exchange an authorization code for an access token.
57
+
58
+ ```typescript
59
+ import { ZAuthTokenService } from "@ziqx/auth";
60
+
61
+ const tokenService = new ZAuthTokenService();
62
+
63
+ const tokenData = await tokenService.getAuthToken({
64
+ authAppKey: "your-app-key",
65
+ authSecret: "your-app-secret",
66
+ code: "authorization-code",
67
+ codeVerifier: "code-verifier",
68
+ redirectUri: "redirect-uri",
69
+ });
70
+ ```
71
+
49
72
  ## Token Validation
50
73
 
51
74
  You can use the `ZAuthTokenService` class to validate authentication tokens issued by ZIQX.
@@ -73,12 +96,22 @@ if (isValid) {
73
96
  #### Constructor
74
97
 
75
98
  ```typescript
76
- new ZAuthClient(options: { authKey: string });
99
+ new ZAuthClient(options: {
100
+ authKey: string;
101
+ redirectUrl: string;
102
+ codeChallenge: string;
103
+ codeChallengeMethod?: string;
104
+ state?: string;
105
+ });
77
106
  ```
78
107
 
79
- | Parameter | Type | Required | Description |
80
- | --------- | ------ | -------- | ----------------------------------------- |
81
- | `authKey` | string | ✅ Yes | Your unique authentication key from ZIQX. |
108
+ | Parameter | Type | Required | Description |
109
+ | --------------------- | ------ | -------- | ----------------------------------------------------------------- |
110
+ | `authKey` | string | ✅ Yes | Your unique authentication key from ZIQX. |
111
+ | `redirectUrl` | string | ✅ Yes | The URL where the user should be redirected after authentication. |
112
+ | `codeChallenge` | string | ✅ Yes | The code challenge for PKCE flow. |
113
+ | `codeChallengeMethod` | string | ❌ No | (Optional) The code challenge method (e.g., "S256"). |
114
+ | `state` | string | ❌ No | (Optional) An opaque value used to maintain state. |
82
115
 
83
116
  #### Methods
84
117
 
@@ -105,21 +138,47 @@ auth.login(true); // Redirects to development portal
105
138
 
106
139
  ##### `validate(token: string): Promise<boolean>`
107
140
 
108
- Validates a given authentication token with the ZIQX Auth API.
141
+ Validates a given authentication token with the ZIQX Auth API (V1).
109
142
 
110
143
  | Parameter | Type | Required | Description |
111
144
  | --------- | ------ | -------- | ------------------------------------------ |
112
145
  | `token` | string | ✅ Yes | The authentication token (JWT or similar). |
113
146
 
147
+ ##### `validateV2(token: string): Promise<boolean>`
148
+
149
+ Validates a given authentication token with the ZIQX Auth API (V2).
150
+
151
+ | Parameter | Type | Required | Description |
152
+ | --------- | ------ | -------- | ------------------------------------- |
153
+ | `token` | string | ✅ Yes | The authentication token to validate. |
154
+
155
+ ##### `getAuthToken(params: GetAuthTokenParams): Promise<any>`
156
+
157
+ Exchanges an authorization code for an access token.
158
+
159
+ **Parameters:**
160
+
161
+ | Parameter | Type | Required | Description |
162
+ | -------------- | ------ | -------- | -------------------------------------------------- |
163
+ | `authAppKey` | string | ✅ Yes | The application key. |
164
+ | `authSecret` | string | ✅ Yes | The application secret. |
165
+ | `code` | string | ✅ Yes | The authorization code received from the callback. |
166
+ | `codeVerifier` | string | ✅ Yes | The code verifier used in PKCE. |
167
+ | `redirectUri` | string | ✅ Yes | The redirect URI used in the initial request. |
168
+
114
169
  **Example:**
115
170
 
116
171
  ```typescript
117
172
  const tokenService = new ZAuthTokenService();
118
- const isValid = await tokenService.validate("your-jwt-token");
173
+ const tokenData = await tokenService.getAuthToken({
174
+ authAppKey: "your-app-key",
175
+ authSecret: "your-app-secret",
176
+ code: "authorization-code",
177
+ codeVerifier: "code-verifier",
178
+ redirectUri: "redirect-uri",
179
+ });
119
180
  ```
120
181
 
121
- Returns `true` if the token is valid and authorized, otherwise `false`.
122
-
123
182
  ---
124
183
 
125
184
  ## Example Implementation
@@ -127,7 +186,11 @@ Returns `true` if the token is valid and authorized, otherwise `false`.
127
186
  ```typescript
128
187
  import { ZAuthClient, ZAuthTokenService } from "@ziqx/auth";
129
188
 
130
- const auth = new ZAuthClient({ authKey: "12345-xyz" });
189
+ const auth = new ZAuthClient({
190
+ authKey: "12345-xyz",
191
+ redirectUrl: "https://myapp.com/callback",
192
+ codeChallenge: "pkce-challenge-string",
193
+ });
131
194
 
132
195
  // Login
133
196
  const loginBtn = document.getElementById("loginBtn");
@@ -140,7 +203,7 @@ const tokenService = new ZAuthTokenService();
140
203
  const token = localStorage.getItem("ziqx_token");
141
204
 
142
205
  if (token) {
143
- const isValid = await tokenService.validate(token);
206
+ const isValid = await tokenService.validateV2(token);
144
207
  console.log("Token valid:", isValid);
145
208
  }
146
209
  ```
@@ -151,7 +214,7 @@ if (token) {
151
214
 
152
215
  - Make sure your `authKey` is valid and corresponds to your environment.
153
216
  - 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.
217
+ - The `ZAuthTokenService` uses `https://ziqx.cc/api/auth/validate-token` internally for V1 and `https://ziqx.cc/zauth/validate` for V2.
155
218
  - This SDK is for **client-side use** only.
156
219
 
157
220
  ---
package/dist/index.d.mts CHANGED
@@ -1,49 +1,63 @@
1
1
  /**
2
2
  * ZAuthClient - A lightweight authentication client for ZIQX Auth.
3
3
  *
4
- * This class helps redirect users to the ZIQX authentication gateway.
4
+ * This class facilitates redirection to the ZIQX authentication gateway.
5
5
  *
6
6
  * Example:
7
7
  * ```ts
8
8
  * import { ZAuthClient } from "@ziqx/auth";
9
9
  *
10
10
  * const auth = new ZAuthClient({
11
- * authKey: "your-auth-key"
11
+ * authKey: "your-auth-key",
12
+ * redirectUrl: "http://localhost:3000/callback",
13
+ * codeChallenge: "your-code-challenge"
12
14
  * });
13
15
  *
14
16
  * // Redirects user to ZIQX Auth
15
17
  * auth.login();
16
18
  *
17
- * // For development mode
19
+ * // For development mode (redirects to localhost)
18
20
  * auth.login(true);
19
21
  * ```
20
22
  */
21
23
  declare class ZAuthClient {
22
24
  private authKey;
25
+ private redirectUrl;
26
+ private codeChallenge;
27
+ private codeChallengeMethod?;
28
+ private state?;
23
29
  /**
24
30
  * Creates a new ZAuthClient instance.
25
31
  *
26
32
  * @param options - The configuration options.
27
33
  * @param options.authKey - The authentication key provided by ZIQX.
34
+ * @param options.redirectUrl - The URL where the user should be redirected after authentication.
35
+ * @param options.codeChallenge - The code challenge for PKCE flow.
36
+ * @param options.codeChallengeMethod - (Optional) The code challenge method (e.g., "S256"). Default is "plaintext".
37
+ * @param options.state - (Optional) An opaque value used to maintain state between the request and the callback.
38
+ * @throws Will throw an error if `authKey`, `redirectUrl`, or `codeChallenge` are missing.
28
39
  */
29
- constructor({ authKey }: {
40
+ constructor({ authKey, redirectUrl, codeChallenge, codeChallengeMethod, state, }: {
30
41
  authKey: string;
42
+ redirectUrl: string;
43
+ codeChallenge: string;
44
+ codeChallengeMethod?: string;
45
+ state?: string;
31
46
  });
32
47
  /**
33
48
  * Redirects the user to the ZIQX authentication page.
34
- *
35
- * @param isDev - (Optional) Set to `true` to use development mode. Defaults to `false`.
36
- *
37
- * @example
38
- * ```ts
39
- * const client = new ZAuthClient({ authKey: "your-auth-key" });
40
- * client.login(); // Redirects to production auth page
41
- * client.login(true); // Redirects to development auth page
42
- * ```
43
49
  */
44
- login(isDev?: boolean): void;
50
+ login(): void;
45
51
  }
46
52
 
53
+ type GetAuthTokenParams = {
54
+ authAppKey: string;
55
+ authSecret: string;
56
+ code: string;
57
+ codeVerifier: string;
58
+ redirectUri: string;
59
+ };
60
+
47
61
  /**
48
62
  * ZAuthTokenService - A simple token validation service for ZIQX Auth.
49
63
  *
@@ -77,6 +91,18 @@ declare class ZAuthTokenService {
77
91
  * ```
78
92
  */
79
93
  validate(token: string): Promise<boolean>;
94
+ /**
95
+ * Exchanges an authorization code for an access token.
96
+ *
97
+ * @param params - The parameters required to exchange the code for a token.
98
+ * @param params.authAppKey - The application key.
99
+ * @param params.authSecret - The application secret.
100
+ * @param params.code - The authorization code received from the callback.
101
+ * @param params.codeVerifier - The code verifier used in PKCE.
102
+ * @param params.redirectUri - The redirect URI used in the initial request.
103
+ * @returns A Promise that resolves to the token response data.
104
+ */
105
+ getAuthToken({ authAppKey, authSecret, code, codeVerifier, redirectUri, }: GetAuthTokenParams): Promise<any>;
80
106
  }
81
107
 
82
108
  export { ZAuthClient, ZAuthTokenService };
package/dist/index.d.ts CHANGED
@@ -1,49 +1,63 @@
1
1
  /**
2
2
  * ZAuthClient - A lightweight authentication client for ZIQX Auth.
3
3
  *
4
- * This class helps redirect users to the ZIQX authentication gateway.
4
+ * This class facilitates redirection to the ZIQX authentication gateway.
5
5
  *
6
6
  * Example:
7
7
  * ```ts
8
8
  * import { ZAuthClient } from "@ziqx/auth";
9
9
  *
10
10
  * const auth = new ZAuthClient({
11
- * authKey: "your-auth-key"
11
+ * authKey: "your-auth-key",
12
+ * redirectUrl: "http://localhost:3000/callback",
13
+ * codeChallenge: "your-code-challenge"
12
14
  * });
13
15
  *
14
16
  * // Redirects user to ZIQX Auth
15
17
  * auth.login();
16
18
  *
17
- * // For development mode
19
+ * // For development mode (redirects to localhost)
18
20
  * auth.login(true);
19
21
  * ```
20
22
  */
21
23
  declare class ZAuthClient {
22
24
  private authKey;
25
+ private redirectUrl;
26
+ private codeChallenge;
27
+ private codeChallengeMethod?;
28
+ private state?;
23
29
  /**
24
30
  * Creates a new ZAuthClient instance.
25
31
  *
26
32
  * @param options - The configuration options.
27
33
  * @param options.authKey - The authentication key provided by ZIQX.
34
+ * @param options.redirectUrl - The URL where the user should be redirected after authentication.
35
+ * @param options.codeChallenge - The code challenge for PKCE flow.
36
+ * @param options.codeChallengeMethod - (Optional) The code challenge method (e.g., "S256"). Default is "plaintext".
37
+ * @param options.state - (Optional) An opaque value used to maintain state between the request and the callback.
38
+ * @throws Will throw an error if `authKey`, `redirectUrl`, or `codeChallenge` are missing.
28
39
  */
29
- constructor({ authKey }: {
40
+ constructor({ authKey, redirectUrl, codeChallenge, codeChallengeMethod, state, }: {
30
41
  authKey: string;
42
+ redirectUrl: string;
43
+ codeChallenge: string;
44
+ codeChallengeMethod?: string;
45
+ state?: string;
31
46
  });
32
47
  /**
33
48
  * Redirects the user to the ZIQX authentication page.
34
- *
35
- * @param isDev - (Optional) Set to `true` to use development mode. Defaults to `false`.
36
- *
37
- * @example
38
- * ```ts
39
- * const client = new ZAuthClient({ authKey: "your-auth-key" });
40
- * client.login(); // Redirects to production auth page
41
- * client.login(true); // Redirects to development auth page
42
- * ```
43
49
  */
44
- login(isDev?: boolean): void;
50
+ login(): void;
45
51
  }
46
52
 
53
+ type GetAuthTokenParams = {
54
+ authAppKey: string;
55
+ authSecret: string;
56
+ code: string;
57
+ codeVerifier: string;
58
+ redirectUri: string;
59
+ };
60
+
47
61
  /**
48
62
  * ZAuthTokenService - A simple token validation service for ZIQX Auth.
49
63
  *
@@ -77,6 +91,18 @@ declare class ZAuthTokenService {
77
91
  * ```
78
92
  */
79
93
  validate(token: string): Promise<boolean>;
94
+ /**
95
+ * Exchanges an authorization code for an access token.
96
+ *
97
+ * @param params - The parameters required to exchange the code for a token.
98
+ * @param params.authAppKey - The application key.
99
+ * @param params.authSecret - The application secret.
100
+ * @param params.code - The authorization code received from the callback.
101
+ * @param params.codeVerifier - The code verifier used in PKCE.
102
+ * @param params.redirectUri - The redirect URI used in the initial request.
103
+ * @returns A Promise that resolves to the token response data.
104
+ */
105
+ getAuthToken({ authAppKey, authSecret, code, codeVerifier, redirectUri, }: GetAuthTokenParams): Promise<any>;
80
106
  }
81
107
 
82
108
  export { ZAuthClient, ZAuthTokenService };
package/dist/index.js CHANGED
@@ -27,38 +27,52 @@ module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/constants.ts
29
29
  var ZAUTH_BASE_URL = "https://ziqx.cc/zauth";
30
- var VALIDATION_URL = "https://ziqx.cc/api/auth/validate-token";
30
+ var TOKEN_URL = "https://ziqx.cc/zauth/token";
31
+ var VALIDATION_URL_V2 = "https://ziqx.cc/zauth/validate";
31
32
 
32
33
  // src/ZAuthClient.ts
33
34
  var ZAuthClient = class {
34
35
  authKey;
36
+ redirectUrl;
37
+ codeChallenge;
38
+ codeChallengeMethod;
39
+ state;
35
40
  /**
36
41
  * Creates a new ZAuthClient instance.
37
42
  *
38
43
  * @param options - The configuration options.
39
44
  * @param options.authKey - The authentication key provided by ZIQX.
45
+ * @param options.redirectUrl - The URL where the user should be redirected after authentication.
46
+ * @param options.codeChallenge - The code challenge for PKCE flow.
47
+ * @param options.codeChallengeMethod - (Optional) The code challenge method (e.g., "S256"). Default is "plaintext".
48
+ * @param options.state - (Optional) An opaque value used to maintain state between the request and the callback.
49
+ * @throws Will throw an error if `authKey`, `redirectUrl`, or `codeChallenge` are missing.
40
50
  */
41
- constructor({ authKey }) {
42
- if (!authKey) {
43
- throw new Error("ZAuthClient: authKey is required.");
51
+ constructor({
52
+ authKey,
53
+ redirectUrl,
54
+ codeChallenge,
55
+ codeChallengeMethod,
56
+ state
57
+ }) {
58
+ if (!authKey || !redirectUrl || !codeChallenge) {
59
+ throw new Error(
60
+ "ZAuthClient: Missing required parameters. `authKey`, `redirectUrl`, and `codeChallenge` are required."
61
+ );
44
62
  }
45
63
  this.authKey = authKey;
64
+ this.redirectUrl = redirectUrl;
65
+ this.codeChallenge = codeChallenge;
66
+ this.codeChallengeMethod = codeChallengeMethod;
67
+ this.state = state;
46
68
  }
47
69
  /**
48
70
  * Redirects the user to the ZIQX authentication page.
49
- *
50
- * @param isDev - (Optional) Set to `true` to use development mode. Defaults to `false`.
51
- *
52
- * @example
53
- * ```ts
54
- * const client = new ZAuthClient({ authKey: "your-auth-key" });
55
- * client.login(); // Redirects to production auth page
56
- * client.login(true); // Redirects to development auth page
57
- * ```
58
71
  */
59
- login(isDev = false) {
60
- const devQuery = isDev ? "&dev=true" : "";
61
- const loginUrl = `${ZAUTH_BASE_URL}?key=${this.authKey}${devQuery}`;
72
+ login() {
73
+ const stateQuery = this.state ? `&state=${this.state}` : "";
74
+ const codeChallengeMethodQuery = this.codeChallengeMethod ? `&challenge_method=${this.codeChallengeMethod}` : "";
75
+ const loginUrl = `${ZAUTH_BASE_URL}?key=${this.authKey}&redir=${this.redirectUrl}&code_challenge=${this.codeChallenge}${codeChallengeMethodQuery}${stateQuery}`;
62
76
  window.location.href = loginUrl;
63
77
  }
64
78
  };
@@ -82,7 +96,7 @@ var ZAuthTokenService = class {
82
96
  throw new Error("ZAuthTokenService: token is required for validation.");
83
97
  }
84
98
  try {
85
- const response = await fetch(VALIDATION_URL, {
99
+ const response = await fetch(VALIDATION_URL_V2, {
86
100
  method: "GET",
87
101
  headers: {
88
102
  Authorization: token
@@ -97,6 +111,44 @@ var ZAuthTokenService = class {
97
111
  return false;
98
112
  }
99
113
  }
114
+ /**
115
+ * Exchanges an authorization code for an access token.
116
+ *
117
+ * @param params - The parameters required to exchange the code for a token.
118
+ * @param params.authAppKey - The application key.
119
+ * @param params.authSecret - The application secret.
120
+ * @param params.code - The authorization code received from the callback.
121
+ * @param params.codeVerifier - The code verifier used in PKCE.
122
+ * @param params.redirectUri - The redirect URI used in the initial request.
123
+ * @returns A Promise that resolves to the token response data.
124
+ */
125
+ async getAuthToken({
126
+ authAppKey,
127
+ authSecret,
128
+ code,
129
+ codeVerifier,
130
+ redirectUri
131
+ }) {
132
+ if (!authAppKey || !authSecret || !code || !codeVerifier || !redirectUri) {
133
+ throw new Error("ZAuthTokenService: All parameters are required");
134
+ }
135
+ const response = await fetch(TOKEN_URL, {
136
+ method: "POST",
137
+ body: JSON.stringify({
138
+ code,
139
+ grant_type: "authorization_code",
140
+ code_verifier: codeVerifier,
141
+ redirect_uri: redirectUri
142
+ }),
143
+ headers: {
144
+ "Content-Type": "application/json",
145
+ "x-app-key": authAppKey,
146
+ "x-app-secret": authSecret
147
+ }
148
+ });
149
+ const data = await response.json();
150
+ return data;
151
+ }
100
152
  };
101
153
  // Annotate the CommonJS export names for ESM import in node:
102
154
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,37 +1,51 @@
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
+ var TOKEN_URL = "https://ziqx.cc/zauth/token";
4
+ var VALIDATION_URL_V2 = "https://ziqx.cc/zauth/validate";
4
5
 
5
6
  // src/ZAuthClient.ts
6
7
  var ZAuthClient = class {
7
8
  authKey;
9
+ redirectUrl;
10
+ codeChallenge;
11
+ codeChallengeMethod;
12
+ state;
8
13
  /**
9
14
  * Creates a new ZAuthClient instance.
10
15
  *
11
16
  * @param options - The configuration options.
12
17
  * @param options.authKey - The authentication key provided by ZIQX.
18
+ * @param options.redirectUrl - The URL where the user should be redirected after authentication.
19
+ * @param options.codeChallenge - The code challenge for PKCE flow.
20
+ * @param options.codeChallengeMethod - (Optional) The code challenge method (e.g., "S256"). Default is "plaintext".
21
+ * @param options.state - (Optional) An opaque value used to maintain state between the request and the callback.
22
+ * @throws Will throw an error if `authKey`, `redirectUrl`, or `codeChallenge` are missing.
13
23
  */
14
- constructor({ authKey }) {
15
- if (!authKey) {
16
- throw new Error("ZAuthClient: authKey is required.");
24
+ constructor({
25
+ authKey,
26
+ redirectUrl,
27
+ codeChallenge,
28
+ codeChallengeMethod,
29
+ state
30
+ }) {
31
+ if (!authKey || !redirectUrl || !codeChallenge) {
32
+ throw new Error(
33
+ "ZAuthClient: Missing required parameters. `authKey`, `redirectUrl`, and `codeChallenge` are required."
34
+ );
17
35
  }
18
36
  this.authKey = authKey;
37
+ this.redirectUrl = redirectUrl;
38
+ this.codeChallenge = codeChallenge;
39
+ this.codeChallengeMethod = codeChallengeMethod;
40
+ this.state = state;
19
41
  }
20
42
  /**
21
43
  * Redirects the user to the ZIQX authentication page.
22
- *
23
- * @param isDev - (Optional) Set to `true` to use development mode. Defaults to `false`.
24
- *
25
- * @example
26
- * ```ts
27
- * const client = new ZAuthClient({ authKey: "your-auth-key" });
28
- * client.login(); // Redirects to production auth page
29
- * client.login(true); // Redirects to development auth page
30
- * ```
31
44
  */
32
- login(isDev = false) {
33
- const devQuery = isDev ? "&dev=true" : "";
34
- const loginUrl = `${ZAUTH_BASE_URL}?key=${this.authKey}${devQuery}`;
45
+ login() {
46
+ const stateQuery = this.state ? `&state=${this.state}` : "";
47
+ const codeChallengeMethodQuery = this.codeChallengeMethod ? `&challenge_method=${this.codeChallengeMethod}` : "";
48
+ const loginUrl = `${ZAUTH_BASE_URL}?key=${this.authKey}&redir=${this.redirectUrl}&code_challenge=${this.codeChallenge}${codeChallengeMethodQuery}${stateQuery}`;
35
49
  window.location.href = loginUrl;
36
50
  }
37
51
  };
@@ -55,7 +69,7 @@ var ZAuthTokenService = class {
55
69
  throw new Error("ZAuthTokenService: token is required for validation.");
56
70
  }
57
71
  try {
58
- const response = await fetch(VALIDATION_URL, {
72
+ const response = await fetch(VALIDATION_URL_V2, {
59
73
  method: "GET",
60
74
  headers: {
61
75
  Authorization: token
@@ -70,6 +84,44 @@ var ZAuthTokenService = class {
70
84
  return false;
71
85
  }
72
86
  }
87
+ /**
88
+ * Exchanges an authorization code for an access token.
89
+ *
90
+ * @param params - The parameters required to exchange the code for a token.
91
+ * @param params.authAppKey - The application key.
92
+ * @param params.authSecret - The application secret.
93
+ * @param params.code - The authorization code received from the callback.
94
+ * @param params.codeVerifier - The code verifier used in PKCE.
95
+ * @param params.redirectUri - The redirect URI used in the initial request.
96
+ * @returns A Promise that resolves to the token response data.
97
+ */
98
+ async getAuthToken({
99
+ authAppKey,
100
+ authSecret,
101
+ code,
102
+ codeVerifier,
103
+ redirectUri
104
+ }) {
105
+ if (!authAppKey || !authSecret || !code || !codeVerifier || !redirectUri) {
106
+ throw new Error("ZAuthTokenService: All parameters are required");
107
+ }
108
+ const response = await fetch(TOKEN_URL, {
109
+ method: "POST",
110
+ body: JSON.stringify({
111
+ code,
112
+ grant_type: "authorization_code",
113
+ code_verifier: codeVerifier,
114
+ redirect_uri: redirectUri
115
+ }),
116
+ headers: {
117
+ "Content-Type": "application/json",
118
+ "x-app-key": authAppKey,
119
+ "x-app-secret": authSecret
120
+ }
121
+ });
122
+ const data = await response.json();
123
+ return data;
124
+ }
73
125
  };
74
126
  export {
75
127
  ZAuthClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziqx/auth",
3
- "version": "0.0.4",
3
+ "version": "1.0.0",
4
4
  "description": "SDK for Ziqx Authentication",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",