Skip to main content

ZAuth SDK Integration

Easily integrate authentication into your app using the @ziqx/auth SDK. This package handles user authentication by redirecting users securely to ZIQX Auth.


๐Ÿ“ฆ Installation#

npm install @ziqx/auth# orpnpm add @ziqx/auth# oryarn add @ziqx/auth

โš™๏ธ Setup#

To use ZIQX Auth, you need an Auth Key. You can obtain it from your ZIQX Console:

  1. Visit https://ziqx.cc/console
  2. Navigate to Apps โ†’ Select App โ†’ Auth.
  3. Copy your Auth Key

๐Ÿš€ Usage Example#

import { ZAuthClient } from "@ziqx/auth";
// Initialize with your Auth Keyconst auth = new ZAuthClient({  authKey: "YOUR_AUTH_KEY",  redirectUrl: "YOUR_REDIRECT_URL",  codeChallenge: "YOUR_CODE_CHALLENGE",  codeChallengeMethod: "S256", // Optional  state: "YOUR_STATE_STRING", // Optional});
// Trigger login flowauth.login();

This will redirect the user to the ZIQX Auth page.

Parameters#

  • authKey โ€” Your auth service key obtained from ZIQX Console.
  • redirectUrl โ€” The URL to redirect to after successful authentication. This URL must be registered in your ZIQX Console.
  • codeChallenge โ€” The code challenge for the authentication flow. This is a random string or hash generated by your app to add extra security to the authentication flow.
  • codeChallengeMethod (optional) โ€” The code challenge method for the authentication flow. This is usually S256. If not provided, it will default to plaintext.
  • state (optional) โ€” You can pass any values you want to be returned to your app after successful authentication.

Get Access Token#

Once the authentication is successful, user will be redirected with a query parameter code, which is a temporary auth code that can be used to get the access token. From your backend, you can use this auth code to get the access token.

import { ZAuthTokenService } from "@ziqx/auth";
const tokenService = new ZAuthTokenService();const response = await tokenService.getAuthToken({  authAppKey: "YOUR_AUTH_APP_KEY",  authSecret: "YOUR_AUTH_SECRET",  code: "YOUR_AUTH_CODE",  codeVerifier: "YOUR_CODE_VERIFIER",  redirectUri: "YOUR_REDIRECT_URI",});
console.log(response);

Parameters#

  • authAppKey โ€” Your auth service key obtained from ZIQX Console.
  • authSecret โ€” Your auth secret obtained from ZIQX Console.
  • code โ€” The auth code received from the Auth page.
  • codeVerifier โ€” The code challenge used in the authentication flow.
  • redirectUri โ€” The redirect URI used for this authentication flow.

๐Ÿ” Token Validation#

In addition to login, you can validate tokens issued by ZIQX using the ZAuthTokenService.

import { ZAuthTokenService } from "@ziqx/auth";
const tokenService = new ZAuthTokenService();const isValid = await tokenService.validate("your-jwt-token");
if (isValid) {  console.log("โœ… Token is valid");} else {  console.log("โŒ Invalid or expired token");}

โšก Manual Integration (Alternative)#

If you prefer to integrate manually without the SDK, see our Manual Auth Implementation Guide.

However, using the @ziqx/auth package is strongly recommended for easier maintenance and future updates.


๐Ÿงฉ Notes#

  • Ensure your app's callback URL is configured in your ZIQX Console.
  • Always keep your authSecret private.
  • Secret code never be exposed to the client side.