Merge pull request #897 from Safelite/feature/digital/SSR-1473
SSR-1473 RSA Auth
This commit is contained in:
commit
23d7f736b5
2 changed files with 93 additions and 99 deletions
|
|
@ -4,18 +4,12 @@ export function validateISSClientTag(clientTag) {
|
||||||
const store = useMainStore();
|
const store = useMainStore();
|
||||||
|
|
||||||
return store.validateClientTag(clientTag)
|
return store.validateClientTag(clientTag)
|
||||||
.then(
|
.then((response) => response.data, () => null);
|
||||||
(response) => response,
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateISSClientSignature(clientTag, token, signature) {
|
export function validateISSClientSignature(clientTag, token, signature) {
|
||||||
const store = useMainStore();
|
const store = useMainStore();
|
||||||
|
|
||||||
return store.validateClientSignature(clientTag, token, signature)
|
return store.validateClientSignature(clientTag, token, signature)
|
||||||
.then(
|
.then((response) => response.data, () => null);
|
||||||
(response) => response,
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,54 +36,54 @@ export default {
|
||||||
async mounted() {
|
async mounted() {
|
||||||
const queryStringParams = this.parseQueryParms();
|
const queryStringParams = this.parseQueryParms();
|
||||||
|
|
||||||
const { isAuthorized, clientData } = await this.validateClientTagOnEntry(queryStringParams);
|
const { isAuthorized, clientData, decryptedParams } = await this.validateClientTagOnEntry(queryStringParams);
|
||||||
|
|
||||||
this.unauthorized = !isAuthorized;
|
this.unauthorized = !isAuthorized;
|
||||||
|
if (!isAuthorized) {
|
||||||
if (isAuthorized) {
|
|
||||||
this.populateISSConfigValues(clientData);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check cookie
|
|
||||||
const issCookie = getISSCookie();
|
|
||||||
if (issCookie !== null && issCookie.VehicleMake && issCookie.VehicleModel) {
|
|
||||||
const clientParentAccountNumber = clientData.parentAccountNumber;
|
|
||||||
const cookieParentAccountNumber = issCookie.ReferralParentAccountNumber;
|
|
||||||
|
|
||||||
if (clientParentAccountNumber === cookieParentAccountNumber) {
|
|
||||||
const savedSessionTimeStamp = new Date(issCookie.SavedSessionTimeoutDate);
|
|
||||||
const isSavedSessionTimedOut = new Date(new Date().toUTCString()) > savedSessionTimeStamp;
|
|
||||||
|
|
||||||
if (!isSavedSessionTimedOut) {
|
|
||||||
this.mainStore.issConfig.enableContinueFromCookie = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateOrCreateISSCookie(true);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
updateOrCreateISSCookie(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clientData.parameters?.length > 0) {
|
|
||||||
const finalParams = this.combineClientParameters(clientData.parameters, queryStringParams);
|
|
||||||
this.populateStoreItemsFromParams(finalParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mainStore.applicationUser.coverageAttempts = 0;
|
|
||||||
if (
|
|
||||||
applicationConfig.CURRENT_ENVIRONMENT === 'Localhost'
|
|
||||||
|| applicationConfig.CURRENT_ENVIRONMENT === 'Dev'
|
|
||||||
|| applicationConfig.CURRENT_ENVIRONMENT === 'SysTest'
|
|
||||||
) {
|
|
||||||
this.navigateForward();
|
|
||||||
} else {
|
|
||||||
// Forced full location redirect here. We do not want the entry page as part of the router/flow/path history.
|
|
||||||
window.location = `/?issPage=${issPageValues.WELCOME_PAGE}`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Remove the loading animation if client tag validation fails so users can see the Unauthorized Access message.
|
// Remove the loading animation if client tag validation fails so users can see the Unauthorized Access message.
|
||||||
showIssLoadingModal(false);
|
showIssLoadingModal(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.populateISSConfigValues(clientData);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check cookie
|
||||||
|
const issCookie = getISSCookie();
|
||||||
|
if (issCookie !== null && issCookie.VehicleMake && issCookie.VehicleModel) {
|
||||||
|
const clientParentAccountNumber = clientData.parentAccountNumber;
|
||||||
|
const cookieParentAccountNumber = issCookie.ReferralParentAccountNumber;
|
||||||
|
|
||||||
|
if (clientParentAccountNumber === cookieParentAccountNumber) {
|
||||||
|
const savedSessionTimeStamp = new Date(issCookie.SavedSessionTimeoutDate);
|
||||||
|
const isSavedSessionTimedOut = new Date(new Date().toUTCString()) > savedSessionTimeStamp;
|
||||||
|
|
||||||
|
if (!isSavedSessionTimedOut) {
|
||||||
|
this.mainStore.issConfig.enableContinueFromCookie = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateOrCreateISSCookie(true);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
updateOrCreateISSCookie(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientData.parameters?.length > 0) {
|
||||||
|
const finalParams = this.combineClientParameters(clientData.parameters, {...queryStringParams, ...decryptedParams});
|
||||||
|
this.populateStoreItemsFromParams(finalParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mainStore.applicationUser.coverageAttempts = 0;
|
||||||
|
if (
|
||||||
|
applicationConfig.CURRENT_ENVIRONMENT === 'Localhost'
|
||||||
|
|| applicationConfig.CURRENT_ENVIRONMENT === 'Dev'
|
||||||
|
|| applicationConfig.CURRENT_ENVIRONMENT === 'SysTest'
|
||||||
|
) {
|
||||||
|
this.navigateForward();
|
||||||
|
} else {
|
||||||
|
// Forced full location redirect here. We do not want the entry page as part of the router/flow/path history.
|
||||||
|
window.location = `/?issPage=${issPageValues.WELCOME_PAGE}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods:
|
methods:
|
||||||
|
|
@ -95,46 +95,51 @@ export default {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
parseQueryParms() {
|
parseQueryParms() {
|
||||||
// Dump the query string parameters into an array. Remove casing on the key for easy compare.
|
// Dump the query string parameters into an object
|
||||||
const queryStringParams = [];
|
|
||||||
|
|
||||||
if (this.$route?.query) {
|
if (this.$route?.query) {
|
||||||
Object.keys(this.$route.query).forEach((param) => {
|
return Object.fromEntries(Object.entries(this.$route?.query).map(([key, value]) => [key.toLowerCase(), value]));
|
||||||
queryStringParams[param.toLowerCase()] = this.$route.query[param];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryStringParams;
|
return {};
|
||||||
},
|
},
|
||||||
async validateClientTagOnEntry(queryStringParams) {
|
async validateClientTagOnEntry(queryStringParams) {
|
||||||
const clientTag = queryStringParams.clienttag;
|
const clientTag = queryStringParams.clienttag;
|
||||||
const clientTagPresent = !!clientTag;
|
if (!clientTag) {
|
||||||
let authorized = false;
|
return { isAuthorized: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = await validateISSClientTag(clientTag);
|
||||||
|
if (!resp) {
|
||||||
|
return { isAuthorized: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
let isAuthorized = false;
|
||||||
let clientData = null;
|
let clientData = null;
|
||||||
|
const decryptedParams = {};
|
||||||
|
|
||||||
if (clientTagPresent) {
|
if (resp.active && resp.accountName.length > 0) {
|
||||||
const resp = await validateISSClientTag(clientTag);
|
if (resp.authentication.startsWith('RSAToken')) {
|
||||||
|
const { token, signature } = queryStringParams;
|
||||||
if (resp?.data.active && resp?.data.accountName.length > 0) {
|
const vsigResp = await validateISSClientSignature(clientTag, token, signature);
|
||||||
if (resp.data.authentication === 'RSAToken') {
|
if (resp.authentication.includes('EncParams')) {
|
||||||
const { token, signature } = queryStringParams;
|
const params = new URLSearchParams(vsigResp.decryptedData);
|
||||||
const vsigResp = await validateISSClientSignature(clientTag, token, signature);
|
for (const [key, value] of params) {
|
||||||
|
decryptedParams[key.toLowerCase()] = value;
|
||||||
this.mainStore.issConfig.isAuthenticated = vsigResp?.data?.valid ?? false;
|
|
||||||
if (this.mainStore.issConfig.isAuthenticated) {
|
|
||||||
authorized = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
authorized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authorized) {
|
isAuthorized = vsigResp?.valid ?? false;
|
||||||
clientData = resp.data;
|
this.mainStore.issConfig.isAuthenticated = isAuthorized;
|
||||||
}
|
} else {
|
||||||
|
isAuthorized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAuthorized) {
|
||||||
|
clientData = resp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { isAuthorized: authorized, clientData };
|
return { isAuthorized, clientData, decryptedParams };
|
||||||
},
|
},
|
||||||
populateISSConfigValues(data) {
|
populateISSConfigValues(data) {
|
||||||
this.mainStore.issConfig.clientName = data.accountName;
|
this.mainStore.issConfig.clientName = data.accountName;
|
||||||
|
|
@ -169,22 +174,17 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
combineClientParameters(configParams, queryStringParams) {
|
combineClientParameters(configParams, queryStringParams) {
|
||||||
const finalParams = [];
|
const finalParams = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const clientParams = JSON.parse(configParams);
|
const clientParams = JSON.parse(configParams);
|
||||||
|
for (const clientParam of clientParams) {
|
||||||
Object.keys(clientParams).forEach((cparam) => {
|
const paramName = clientParam.toLowerCase();
|
||||||
const cname = clientParams[cparam].toLowerCase();
|
const value = queryStringParams[paramName];
|
||||||
|
if (value) {
|
||||||
Object.keys(queryStringParams).forEach((qsparam) => {
|
finalParams[paramName] = value;
|
||||||
const qsname = qsparam.toLowerCase();
|
}
|
||||||
|
}
|
||||||
if (cname === qsname) {
|
|
||||||
finalParams[cname] = queryStringParams[cname];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.console.error(`Error combining client parameters: ${e}`);
|
window.console.error(`Error combining client parameters: ${e}`);
|
||||||
}
|
}
|
||||||
|
|
@ -193,12 +193,9 @@ export default {
|
||||||
},
|
},
|
||||||
populateStoreItemsFromParams(params) {
|
populateStoreItemsFromParams(params) {
|
||||||
// Populate store items from parameters.
|
// Populate store items from parameters.
|
||||||
|
for (const [key, value] of Object.entries(params)) {
|
||||||
Object.keys(params).forEach((param) => {
|
switch (key.toLowerCase()) {
|
||||||
const name = param.toLowerCase();
|
case 'policynbr':
|
||||||
const value = params[param];
|
|
||||||
|
|
||||||
switch (name) {
|
|
||||||
case 'policynumber':
|
case 'policynumber':
|
||||||
this.mainStore.order.policy.policyNumber = value;
|
this.mainStore.order.policy.policyNumber = value;
|
||||||
this.mainStore.issConfig.disabledFields.policyNumber = true;
|
this.mainStore.issConfig.disabledFields.policyNumber = true;
|
||||||
|
|
@ -209,16 +206,19 @@ export default {
|
||||||
this.mainStore.issConfig.disabledFields.policyZipCode = true;
|
this.mainStore.issConfig.disabledFields.policyZipCode = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'dateofloss':
|
||||||
case 'lossdate':
|
case 'lossdate':
|
||||||
// NOTE: May need some date parsing logic in here depending on client.
|
// NOTE: May need some date parsing logic in here depending on client.
|
||||||
this.mainStore.order.policy.dateOfLoss = value;
|
this.mainStore.order.policy.dateOfLoss = value;
|
||||||
this.mainStore.issConfig.disabledFields.dateOfLoss = true;
|
this.mainStore.issConfig.disabledFields.dateOfLoss = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'returnurl':
|
||||||
case 'successreturnurl':
|
case 'successreturnurl':
|
||||||
this.mainStore.issConfig.successReturnURL = value;
|
this.mainStore.issConfig.successReturnURL = value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'returnurl2':
|
||||||
case 'failurereturnurl':
|
case 'failurereturnurl':
|
||||||
this.mainStore.issConfig.failureReturnURL = value;
|
this.mainStore.issConfig.failureReturnURL = value;
|
||||||
break;
|
break;
|
||||||
|
|
@ -230,7 +230,7 @@ export default {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue