Authentication Configuration for Node
To use the JavaScript SDK methods for server or node operations, you need to fulfill the following prerequsites to ensure the methods are accessed in an authenticated manner:
Install Requirement
Import Requirement
import {zcAuth} from '@zcatalyst/auth';
Initialize the SDK
Once the above prerequisites are fulfilled, you can initalize the Catalyst JavaScript SDK in Catalyst functions in the following manner:
const { zcAuth }= require(’@zcatalyst/auth’);
module.exports = (req, res) =>
{
const app = await zcAuth.init(req);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}
const { zcAuth }= require(’@zcatalyst/auth’);
const express = require(’express’);
const expressApp = express();
expressApp.get(’/’,(req,res)=>
{
const app = await zcAuth.init(req);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
});
module.exports=expressApp;
const { zcAuth }= require(’@zcatalyst/auth’);
module.exports = (context, basicIO) =>
{
const app = await zcAuth.init(context);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}
const { zcAuth }= require(’@zcatalyst/auth’);
module.exports = (event, context) =>
{
const app = await zcAuth.init(context);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}
const { zcAuth }= require(’@zcatalyst/auth’);
module.exports = (cronDetails, context) =>
{
const app = await zcAuth.init(context);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}
Initialize with Scopes
Catalyst allows you to initialize the SDK in a project using the following scopes:
- Admin: You have unrestricted access to all the components and their respective functionalities.
- User: You can restrict access to components and specific functionalities.
- It is not mandatory for you to initialize the projects with scopes. By default, a project that is initialized will have Admin privileges.
- Ensure you have initialized the Catalyst SDK with the appropriate scope while you engineer your business logic. The permissions you define for your scope control your end-user’s actions.
- Depending on how you engineer your business logic, you can decide if your end-users can perform Admin or User actions. This is decided based on the role assigned to your end-user when they sign up to your application in Catalyst Authentication.
- Learn more about the scopes of the SDK operations.
The SDK snippets below will allow you to initialize the SDK using either Admin or User scope, and use the authentication required to use the Catalyst components:
You need to initialize the SDK in the following manner to use the SDK methods using Admin scope.
const app = await zcAuth.init(req, {scope: ‘admin’});
You need to initialize the SDK in the following manner to use the SDK methods using User scope.
const app = await zcAuth.init(req, {scope: ‘user’});
Initialize the SDK Using Custom Credentials
To use the SDK with third-party authentication services, you can initalize the SDK in the following manner:
const credential = {
"client_id":"xxxxxxxxxx",
"client_secret": "yyyyyyyyyyy",
"refresh_token": "sgdw6et6736e8723e"
}
const customConfigurations = {
"project_id": "46386458237492",
"project_domain": "project-domain",
"environment": "development", // optional. default: development
credential
}
const app = await zcAuth.init(customConfigurations, { type: 'custom', appName: "custom-app" });
Get Instance Using Application Name
Once you’ve initialized your application, you have the additional option to use the getApp() method to get an app instance at any point by using the application’s name.
const app = zcAuth.getApp("app-name");
This ensures you are able to get an instance without having to re-intialize your SDK.
Using Environment Variables
You also have the option of initalizing the SDK by setting custom credentials as environment variables.
If you choose to initalize the SDK in this manner, then you do not have to initalize using the zcAuth.init() method, and you do not have to maintain the app instance in the manner shown in the above example snippet.
You need to configure the environment variables in a manner similar to the one shown below:
ZC_SDK_PROJECT_ID="your_project_id"
ZC_SDK_PROJECT_KEY="your_project_key"
ZC_SDK_PROJECT_DOMAIN="your_project_domain"
ZC_SDK_ENVIRONMENT="your_environment"
ZC_SDK_CLIENT_ID="your_client_id"
ZC_SDK_CLIENT_SECRET="your_client_secret"
ZC_SDK_REFRESH_TOKEN="your_refresh_token"
Last Updated 2026-07-02 14:51:41 +0530 IST
Yes
No
Send your feedback to us