added in oauth fo dev
This commit is contained in:
+66
-57
@@ -2,10 +2,6 @@ import axios from "axios";
|
||||
import https from "https";
|
||||
import CryptoJS from "crypto-js";
|
||||
|
||||
//import {XMLHttpRequest} from 'xmlhttprequest';
|
||||
|
||||
//process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
|
||||
|
||||
let BASE_URL;
|
||||
const port = parseInt(process.env.PORT, 10) || 3000;
|
||||
|
||||
@@ -15,8 +11,12 @@ if (process.browser) {
|
||||
BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
|
||||
}
|
||||
|
||||
const cache = {};
|
||||
const API_PATH = "/api/data/v8.2/";
|
||||
|
||||
const accessTokenEndpoint = process.env.ACCESS_TOKEN_ENDPOINT;
|
||||
const tenantId = process.env.TENANT;
|
||||
|
||||
//const WEBAPI_URL = "https://devcrm2016.llcdt.gov.wales/DVPINS" + API_PATH;
|
||||
|
||||
const WEBAPI_URL =
|
||||
@@ -27,6 +27,48 @@ const agent = new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
|
||||
export const getToken = () => {
|
||||
if (cache.tokenResponse) {
|
||||
console.log("from cache", tokenResponse);
|
||||
return cache.tokenResponse;
|
||||
} else {
|
||||
return axios
|
||||
.post(
|
||||
`${accessTokenEndpoint}${tenantId}/oauth2/v2.0/token`,
|
||||
tokenBody,
|
||||
tokenConfig
|
||||
)
|
||||
.then((res) => res.data)
|
||||
.then((data) => {
|
||||
cache.tokenResponse = data;
|
||||
return data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error :", error.response);
|
||||
// return error;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const tokenBody =
|
||||
"grant_type=" +
|
||||
process.env.GRANT_TYPE +
|
||||
"&client_id=" +
|
||||
process.env.CLIENT_ID +
|
||||
"&client_secret=" +
|
||||
process.env.CLIENT_SECRET +
|
||||
"&scope=" +
|
||||
"https://" +
|
||||
process.env.RELAYURI +
|
||||
"/.default";
|
||||
|
||||
const tokenConfig = {
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
};
|
||||
|
||||
export const getSASToken = () => {
|
||||
var m_ResourceURI =
|
||||
process.env.RELAYURI || "dev-pedw-ns.servicebus.windows.net";
|
||||
@@ -76,34 +118,6 @@ export const getSASToken = () => {
|
||||
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) => {
|
||||
return {
|
||||
headers: {
|
||||
@@ -112,7 +126,7 @@ const azureHeaders = (SASToken) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": SASToken,
|
||||
"Authorization": "Bearer " + SASToken,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -126,7 +140,7 @@ const azureHeadersPaged = (SASToken) => {
|
||||
"Prefer":
|
||||
'odata.include-annotations="*",return=representation, odata.maxpagesize=10',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": SASToken,
|
||||
"Authorization": "Bearer " + SASToken,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -160,7 +174,7 @@ export const getBasicSearch = (token, searchString) => {
|
||||
|
||||
export const getBasicSearchPaged = (searchString, pageNumber) => {
|
||||
//console.log("\n\n", token, searchString);
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
console.log(typeof pageNumber != "undefined");
|
||||
return axios
|
||||
@@ -204,7 +218,7 @@ export const getBasicDNSSearch = (token, searchString) => {
|
||||
};
|
||||
|
||||
export const getBasicDNSSearchPaged = (pageNumber) => {
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -274,7 +288,7 @@ export const getAdvancedSearch = (token, searchString) => {
|
||||
|
||||
export const getAdvancedSearchPaged = (searchString, pageNumber) => {
|
||||
//console.log(searchString);
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
var queryString = "";
|
||||
|
||||
@@ -358,7 +372,7 @@ export const getBasicSearchDetailsPaged = (
|
||||
incidentID
|
||||
) => {
|
||||
//console.log("check appealtype:", appealType, caseReference);
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -378,7 +392,6 @@ export const getBasicSearchDetailsPaged = (
|
||||
};
|
||||
|
||||
export const getSearchDocumentDetails = (token, incidentID) => {
|
||||
console.log(incidentID);
|
||||
return axios
|
||||
.get(
|
||||
WEBAPI_URL +
|
||||
@@ -409,7 +422,7 @@ export const getSearchDocumentHistory = (token, documentID) => {
|
||||
|
||||
export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => {
|
||||
console.log(incidentID);
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -429,7 +442,7 @@ export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => {
|
||||
};
|
||||
|
||||
export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => {
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -449,7 +462,6 @@ export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => {
|
||||
|
||||
export const getSearchDocumentDetails1 = (incidentID) => {
|
||||
//console.log(incidentID);
|
||||
var token = getSASToken();
|
||||
return axios
|
||||
.get(
|
||||
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
||||
@@ -464,7 +476,6 @@ export const getSearchDocumentDetails1 = (incidentID) => {
|
||||
|
||||
export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => {
|
||||
//console.log(incidentID);
|
||||
var token = getSASToken();
|
||||
return axios
|
||||
.get(
|
||||
"/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " +
|
||||
@@ -483,7 +494,6 @@ export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => {
|
||||
|
||||
export const getSearchDocumentHistory1 = (documentID) => {
|
||||
//console.log(documentID);
|
||||
var token = getSASToken();
|
||||
return axios
|
||||
.get(
|
||||
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
||||
@@ -499,7 +509,6 @@ export const getSearchDocumentHistory1 = (documentID) => {
|
||||
|
||||
export const getSearchDocumentHistory1Paged = (documentID, pageNumber) => {
|
||||
//console.log(documentID);
|
||||
var token = getSASToken();
|
||||
return axios
|
||||
.get(
|
||||
"/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " +
|
||||
@@ -533,7 +542,7 @@ export const getBasicDNSSearchDetails = (token, appealType, caseReference) => {
|
||||
};
|
||||
|
||||
export const getBasicDNSSearchDetailsPaged = (caseReference) => {
|
||||
var token = getSASToken();
|
||||
var token = getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -550,7 +559,7 @@ export const getBasicDNSSearchDetailsPaged = (caseReference) => {
|
||||
|
||||
export const getLinkedCases = (parentIncidentid) => {
|
||||
//console.log(parentIncidentid);
|
||||
var token = getSASToken();
|
||||
//var token = getToken();
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -698,7 +707,7 @@ export const getAppealID = (
|
||||
|
||||
console.log("proxy url ", weburl);
|
||||
return axios
|
||||
.get(weburl, azureHeaders(getSASToken()))
|
||||
.get(weburl, azureHeaders(getToken()))
|
||||
.then((res) => {
|
||||
var appealID = res.data.value[0][primaryAttribute];
|
||||
return appealID;
|
||||
@@ -784,7 +793,7 @@ export const updateCase = async (
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
@@ -857,7 +866,7 @@ export const deleteMyRepresentations = (myRepresentationsID) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
};
|
||||
// console.log(config);
|
||||
@@ -877,7 +886,7 @@ export const getRepresentations = (incidentID) => {
|
||||
"/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " +
|
||||
incidentID +
|
||||
" and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc",
|
||||
azureHeaders(getSASToken())
|
||||
azureHeaders(getToken())
|
||||
)
|
||||
.then((res) => res.data)
|
||||
.catch((error) => {
|
||||
@@ -940,7 +949,7 @@ export const createWatchedCases = (formValues) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
@@ -965,7 +974,7 @@ export const deleteWatchedCases = (watchedCaseID) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
};
|
||||
// console.log(config);
|
||||
@@ -1027,7 +1036,7 @@ export const getPortalModuleDetailsProxy = (
|
||||
};
|
||||
|
||||
export const getEmailAccountCheck = (emailAddress) => {
|
||||
let token = getSASToken();
|
||||
let token = getToken();
|
||||
return axios
|
||||
.get(
|
||||
"/api/proxy/contacts?$filter=emailaddress1 eq '" +
|
||||
@@ -1052,7 +1061,7 @@ export const createAccount = (formValues) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
@@ -1079,7 +1088,7 @@ export const updateAccount = (contactId, updateBody) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
@@ -1107,7 +1116,7 @@ export const updatePassword = (contactId, newpassword) => {
|
||||
"Accept": "application/json",
|
||||
"Prefer": 'odata.include-annotations="*",return=representation',
|
||||
"Content-Type": "application/json",
|
||||
"ServiceBusAuthorization": getSASToken(),
|
||||
"Authorization": getToken(),
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user