feat(Mautic Node): Add credential test and allow trailing slash in host (#3080)

* Updated Mautic to stop trailing slashes from causing an issue

* Fixed oauth failing when there is a trailing slash in the mautic host

* Added credential test
This commit is contained in:
Jonathan Bennetts
2022-04-01 16:31:43 +01:00
committed by GitHub
parent 984f62df9e
commit 0a75539cc3
3 changed files with 67 additions and 5 deletions

View File

@@ -3,8 +3,12 @@ import {
} from 'n8n-core';
import {
ICredentialDataDecryptedObject,
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeCredentialTestResult,
INodeExecutionData,
INodePropertyOptions,
INodeType,
@@ -17,6 +21,7 @@ import {
import {
mauticApiRequest,
mauticApiRequestAllItems,
validateCredentials,
validateJSON,
} from './GenericFunctions';
@@ -80,6 +85,7 @@ export class Mautic implements INodeType {
],
},
},
testedBy: 'mauticCredentialTest',
},
{
name: 'mauticOAuth2Api',
@@ -166,6 +172,29 @@ export class Mautic implements INodeType {
};
methods = {
credentialTest: {
async mauticCredentialTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
try {
let responseData;
responseData = await validateCredentials.call(this, credential.data as ICredentialDataDecryptedObject);
if (responseData.id) {
return {
status: 'OK',
message: 'Authentication successful!',
};
}
} catch (error) {
return {
status: 'Error',
message: 'Invalid credentials',
};
}
return {
status: 'Error',
message: 'Invalid credentials',
};
},
},
loadOptions: {
// Get all the available companies to display them to user so that he can
// select them easily