Merge pull request #450 from Safelite/feature/SSR-705
SSR-705: Client signature validation call implementation
This commit is contained in:
commit
829bd75eb2
4 changed files with 68 additions and 30 deletions
|
|
@ -126,6 +126,10 @@ const endpoints = Object.freeze({
|
|||
url: '/clientauth/api/v1/clientauth/validate-client-tag',
|
||||
method: 'GET'
|
||||
},
|
||||
ValidateClientSignature: {
|
||||
url: '/clientauth/api/v1/clientauth/validate-client-signature',
|
||||
method: 'POST'
|
||||
},
|
||||
IsVinbyAddressPermissible: {
|
||||
url: '/vehicle/api/v1/vehicle/is-vin-by-address-permissible',
|
||||
method: 'Get'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useMainStore } from '@/store';
|
||||
|
||||
const validateISSClientTag = (clientTag) => {
|
||||
export function validateISSClientTag(clientTag) {
|
||||
const store = useMainStore();
|
||||
|
||||
return store.validateClientTag(clientTag)
|
||||
|
|
@ -8,6 +8,14 @@ const validateISSClientTag = (clientTag) => {
|
|||
(response) => response,
|
||||
() => null
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default validateISSClientTag;
|
||||
export function validateISSClientSignature(clientTag, token, signature) {
|
||||
const store = useMainStore();
|
||||
|
||||
return store.validateClientSignature(clientTag, token, signature)
|
||||
.then(
|
||||
(response) => response,
|
||||
() => null
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<script>
|
||||
// Supporting files
|
||||
import issPageValues from '@/router/router-constants/issPage-values';
|
||||
import validateISSClientTag from '@/helpers/clientauth-helper';
|
||||
import { validateISSClientTag, validateISSClientSignature } from '@/helpers/clientauth-helper';
|
||||
import { useMainStore } from '@/store';
|
||||
|
||||
export default {
|
||||
|
|
@ -44,10 +44,13 @@ export default {
|
|||
parseQueryParms() {
|
||||
// Dump the query string parameters into an array. Remove casing on the key for easy compare.
|
||||
const queryStringParams = [];
|
||||
// TODO: Modify to not iterate entire prototype chain
|
||||
for (const param in this.$route.query) {
|
||||
queryStringParams[param.toLowerCase()] = this.$route.query[param];
|
||||
|
||||
if (this.$route?.query) {
|
||||
Object.keys(this.$route.query).forEach((param) => {
|
||||
queryStringParams[param.toLowerCase()] = this.$route.query[param];
|
||||
});
|
||||
}
|
||||
|
||||
return queryStringParams;
|
||||
},
|
||||
async validateClientTagOnEntry() {
|
||||
|
|
@ -60,13 +63,27 @@ export default {
|
|||
const resp = await validateISSClientTag(clientTag);
|
||||
|
||||
if (resp?.data.active && resp?.data.accountName.length > 0) {
|
||||
this.populateISSConfigValues(resp.data);
|
||||
if (resp.data.authentication === 'RSAToken') {
|
||||
const token = queryStringParams.token;
|
||||
const signature = queryStringParams.signature;
|
||||
|
||||
authorized = true;
|
||||
const vsigResp = await validateISSClientSignature(clientTag, token, signature);
|
||||
this.mainStore.issConfig.isAuthenticated = vsigResp?.data?.valid ?? false;
|
||||
|
||||
if (resp.data.parameters?.length > 0) {
|
||||
const finalParams = this.combineClientParameters(resp.data.parameters, queryStringParams);
|
||||
this.populateStoreItemsFromParams(finalParams);
|
||||
if (this.mainStore.issConfig.isAuthenticated) {
|
||||
authorized = true;
|
||||
}
|
||||
} else {
|
||||
authorized = true;
|
||||
}
|
||||
|
||||
if (authorized) {
|
||||
await this.populateISSConfigValues(resp.data);
|
||||
|
||||
if (resp.data.parameters?.length > 0) {
|
||||
const finalParams = this.combineClientParameters(resp.data.parameters, queryStringParams);
|
||||
this.populateStoreItemsFromParams(finalParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,17 +95,13 @@ export default {
|
|||
window.location = `/?issPage=${issPageValues.WELCOME_PAGE}`;
|
||||
}
|
||||
},
|
||||
populateISSConfigValues(data) {
|
||||
async populateISSConfigValues(data) {
|
||||
this.mainStore.issConfig.clientName = data.accountName;
|
||||
this.mainStore.issConfig.clientDisplayName = data.accountName; // Defaults to use the client name.
|
||||
this.mainStore.issConfig.accountNumber = data.accountNumber;
|
||||
this.mainStore.issConfig.styleSheet = data.styleSheet;
|
||||
this.mainStore.issConfig.isCoverageEnabled = data.coverageEnabled;
|
||||
|
||||
// NOTE: This is only here for testing purposes.
|
||||
// Will be removed and replaced by actual token / signature validation when work is completed.
|
||||
if (data.authentication === 'RSAToken') this.mainStore.issConfig.isAuthenticated = true;
|
||||
|
||||
try {
|
||||
if (data.clientFlags) {
|
||||
const clientFlags = JSON.parse(data.clientFlags);
|
||||
|
|
@ -115,19 +128,17 @@ export default {
|
|||
try {
|
||||
const clientParams = JSON.parse(configParams);
|
||||
|
||||
// TODO: Modify to not iterate entire prototype chain
|
||||
for (const cparam in clientParams) {
|
||||
Object.keys(clientParams).forEach((cparam) => {
|
||||
const cname = clientParams[cparam].toLowerCase();
|
||||
|
||||
// TODO: Modify to not iterate entire prototype chain
|
||||
for (const qsparam in queryStringParams) {
|
||||
Object.keys(queryStringParams).forEach((qsparam) => {
|
||||
const qsname = qsparam.toLowerCase();
|
||||
|
||||
if (cname === qsname) {
|
||||
finalParams[cname] = queryStringParams[cname];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
window.console.error(`Error combining client parameters: ${e}`);
|
||||
}
|
||||
|
|
@ -136,8 +147,8 @@ export default {
|
|||
},
|
||||
populateStoreItemsFromParams(params) {
|
||||
// Populate store items from parameters.
|
||||
// TODO: Modify to not iterate entire prototype chain
|
||||
for (const param in params) {
|
||||
|
||||
Object.keys(params).forEach((param) => {
|
||||
const name = param.toLowerCase();
|
||||
const value = params[param];
|
||||
|
||||
|
|
@ -172,7 +183,7 @@ export default {
|
|||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ export const useMainStore = defineStore({
|
|||
|
||||
getDamageOptions(carId) {
|
||||
return globalMethods.callHttpClient({
|
||||
methods: endpoints.GetDamageOptions.method,
|
||||
method: endpoints.GetDamageOptions.method,
|
||||
endpoint: `${endpoints.GetDamageOptions.url}/${carId}`,
|
||||
payload: {}
|
||||
});
|
||||
|
|
@ -799,7 +799,7 @@ export const useMainStore = defineStore({
|
|||
setVehicle() {
|
||||
return globalMethods
|
||||
.callHttpClient({
|
||||
methods: endpoints.GetVehicle.method,
|
||||
method: endpoints.GetVehicle.method,
|
||||
endpoint: `${endpoints.GetVehicle.url}/${this.order.vehicle.year}/${this.order.vehicle.make}/${this.order.vehicle.model}/${this.order.vehicle.style}`,
|
||||
payload: {}
|
||||
})
|
||||
|
|
@ -1535,18 +1535,33 @@ export const useMainStore = defineStore({
|
|||
|
||||
async validateZip({ zip }) {
|
||||
return await globalMethods.callHttpClient({
|
||||
methods: endpoints.ValidateZip.method,
|
||||
method: endpoints.ValidateZip.method,
|
||||
endpoint: `${endpoints.ValidateZip.url}/${zip}`
|
||||
});
|
||||
},
|
||||
|
||||
async validateClientTag(clientTag) {
|
||||
return await globalMethods.callHttpClient({
|
||||
methods: endpoints.ValidateClientTag.method,
|
||||
method: endpoints.ValidateClientTag.method,
|
||||
endpoint: `${endpoints.ValidateClientTag.url}/${clientTag}`
|
||||
});
|
||||
},
|
||||
|
||||
async validateClientSignature(clientTag, token, signature) {
|
||||
|
||||
const payload = {
|
||||
clientTag,
|
||||
token,
|
||||
signature
|
||||
};
|
||||
|
||||
return await globalMethods.callHttpClient({
|
||||
method: endpoints.ValidateClientSignature.method,
|
||||
endpoint: endpoints.ValidateClientSignature.url,
|
||||
payload
|
||||
});
|
||||
},
|
||||
|
||||
saveServiceLocation(serviceLocationInfo) {
|
||||
if (this.order.serviceLocation) {
|
||||
if (
|
||||
|
|
|
|||
Loading…
Reference in a new issue