--- title: "Configure the Advanced IO Function" url: https://docs.catalyst.zoho.com/en/tutorials/third-party-auth/nodejs/config-advancedio/ description: "Integrate Auth0 SPA authentication service with basic web applications hosted on Catalyst using OpenID Connect and 0Auth2.0 authentication protocols." last_updated: 2026-08-17T12:16:04Z service: All Services type: tutorial related_links: - name: "Third-party Authentication type" url: /en/cli/v1/initialize-resources/introduction - name: "Advanced IO Function" url: /en/serverless/help/functions/advanced-io/ - name: "Third-party Authentication SDK" url: /en/sdk/nodejs/v2/cloud-scale/authentication/third-party-server-token/ - name: "Auth0 Help Documentation" url: https://auth0.com/docs --- # Configure the Advanced IO Function Now, we will begin coding the authorization portal application by configuring the function component. The [function’s directory](https://docs.catalyst.zoho.com/en/cli/v1/project-directory-structure/functions-directory), (`functions/custom_token_generation`), contains: * The `ndex.js` main function file * The `catalyst-config.json` configuration file * Node modules * [`package.json`](https://docs.npmjs.com/files/package.json) and [`package-lock.json`](https://docs.npmjs.com/configuring-npm/package-lock-json.html) dependency files Before you start adding code, you need to install the following packages to ensure all required dependencies are satisfied. * **Express**: The [`express`](https://www.npmjs.com/package/express) package is required to handle HTTP routes * **Axios**: The [`axios`](https://www.npmjs.com/package/axios) package is required to handle outgoing HTTP requests Navigate to the function folder present in the `functions/custom_token_generation` directory and install the following packages using the command shown below: ```sh npm install express axios --save ``` ![catalyst_tutorials_third_party_package_install](https://catalyst-docs-development.zohostratus.in/images/tutorials/third-party-auth/catalyst_tutorials_third_party_package_install.webp) You will be adding code in the `index.js` file. The Advanced IO function contains the following functionalities:
Endpoint Request Method Purpose Possible Expected Responses
`/getauth` `GET`
  • Will read the Auth0 access token from the `zc-customauth` header.
  • Will call the Auth0 `/userinfo` and will generate a custom web token using the returned user details.
Returns the required **Catalyst Custom Token** (JSON) or a **401** if no token is obtained.
`/catalystUser` `GET` Initializes Catalyst using request context and retrieves the details of the authenticated user. Returns a JSON containing the end-user details.
Copy the code below and paste it into the `index.js` files of your project using an IDE and save the files. > **Note:** Go through the code in this section to make sure you fully understand it. **index.js** ```javascript 'use strict' // Import Catalyst Node SDK const catalyst = require('zcatalyst-sdk-node') // Import Express framework const express = require('express') const app = express() // Initialize express middleware app.use(express()) // Import axios to make HTTP requests to Auth0 const axios = require('axios') // Header name where Auth0 access token is expected const auth0TokenHeader = 'zc-customauth' // Replace with your Auth0 domain (example: https://your-domain.auth0.com) const auth0Domain = '{replace your Auth0 domain}' // Endpoint to validate Auth0 token and generate Catalyst custom token app.get('/getauth', async (req, res) => { try { // Read Auth0 access token from request header const auth0AccessToken = req.headers[auth0TokenHeader] // Auth0 user info endpoint const auth0Url = auth0Domain + '/userinfo' // Proceed only if token is provided if (auth0AccessToken !== undefined) { const url = auth0Url // Attach Authorization header with Bearer token const config = { headers: { Authorization: 'Bearer ' + auth0AccessToken } } // Call Auth0 to fetch user details const auth0response = await axios.get(url, config) // Initialize Catalyst app using request context const catalystApp = catalyst.initialize(req) // Generate Catalyst custom web token using Auth0 user details const tokenObj = await catalystApp.userManagement().generateCustomToken({ type: 'web', user_details: { email_id: auth0response.data.email, first_name: auth0response.data.given_name, last_name: auth0response.data.family_name } }) // Send generated Catalyst token back to client res.status(200).send(JSON.stringify(tokenObj)) } else { // If Auth0 token is missing in header res.status(401).send({ status: 'failure', message: 'Token not provided in the header' }) } } catch (error) { // Log error and return failure response console.log(error) res.status(error.response.status).send({ status: 'failure', message: 'An unexpected error has occured. Please try again after sometime.' }) } }) // Endpoint to fetch the currently authenticated Catalyst user app.get('/catalystUser', async (req, res) => { try { // Initialize Catalyst using request context const catalystApp = catalyst.initialize(req) // Retrieve current logged-in Catalyst user const currentUser = await catalystApp.userManagement().getCurrentUser() // Send user details as response res.status(200).send(JSON.stringify(currentUser)) } catch (error) { // Handle and log any unexpected errors console.log(error) res.status(500).send({ status: 'failure', message: error }) } }) // Export the Express app module.exports = app ``` > **Note:** Ensure you provide domain generated by Auth0 in line **14**.