/** * @swagger * /api/endpoint/getportallogin_api: * get: * tags: [Login] * description: Returns portal login * summary: Phase 2 * parameters: * - name: emailaddress * in: query * required: true * schema: * type: string * responses: * 200: * description: hello world */ import { azureHeadersPaged } from "../../../actions/core/headers"; import { hashAPIPath } from "../../../actions/core/hash"; import { respondError } from "../middleware/apiResponse"; import { relayGet } from "../middleware/relayForwarding"; import { RELAY_POLICY_STRICT_LOGIN } from "../middleware/relayPolicyPresets"; export default async function ApiProxy(req, res) { const emailAddress = req.query.emailAddress; const checkHash = req.query.hash; if (typeof emailAddress !== "string" || emailAddress.trim().length === 0) { return respondError(res, { status: 400, code: "EMAIL_ADDRESS_REQUIRED", message: "emailAddress is required" }); } if (typeof checkHash !== "string" || checkHash.length === 0) { return respondError(res, { status: 400, code: "HASH_REQUIRED", message: "hash is required" }); } const checkquerypath = "/api/endpoint/getportallogin_api?emailAddress=" + emailAddress; const encodedCheckquerypath = "/api/endpoint/getportallogin_api?emailAddress=" + encodeURIComponent(emailAddress); const expectedHashCandidates = [ hashAPIPath(checkquerypath), hashAPIPath(encodedCheckquerypath) ]; if (!expectedHashCandidates.includes("&hash=" + checkHash)) { return respondError(res, { status: 400, code: "INVALID_HASH", message: "Invalid hash" }); } const queryUrl = "contacts?$filter=emailaddress1 eq '" + emailAddress + "' and statuscode eq 1&$count=true&$select=emailaddress1,contactid,yomifullname,firstname,lastname"; const relayPolicy = RELAY_POLICY_STRICT_LOGIN; return relayGet({ queryUrl, res, requestOptionsBuilder: (accessToken) => azureHeadersPaged(accessToken), relayPolicy, errorResponse: { status: 400, code: "PORTAL_LOGIN_FETCH_FAILED", message: "Failed to fetch portal login" } }); }