set logged in from GovGateway Code

This commit is contained in:
2021-12-07 08:14:15 +00:00
parent 8bf7fd973e
commit bcfef0ec91
4 changed files with 111 additions and 13 deletions
+52 -2
View File
@@ -1,8 +1,12 @@
import axios from "axios";
import { hashAPIPath } from "./";
const configEndpoint = process.env.GG_PROVIDER_CONFIG_ENDPOINT;
const ggClientID = process.env.GG_ClIENT_ID;
const ggClientSecret = process.env.GG_CLIENT_SECRET;
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
export const getProviderConfig = () => {
return axios
@@ -36,11 +40,57 @@ export const getGGToken = (tokenURL, authCode, redirectUri) => {
.post(tokenURL, tokenBody, tokenConfig)
.then((res) => res.data)
.catch((error) => {
console.log("error :", error.response);
// return error;
// if (error.response) {
// console.log(error.response.data);
// console.log(error.response.status);
// console.log(error.response.headers);
// }
return error.response;
});
};
export const getUserInfo = (userInfoURL, authToken) => {
const tokenConfig = {
headers: {
"Authorization": "Bearer " + authToken,
},
};
return axios
.get(userInfoURL, tokenConfig)
.then((res) => res)
.catch((error) => {
//console.log(`Error: ${err?.response?.data}`);
//return error;
});
};
export const getPortalLogin = (emailAddress, token) => {
var queryUrl =
"contacts?$filter=emailaddress1 eq '" +
emailAddress +
"'&$count=true&$select=emailaddress1,contactid,pinswg_custom_password,yomifullname,firstname,lastname";
return axios
.get(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), azureHeaders(token))
.then((res) => res.data)
.catch((error) => {
console.log("thiserror", error);
});
};
const azureHeaders = (access_token) => {
return {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json;odata.metadata=none",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token,
},
};
};
var Base64 = {
_keyStr:
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
+1 -1
View File
@@ -94,7 +94,7 @@ const azureHeadersPaged = (access_token) => {
};
};
const hashAPIPath = (queryPath) => {
export const hashAPIPath = (queryPath) => {
var hashPath =
queryPath.indexOf("/api/proxy/") == -1
? queryPath