Custom User Validation
Catalyst offers you the option to validate and authorize end-users to your application using custom functions. This option allows you configure a Catalyst Basic I/O function to contain the logic of the manner you wish to authorize the user with. During user sign up, the credentials of the user will be validated through this Basic I/O function.
Note: To enable Custom User Validation, you must first ensure that Public Signup has been enabled.
Refer the code snippets below a sample Custom User Validation function in Java, Node.js, and Python:
Custom User Validationcopy
public class MainClass implements ZCFunction {
private static final Logger LOGGER = Logger.getLogger(MainClass.class.getName());
@Override
public void runner(Context context, BasicIO basicIO) throws Exception {
try {
ZCProject.initProject();
ZCSignupUserValidationRequest requestDetails = ZCSignupUserService.getSignupValidationRequest(basicIO);
if (requestDetails != null) {
/* Validation logic starts */
LOGGER.info("Inside null check");
ZCSignupUserValidationResponse validationResponse = ZCSignupUserValidationResponse.getInstance();
if (requestDetails.getUserDetails().getEmailId().contains("@notallowedmail")) {
validationResponse.setStatus(ZCSignupValidationStatus.FAILURE); // The user has failed authentication
} else {
validationResponse.setStatus(ZCSignupValidationStatus.SUCCESS); // The actions that occur in the event of a successful authentication can be customized
ZCSignupResponseUserDetails respUserDetails = ZCSignupResponseUserDetails.getInstance();
respUserDetails.setFirstName("{customFirstName}");
respUserDetails.setLastName("{customLastname}");
respUserDetails.setRoleIdentifier("{customRoleName}");
respUserDetails.setOrgId("{customOrgId}");
validationResponse.setUserDetails(respUserDetails);
}
basicIO.write(validationResponse);
/* Validation logic ends */
}
} catch (Exception e) {
basicIO.write(e);
LOGGER.log(Level.SEVERE, "Exception in MainClass", e);
basicIO.setStatus(500);
}
}
}
const catalyst = require('zcatalyst-sdk-node');
module.exports = (context, basicIO) => {
const catalystApp = catalyst.initialize(context);
const userManagement = catalystApp.userManagement();
const requestDetails = userManagement.getSignupValidationRequest(basicIO);
if (requestDetails !== undefined) {
if (requestDetails.user_details.email_id.includes('node')) {
basicIO.write(JSON.stringify({
status: 'failure'
}))
} else {
basicIO.write(JSON.stringify({
status: 'success',
user_details: {
first_name: 'CustomFirstName',
last_name: 'CustomLastName',
role_identifier: 'CustomRole',
org_id : 'CustomOrgID'//If you are providing the Org ID, make sure it is copied exactly from the console.
}
}))
}
}
context.close();
}
import json
import zcatalyst_sdk
def handler(context, basicio):
app = zcatalyst_sdk.initialize()
auth_service = app.authentication()
request_details = auth_service.get_signup_validation_request(basicio)
if request_details:
if "spam.com" in request_details["user_details"]["email_id"]:
basicio.write(json.dumps({"status": "failure"}))
else:
basicio.write(
json.dumps(
{
"status": "success",
"user_details": {
"first_name": "Amelia",
"last_name": "Jack",
"role_identifier": "cx_role",
'org_id': orgId #If you are providing the Org ID, make sure it is copied exactly from the console.
},
}
)
)
context.close()
Note: These snippets are also available in the Catalyst Java SDK, Node.js SDK, and Python SDK repositories.
Last Updated 2023-05-08 18:05:05 +0530 +0530
Yes
No
Send your feedback to us
Skip
Submit