oidc-client-rx
Version:
ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications
29 lines (28 loc) • 1.1 kB
JavaScript
import { POSITIVE_VALIDATION_RESULT } from "../rule.js";
const createIdentifierToCheck = (passedConfig)=>{
if (!passedConfig) return "";
const { authority, clientId, scope } = passedConfig;
return `${authority}${clientId}${scope}`;
};
const arrayHasDuplicates = (array)=>new Set(array).size !== array.length;
const ensureNoDuplicatedConfigsRule = (passedConfigs)=>{
const allIdentifiers = passedConfigs.map((x)=>createIdentifierToCheck(x));
const someAreNotSet = allIdentifiers.some((x)=>"" === x);
if (someAreNotSet) return {
result: false,
messages: [
"Please make sure you add an object with a 'config' property: ....({ config }) instead of ...(config)"
],
level: "error"
};
const hasDuplicates = arrayHasDuplicates(allIdentifiers);
if (hasDuplicates) return {
result: false,
messages: [
"You added multiple configs with the same authority, clientId and scope"
],
level: "warning"
};
return POSITIVE_VALIDATION_RESULT;
};
export { ensureNoDuplicatedConfigsRule };