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:
- Visit https://ziqx.cc/console
- Navigate to Apps โ Select App โ Auth.
- 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 usuallyS256. If not provided, it will default toplaintext.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
authSecretprivate. - Secret code never be exposed to the client side.