mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core) Simplify authentication type (#3578)
* ⚡ Add generic auth type * ⚡ Remove queryAuth * ⚡ Remove bearer * ⚡ Remove headerAuth * ⚡ Remove basicAuth * ⚡ Adjust tests * ⚡ Small improvements * 👕 Fix lint issue
This commit is contained in:
@@ -98,73 +98,41 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||
if (typeof credentialType.authenticate === 'object') {
|
||||
// Predefined authentication method
|
||||
|
||||
let keyResolved: string;
|
||||
let valueResolved: string;
|
||||
const { authenticate } = credentialType;
|
||||
if (requestOptions.headers === undefined) {
|
||||
requestOptions.headers = {};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (authenticate.type === 'bearer') {
|
||||
const tokenPropertyName: string =
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.tokenPropertyName ?? 'accessToken';
|
||||
requestOptions.headers.Authorization = `Bearer ${
|
||||
credentials[tokenPropertyName] as string
|
||||
}`;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
} else if (authenticate.type === 'basicAuth') {
|
||||
const userPropertyName: string =
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.userPropertyName ?? 'user';
|
||||
const passwordPropertyName: string =
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.passwordPropertyName ?? 'password';
|
||||
if (authenticate.type === 'generic') {
|
||||
Object.entries(authenticate.properties).forEach(([outerKey, outerValue]) => {
|
||||
Object.entries(outerValue).forEach(([key, value]) => {
|
||||
keyResolved = this.resolveValue(
|
||||
key,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
|
||||
requestOptions.auth = {
|
||||
username: credentials[userPropertyName] as string,
|
||||
password: credentials[passwordPropertyName] as string,
|
||||
};
|
||||
} else if (authenticate.type === 'headerAuth') {
|
||||
const key = this.resolveValue(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.name,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
valueResolved = this.resolveValue(
|
||||
value as string,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
|
||||
const value = this.resolveValue(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.value,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
requestOptions.headers[key] = value;
|
||||
} else if (authenticate.type === 'queryAuth') {
|
||||
const key = this.resolveValue(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.key,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
|
||||
const value = this.resolveValue(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
authenticate.properties.value,
|
||||
{ $credentials: credentials },
|
||||
workflow,
|
||||
node,
|
||||
defaultTimezone,
|
||||
);
|
||||
if (!requestOptions.qs) {
|
||||
requestOptions.qs = {};
|
||||
}
|
||||
requestOptions.qs[key] = value;
|
||||
// @ts-ignore
|
||||
if (!requestOptions[outerKey]) {
|
||||
// @ts-ignore
|
||||
requestOptions[outerKey] = {};
|
||||
}
|
||||
// @ts-ignore
|
||||
requestOptions[outerKey][keyResolved] = valueResolved;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user