feat: init and fork some code from angular-auth-oidc-client
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { OpenIdConfiguration } from '../../openid-configuration';
|
||||
import { POSITIVE_VALIDATION_RESULT, RuleValidationResult } from '../rule';
|
||||
|
||||
const createIdentifierToCheck = (passedConfig: OpenIdConfiguration): string => {
|
||||
if (!passedConfig) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const { authority, clientId, scope } = passedConfig;
|
||||
|
||||
return `${authority}${clientId}${scope}`;
|
||||
};
|
||||
|
||||
const arrayHasDuplicates = (array: string[]): boolean =>
|
||||
new Set(array).size !== array.length;
|
||||
|
||||
export const ensureNoDuplicatedConfigsRule = (
|
||||
passedConfigs: OpenIdConfiguration[]
|
||||
): RuleValidationResult => {
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user