Merged PR 612: assing hash signature to proxy requests

Related work items: #6718
This commit is contained in:
Robert Bond
2021-11-16 19:20:28 +00:00
6 changed files with 255 additions and 250 deletions
+16 -12
View File
@@ -1,9 +1,9 @@
// dev // dev
RELAY_ROOT = https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/ //RELAY_ROOT = https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/
RELAYURI = "dev-pedw-ns.servicebus.windows.net" //RELAYURI = "dev-pedw-ns.servicebus.windows.net"
RELAYPATH = "dev-pedw-hc" //RELAYPATH = "dev-pedw-hc"
SASKEY = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y=" //SASKEY = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y="
SASKEYNAME = "devpedwnspolicy" //SASKEYNAME = "devpedwnspolicy"
PORT= "3000" PORT= "3000"
@@ -23,16 +23,20 @@ I18N_DOMAIN = "cymru.local"
//preprod //preprod
//RELAY_ROOT = https://pp-pedw-ns.servicebus.windows.net/pp-pedw-hc/ RELAY_ROOT = https://pp-pedw-ns.servicebus.windows.net/pp-pedw-hc/
//RELAYURI = "pp-pedw-ns.servicebus.windows.net" RELAYURI = "pp-pedw-ns.servicebus.windows.net"
//RELAYPATH = "pp-pedw-hc" RELAYPATH = "pp-pedw-hc"
//SASKEY = "JzrOYfMTsGBD1cZHH2nkzqsbfDCqg0brO6jyiIDNVPo=" SASKEY = "JzrOYfMTsGBD1cZHH2nkzqsbfDCqg0brO6jyiIDNVPo="
//SASKEYNAME = "pppedwnspolicy" SASKEYNAME = "pppedwnspolicy"
GOOGLE_TAG_MANAGER = GTM-T78CBC3 GOOGLE_TAG_MANAGER = GTM-T78CBC3
SHOWLOGIN = "false" SHOWLOGIN = "false"
SHOWREPRESENTATIONS = "false" SHOWREPRESENTATIONS = "false"
BASIC_AUTH_CREDENTIALS = pinswg:password|pinswg2:password2 BASIC_AUTH_CREDENTIALS,, = pinswg:password|pinswg2:password2
NEXT_PUBLIC_ISHARESECRETPHRASE = "Secret phrase" NEXT_PUBLIC_ISHARESECRETPHRASE = "Secret phrase"
HASHKEY = "028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c"
NEXT_PUBLIC_HASHKEY = "028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c"
+144 -175
View File
@@ -1,6 +1,7 @@
import axios from "axios"; import axios from "axios";
import https from "https"; import https from "https";
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import HmacSHA256 from "crypto-js/hmac-sha256";
//import {XMLHttpRequest} from 'xmlhttprequest'; //import {XMLHttpRequest} from 'xmlhttprequest';
@@ -14,6 +15,7 @@ if (process.browser) {
} else { } else {
BASE_URL = process.env.API_ROOT || `http://localhost:${port}`; BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
} }
const WORDKEY = process.env.NEXT_PUBLIC_HASHKEY;
const API_PATH = "/api/data/v8.2/"; const API_PATH = "/api/data/v8.2/";
@@ -76,34 +78,6 @@ export const getSASToken = () => {
return token; return token;
}; };
const accessToken =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSIsImtpZCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSJ9.eyJhdWQiOiJodHRwczovL2RldmNybTIwMTYubGxjZHQuZ292LndhbGVzLyIsImlzcyI6Imh0dHA6Ly9mcy50ZXN0Lmdvdi53YWxlcy9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNjMyMTIxMjkxLCJuYmYiOjE2MzIxMjEyOTEsImV4cCI6MTYzMjE1MDA5MSwidXBuIjpbIlJvYmVydC5Cb25kQHRlc3QuZ292LndhbGVzIiwicm9iZXJ0LmJvbmRAdGVzdC5nb3Yud2FsZXMiXSwicHJpbWFyeXNpZCI6IlMtMS01LTIxLTE4MDA4NDIwNzYtMjQ1NTYwNjU5LTQyMTU3NzU0NjktMTY2MjgiLCJ1bmlxdWVfbmFtZSI6IlhNXFxCb25kUiIsImFwcHR5cGUiOiJQdWJsaWMiLCJhcHBpZCI6IjQyN2ZhNzljLWI1ZmMtNDJhZC04M2Q0LTQxMGIwMzk0OGFiNiIsImF1dGhtZXRob2QiOiJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvYXV0aGVudGljYXRpb25tZXRob2Qvd2luZG93cyIsImF1dGhfdGltZSI6IjIwMjEtMDktMjBUMDc6MDE6MzEuNDYzWiIsInZlciI6IjEuMCJ9.W0ID2nCBYVxh8T1eQqWKk2Wh45kRbRzCICfzrZNAs-4u54yl0UJUcVihyI8EBmQeALCEc5eY99DjK0gaqzCdJqxbxol8yk5LrFvhV5UkCiZ7SO2Wq1cLReWHVsgz39qBtrZ8vlqqZsv7DsEaRJQbtj8Djnx26Wb_kcNu-tuXwUBF0uR5GLFFvJfM3PzkRCY-ZPOTbvPTb73oN_NKe6BrsVjyaR9xSXsRJjgHPmJgWgnvq-2X0Dj7LCwXSEygDDOGlF1yqqN0Lv6qplhQoH-heZlC1K6qe_92nHPswXag6uN5nxTmk1Qw6zJt_aHMnXdwa18ghh4hGx5R0Jz53X113Q";
//const SASToken = getSASToken();
const crmHeaders = {
withCredentials: true,
headers: {
"Content-Type": "application/json; charset=utf-8",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Authorization": "Bearer " + accessToken,
},
};
const crmHeadersReturn = {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": "return=representation",
"Content-Type": "application/json",
"Authorization": "Bearer " + accessToken,
},
};
const azureHeaders = (SASToken) => { const azureHeaders = (SASToken) => {
return { return {
headers: { headers: {
@@ -131,6 +105,16 @@ const azureHeadersPaged = (SASToken) => {
}; };
}; };
const hashProxyPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString();
return "&hash=" + hashlink;
};
export const getBasicSearch = (token, searchString) => { export const getBasicSearch = (token, searchString) => {
//console.log("\n\n", token, searchString); //console.log("\n\n", token, searchString);
@@ -160,22 +144,22 @@ export const getBasicSearch = (token, searchString) => {
export const getBasicSearchPaged = (searchString, pageNumber) => { export const getBasicSearchPaged = (searchString, pageNumber) => {
//console.log("\n\n", token, searchString); //console.log("\n\n", token, searchString);
var token = getSASToken();
console.log(typeof pageNumber != "undefined"); //console.log(typeof pageNumber != "undefined");
var queryUrl =
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
searchString +
"') or contains(ticketnumber, '" +
searchString +
"')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: "");
//console.log(queryUrl);
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
searchString +
"') or contains(ticketnumber, '" +
searchString +
"')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: ""),
azureHeadersPaged(token)
)
.then((res) => { .then((res) => {
// console.log(" "); // console.log(" ");
// console.log("/////////////////////"); // console.log("/////////////////////");
@@ -206,15 +190,14 @@ export const getBasicDNSSearch = (token, searchString) => {
export const getBasicDNSSearchPaged = (pageNumber) => { export const getBasicDNSSearchPaged = (pageNumber) => {
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: "");
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: ""),
azureHeadersPaged(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
return error.response; return error.response;
@@ -257,7 +240,6 @@ export const getAdvancedSearch = (token, searchString) => {
"incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + "incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" +
queryString + queryString +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true", " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true",
azureHeadersPaged(token) azureHeadersPaged(token)
) )
.then((res) => res.data) .then((res) => res.data)
@@ -303,18 +285,16 @@ export const getAdvancedSearchPaged = (searchString, pageNumber) => {
searchString.apt searchString.apt
: ""; : "";
return axios var queryUrl =
.get( "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" +
"/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + queryString +
queryString + " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + (typeof pageNumber != "undefined"
(typeof pageNumber != "undefined" ? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
? "&$skiptoken=" + : "");
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: ""),
azureHeadersPaged(token) return axios
) .get(queryUrl + hashProxyPath(queryUrl))
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
let ErrResponse = { let ErrResponse = {
@@ -358,19 +338,18 @@ export const getBasicSearchDetailsPaged = (
incidentID incidentID
) => { ) => {
//console.log("check appealtype:", appealType, caseReference); //console.log("check appealtype:", appealType, caseReference);
var token = getSASToken();
var queryUrl =
"/api/proxy/" +
appealTypeName +
"?$filter=_" +
primaryIdAttribute +
"s_value eq " +
incidentID +
"&$count=true";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/" +
appealTypeName +
"?$filter=_" +
primaryIdAttribute +
"s_value eq " +
incidentID +
"&$count=true",
azureHeaders(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("this error", error); console.log("this error", error);
@@ -411,17 +390,17 @@ export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => {
console.log(incidentID); console.log(incidentID);
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: ""),
azureHeadersPaged(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -431,16 +410,14 @@ export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => {
export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => { export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => {
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: ""),
azureHeadersPaged(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -450,12 +427,12 @@ export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => {
export const getSearchDocumentDetails1 = (incidentID) => { export const getSearchDocumentDetails1 = (incidentID) => {
//console.log(incidentID); //console.log(incidentID);
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
incidentID +
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
incidentID +
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference"
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -465,16 +442,15 @@ export const getSearchDocumentDetails1 = (incidentID) => {
export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => { export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => {
//console.log(incidentID); //console.log(incidentID);
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
incidentID +
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
incidentID +
"&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: "")
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -484,11 +460,11 @@ export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => {
export const getSearchDocumentHistory1 = (documentID) => { export const getSearchDocumentHistory1 = (documentID) => {
//console.log(documentID); //console.log(documentID);
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID;
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID
)
.then((res) => { .then((res) => {
return res.data; return res.data;
}) })
@@ -500,15 +476,14 @@ export const getSearchDocumentHistory1 = (documentID) => {
export const getSearchDocumentHistory1Paged = (documentID, pageNumber) => { export const getSearchDocumentHistory1Paged = (documentID, pageNumber) => {
//console.log(documentID); //console.log(documentID);
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + ('<cookie pagenumber="' + pageNumber + '" />')
: "");
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
documentID +
(typeof pageNumber != "undefined"
? "&$skiptoken=" +
encodeURI('<cookie pagenumber="' + pageNumber + '" />')
: "")
)
.then((res) => { .then((res) => {
return res.data; return res.data;
}) })
@@ -535,13 +510,13 @@ export const getBasicDNSSearchDetails = (token, appealType, caseReference) => {
export const getBasicDNSSearchDetailsPaged = (caseReference) => { export const getBasicDNSSearchDetailsPaged = (caseReference) => {
var token = getSASToken(); var token = getSASToken();
var queryUrl =
"/api/proxy/pinswg_dnses?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_dnses?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true",
azureHeadersPaged(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -550,14 +525,12 @@ export const getBasicDNSSearchDetailsPaged = (caseReference) => {
export const getLinkedCases = (parentIncidentid) => { export const getLinkedCases = (parentIncidentid) => {
//console.log(parentIncidentid); //console.log(parentIncidentid);
var token = getSASToken(); var queryUrl =
"/api/proxy/incidents?$count=true&$filter=_parentcaseid_value eq " +
parentIncidentid +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/incidents?$count=true&$filter=_parentcaseid_value eq " +
parentIncidentid +
" and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid,"
)
.then((res) => { .then((res) => {
//console.log(" linked date", res.data); //console.log(" linked date", res.data);
return res.data; return res.data;
@@ -709,14 +682,15 @@ export const getAppealID = (
}; };
export const getLogin = (emailAddress, pwd) => { export const getLogin = (emailAddress, pwd) => {
var queryUrl =
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
emailAddress +
"' and pinswg_custom_password eq '" +
pwd +
"'&$count=true&$select=emailaddress1,%20contactid,pinswg_custom_password, yomifullname, firstname, lastname";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
emailAddress +
"' and pinswg_custom_password eq '" +
pwd +
"'&$count=true&$select=emailaddress1,%20contactid,pinswg_custom_password, yomifullname, firstname, lastname"
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -834,13 +808,12 @@ export const getMyRepresentations = (token, loggedInUserId) => {
}; };
export const getMyRepresentationsProxy = (token, loggedInUserId) => { export const getMyRepresentationsProxy = (token, loggedInUserId) => {
var queryUrl =
"/api/proxy/pinswg_representationses?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_representationses?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc",
azureHeaders(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("this serror", error); console.log("this serror", error);
@@ -872,13 +845,12 @@ export const deleteMyRepresentations = (myRepresentationsID) => {
}; };
export const getRepresentations = (incidentID) => { export const getRepresentations = (incidentID) => {
var queryUrl =
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc",
azureHeaders(getSASToken())
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("this serror", error); console.log("this serror", error);
@@ -886,13 +858,12 @@ export const getRepresentations = (incidentID) => {
}; };
export const getRepresentationsProxy = (token, incidentID) => { export const getRepresentationsProxy = (token, incidentID) => {
var queryUrl =
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
"&$count=true&$orderby=createdon desc";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
incidentID +
"&$count=true&$orderby=createdon desc",
azureHeaders(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("this serror", error); console.log("this serror", error);
@@ -915,13 +886,12 @@ export const getWatchedCases = (token, loggedInUserId) => {
}; };
export const getWatchedCasesProxy = (token, loggedInUserId) => { export const getWatchedCasesProxy = (token, loggedInUserId) => {
var queryUrl =
"/api/proxy/pinswg_watchlists?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc";
return axios return axios
.get( .get(queryUrl | +hashProxyPath(queryUrl))
"/api/proxy/pinswg_watchlists?$filter= _pinswg_contact_value eq " +
loggedInUserId +
"&$count=true&$orderby=createdon desc",
azureHeaders(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("this serror", error); console.log("this serror", error);
@@ -1011,15 +981,14 @@ export const getPortalModuleDetailsProxy = (
appealType, appealType,
caseReference caseReference
) => { ) => {
var queryUrl =
"/api/proxy/" +
appealType +
"?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/" +
appealType +
"?$filter=pinswg_name eq '" +
caseReference +
"'&$count=true",
azureHeaders(token)
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
@@ -1028,12 +997,12 @@ export const getPortalModuleDetailsProxy = (
export const getEmailAccountCheck = (emailAddress) => { export const getEmailAccountCheck = (emailAddress) => {
let token = getSASToken(); let token = getSASToken();
var queryUrl =
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
emailAddress +
"'&$count=true&$select=emailaddress1, contactid";
return axios return axios
.get( .get(queryUrl + hashProxyPath(queryUrl))
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
emailAddress +
"'&$count=true&$select=emailaddress1, contactid"
)
.then((res) => res.data) .then((res) => res.data)
.catch((error) => { .catch((error) => {
console.log("thiserror", error); console.log("thiserror", error);
+14 -14
View File
@@ -105,12 +105,9 @@ const DocumentDetails = (props) => {
> >
<dd className="govuk-summary-list__value govuk-!-font-size-16 "> <dd className="govuk-summary-list__value govuk-!-font-size-16 ">
<a <a
href={ href={encryptDocReference(
"/api/proxy/documents/download/" + detailsObj.pinswg_isharedocumentreference
encryptDocReference( )}
detailsObj.pinswg_isharedocumentreference
)
}
> >
<span className="results-visually-hidden"> <span className="results-visually-hidden">
{t( {t(
@@ -194,15 +191,18 @@ const DocumentDetails = (props) => {
); );
}; };
const encryptDocReference = (documentRef) => { const WORDKEY = process.env.NEXT_PUBLIC_HASHKEY;
var encrypted = encodeURIComponent(
CryptoJS.AES.encrypt(
documentRef,
process.env.NEXT_PUBLIC_ISHARESECRETPHRASE
)
);
return encrypted; const encryptDocReference = (documentRef) => {
var hashlink = CryptoJS.HmacSHA256(
"/api/proxy/documents/download/" + documentRef,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString();
return (
"/api/proxy/documents/download/" + documentRef + "&hash=" + hashlink
);
}; };
useEffect(() => { useEffect(() => {
+13 -1
View File
@@ -263,7 +263,19 @@ const Pinswg_dnsid = (props) => {
detailsObj.pinswg_webaddress + detailsObj.pinswg_webaddress +
'")].value_cy' '")].value_cy'
) )
: detailsObj.pinswg_webaddress || : (
<a
target="_blank"
rel="noopener"
href={
detailsObj.pinswg_webaddress
}
>
{
detailsObj.pinswg_webaddress
}
</a>
) ||
t( t(
"case:summary-no-date-entered-label" "case:summary-no-date-entered-label"
)} )}
+1 -1
View File
@@ -268,7 +268,7 @@ const DNSSearchResults = (props) => {
//console.log("getting details", data); //console.log("getting details", data);
return getSearchDetailsPaged(data).then((data) => { return getSearchDetailsPaged(data).then((data) => {
setSearchDetails(data); setSearchDetails(data);
setShowSpinnerState(false); //setShowSpinnerState(false);
}); });
}); });
}; };
+67 -47
View File
@@ -1,7 +1,8 @@
import axios from "axios"; import axios from "axios";
import https from "https"; import https from "https";
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import { response } from "express"; import HmacSHA256 from "crypto-js/hmac-sha256";
import { rest } from "lodash";
const PROXY_RELAY_URL = const PROXY_RELAY_URL =
"https://" + "https://" +
@@ -48,16 +49,30 @@ const getSASToken = () => {
return token; return token;
}; };
export default async function ApiProxy(req, res) { function checkProxyPath(queryPath) {
//console.log(req.method); const WORDKEY = process.env.NEXT_PUBLIC_HASHKEY;
const wordKey = WORDKEY;
var hashlink = CryptoJS.HmacSHA256(
decodeURI(queryPath),
CryptoJS.enc.Hex.parse(wordKey)
);
hashlink = hashlink.toString();
return hashlink;
}
export default async function ApiProxy(req, res) {
var data = JSON.stringify(req.body); var data = JSON.stringify(req.body);
const SASToken = getSASToken(); const SASToken = getSASToken();
var configNoData = { var configNoData = {
method: req.method, method: req.method,
//url: PROXY_RELAY_URL + updateFormCollection + "(" + incidentId + ")", //url: PROXY_RELAY_URL + updateFormCollection + "(" + incidentId + ")",
url: PROXY_RELAY_URL + req.url.split("/api/proxy/")[1], url:
PROXY_RELAY_URL +
req.url.split("&hash=")[0].split("/api/proxy/")[1],
headers: { headers: {
"OData-MaxVersion": "4.0", "OData-MaxVersion": "4.0",
"OData-Version": "4.0", "OData-Version": "4.0",
@@ -85,7 +100,9 @@ export default async function ApiProxy(req, res) {
var configDocument = { var configDocument = {
method: req.method, method: req.method,
url: PROXY_RELAY_URL + req.url.split("/api/proxy/")[1], url:
PROXY_RELAY_URL +
req.url.split("&hash=")[0].split("/api/proxy/")[1],
headers: { headers: {
"OData-MaxVersion": "4.0", "OData-MaxVersion": "4.0",
"OData-Version": "4.0", "OData-Version": "4.0",
@@ -97,46 +114,49 @@ export default async function ApiProxy(req, res) {
responseType: "arraybuffer", responseType: "arraybuffer",
}; };
return new Promise((resolve, reject) => { let hashCheckPath = req.url.split("&hash=")[0];
let apiPath = req.url.split("/api/proxy/")[1]; let hashCheckValue = req.url.split("&hash=")[1];
let hasDocument = apiPath.indexOf("/download") > 0 ? true : false; let hashFromRequest = checkProxyPath(hashCheckPath);
// console.log(
// "//////////////", if (hashCheckValue == hashFromRequest) {
// req.url.split("/api/proxy/")[1], return new Promise((resolve, reject) => {
// PROXY_RELAY_URL + req.query.route[0], let hasDocument =
// req.method, hashCheckPath.indexOf("/download") > 0 ? true : false;
// hasDocument
// ); axios(
axios( req.method == "GET"
req.method == "GET" ? hasDocument
? hasDocument ? configDocument
? configDocument : configNoData
: configNoData : config
: config )
) .then((response) => {
.then((response) => { res.statusCode = 200;
res.statusCode = 200; if (hasDocument) {
if (hasDocument) { res.setHeader(
res.setHeader( "Content-disposition",
"Content-disposition", "attachment; filename=" +
"attachment; filename=" + response.headers["content-disposition"].split(
response.headers["content-disposition"].split( "filename="
"filename=" )[1]
)[1] );
); res.end(response.data);
res.end(response.data); } else {
} else { res.setHeader("Content-Type", "application/json");
res.setHeader("Content-Type", "application/json"); // res.setHeader("Cache-Control", "max-age=1800000");
// res.setHeader("Cache-Control", "max-age=1800000"); res.end(JSON.stringify(response.data));
res.end(JSON.stringify(response.data)); }
} resolve();
resolve(); })
}) .catch((error) => {
.catch((error) => { console.log("proxy response error", error);
console.log("proxy response error", error); // res.json(error);
res.json(error); res.status(405).end();
res.status(405).end(); return resolve();
return resolve(); });
}); });
}); } else {
res.status(405).end();
return resolve();
}
} }