UNPKG

open-api-aurum-connector2

Version:

Module to connect to the OPEN API Aurum Core

42 lines (35 loc) 1.47 kB
const { module_name, configurations_key } = require("../utils/Constants.js"); const { logger } = require("../utils/Logger.js"); //this method requiere user autentication, not clients const validateOTP = async (token, body) => { try { logger.info(`module-hub-aurum-core-connector :: validateOTP "${module_name}" ...`); const config = global[configurations_key]; let endpoint = config?.otp?.validate?.endpoint || ""; //replace endpoint with the correct values endpoint = endpoint.replace("{mgtwUrl}", config.mgtwUrl); endpoint = endpoint.replace("{tenantName}", config.tenantName); logger.info(`module-hub-aurum-core-connector :: Validating OTP to endpoint: ${endpoint}`); //INVOKE ENDPOINT, POST, headers: authorization bearer(token), body: raw json (body) const response = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json", Authorization: "Bearer " + token, }, body: JSON.stringify(body), }); //PARSE RESPONSE const responseJson = await response.json(); logger.info(`module-hub-aurum-core-connector :: Response: ${JSON.stringify(responseJson)}`); return responseJson; } catch (error) { logger.error(`module-hub-aurum-core-connector :: Error validating OTP: ${error}`); return { responseCode: 500, error: error, error_description: "Error validating OTP", }; } }; module.exports = validateOTP;