feat: Add support for preAuthentication and add Metabase credentials (#3399)

*  Add preAuthentication method to credentials

* Improvements

*  Improvements

*  Add feedback

* 🔥 Remove comments

*  Add generic type to autheticate method

*  Fix typo

*  Remove console.log and fix indentation

*  Minor improvements

*  Expire credentials in every credential test run

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza
2022-07-19 04:09:06 -04:00
committed by GitHub
parent f958e6ffab
commit 994c89a6c6
9 changed files with 290 additions and 7 deletions

View File

@@ -166,6 +166,9 @@ export interface IRequestOptionsSimplifiedAuth {
skipSslCertificateValidation?: boolean | string;
}
export interface IHttpRequestHelper {
helpers: { httpRequest: IAllExecuteFunctions['helpers']['httpRequest'] };
}
export abstract class ICredentialsHelper {
encryptionKey: string;
@@ -184,6 +187,14 @@ export abstract class ICredentialsHelper {
defaultTimezone: string,
): Promise<IHttpRequestOptions>;
abstract preAuthentication(
helpers: IHttpRequestHelper,
credentials: ICredentialDataDecryptedObject,
typeName: string,
node: INode,
credentialsExpired: boolean,
): Promise<ICredentialDataDecryptedObject | undefined>;
abstract getCredentials(
nodeCredentials: INodeCredentialsDetails,
type: string,
@@ -269,6 +280,10 @@ export interface ICredentialType {
documentationUrl?: string;
__overwrittenProperties?: string[];
authenticate?: IAuthenticate;
preAuthentication?: (
this: IHttpRequestHelper,
credentials: ICredentialDataDecryptedObject,
) => Promise<IDataObject>;
test?: ICredentialTestRequest;
genericAuth?: boolean;
}
@@ -894,6 +909,7 @@ export interface INodePropertyTypeOptions {
rows?: number; // Supported by: string
showAlpha?: boolean; // Supported by: color
sortable?: boolean; // Supported when "multipleValues" set to true
expirable?: boolean; // Supported by: hidden (only in the credentials)
[key: string]: any;
}

View File

@@ -14,6 +14,7 @@ import {
IExecuteResponsePromiseData,
IExecuteSingleFunctions,
IExecuteWorkflowInfo,
IHttpRequestHelper,
IHttpRequestOptions,
IN8nHttpFullResponse,
IN8nHttpResponse,
@@ -111,6 +112,16 @@ export class CredentialsHelper extends ICredentialsHelper {
return requestParams;
}
async preAuthentication(
helpers: IHttpRequestHelper,
credentials: ICredentialDataDecryptedObject,
typeName: string,
node: INode,
credentialsExpired: boolean,
): Promise<{ updatedCredentials: boolean; data: ICredentialDataDecryptedObject }> {
return { updatedCredentials: false, data: {} }
};
getParentTypes(name: string): string[] {
return [];
}