46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import request from "request";
|
|
import logger from "../config/logger.js";
|
|
|
|
async function httpReqValidateAuth(
|
|
orgId,
|
|
access_token,
|
|
instance_url,
|
|
refresh_token
|
|
) {
|
|
|
|
const getRequest = () => {
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
request.get(
|
|
{
|
|
headers: {
|
|
'Authorization': `Bearer ${access_token}`,
|
|
},
|
|
url: `${instance_url}/services/data/v58.0/query?q=select+id+from+user+limit+1`,
|
|
},
|
|
(error, res) => {
|
|
resolve(res);
|
|
}
|
|
);
|
|
} catch (error) {
|
|
reject("error in validateAuth.httpReq1", error);
|
|
}
|
|
});
|
|
};
|
|
|
|
// Await the postRequest promise
|
|
try {
|
|
const result = await getRequest();
|
|
if(result.statusCode === 200 || result.statusCode === 201){
|
|
logger.info("Access Token is Valid - validateAuth.httpReq < ==")
|
|
return true;
|
|
}
|
|
logger.info("Access Token is Invalid - validateAuth.httpReq < ==")
|
|
return false;
|
|
} catch (err) {
|
|
logger.error("Error in validateAuth.httpReq2", err);
|
|
}
|
|
}
|
|
|
|
export default httpReqValidateAuth;
|