mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(Mautic Node): Fix authentication issue (#3761)
* Fixes mautic credential issue * removed unused imports Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
15d8ffd3ba
commit
fe58769b48
|
@ -1,8 +1,7 @@
|
||||||
import {
|
import {
|
||||||
ICredentialDataDecryptedObject,
|
IAuthenticateGeneric,
|
||||||
ICredentialTestRequest,
|
ICredentialTestRequest,
|
||||||
ICredentialType,
|
ICredentialType,
|
||||||
IHttpRequestOptions,
|
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
@ -34,22 +33,16 @@ export class MauticApi implements ICredentialType {
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
async authenticate(
|
|
||||||
credentials: ICredentialDataDecryptedObject,
|
|
||||||
requestOptions: IHttpRequestOptions,
|
|
||||||
): Promise<IHttpRequestOptions> {
|
|
||||||
const { url, username, password } = credentials as {
|
|
||||||
url: string;
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
};
|
|
||||||
const credentialUrl = url.endsWith('/') ? `${url}api/users/self` : `${url}/api/users/self`;
|
|
||||||
const base64Key = Buffer.from(`${username}:${password}`).toString('base64');
|
|
||||||
requestOptions.headers!['Authorization'] = `Basic ${base64Key}`;
|
|
||||||
requestOptions.url = credentialUrl ? credentialUrl : requestOptions.url;
|
|
||||||
|
|
||||||
return requestOptions;
|
authenticate: IAuthenticateGeneric = {
|
||||||
}
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
auth: {
|
||||||
|
username: '={{$credentials.username}}',
|
||||||
|
password: '={{$credentials.password}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
test: ICredentialTestRequest = {
|
test: ICredentialTestRequest = {
|
||||||
request: {
|
request: {
|
||||||
|
|
|
@ -29,8 +29,12 @@ export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||||
let returnData;
|
let returnData;
|
||||||
|
|
||||||
if (authenticationMethod === 'credentials') {
|
if (authenticationMethod === 'credentials') {
|
||||||
|
const credentials = await this.getCredentials('mauticApi');
|
||||||
|
const baseUrl = credentials.url as string;
|
||||||
|
|
||||||
|
options.uri = `${baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl}${options.uri}`;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
returnData = await this.helpers.httpRequestWithAuthentication.call(this, 'mauticApi', options);
|
returnData = await this.helpers.requestWithAuthentication.call(this, 'mauticApi', options);
|
||||||
} else {
|
} else {
|
||||||
const credentials = await this.getCredentials('mauticOAuth2Api');
|
const credentials = await this.getCredentials('mauticOAuth2Api');
|
||||||
const baseUrl = credentials.url as string;
|
const baseUrl = credentials.url as string;
|
||||||
|
|
Loading…
Reference in a new issue