Async authenticate doesn't work at latest n8n version?

Describe the problem/error/question

hello. i have problem.
i made good working code at n8n v1.68.1. but it is not working latest version.

The following code (//HERE!! section) works fine in n8n version 1.68.1 but does not work in versions 1.80.3 and 1.78.0

  1. The credential for Solapi API is created successfully.
  2. A workflow’s HTTP request node is created.
  3. In the authentication settings of the HTTP request node:

Authentication - Select Predefined Credential Type

Here,

  • In version 1.68.0: The credential type “Solapi API” is visible and selectable.
  • In version 1.80.3: “Solapi API” is not visible and cannot be used.

Is async authenticate not supported in the latest versions (such as 1.80.3)?

thanks for reading

code

import {
        IAuthenticateGeneric,
        ICredentialTestRequest,
        ICredentialType,
        INodeProperties,
        ICredentialDataDecryptedObject,
IHttpRequestHelper,

IHttpRequestOptions
} from 'n8n-workflow';
import * as crypto from 'crypto'


export class AllabuSolapiKakaoApi implements ICredentialType {
        name = 'allabusolapikakaoApi';
        displayName = 'Solapi API';
        properties: INodeProperties[] = [
                {
                        displayName: 'API KEY',
                        name: 'apiKey',
                        type: 'string',
                        typeOptions: {
                                password: false,
                        },
                        default: '',
                },
                {
                        displayName: 'API secret',
                        name: 'apiSecret',
                        type: 'string',
                        typeOptions: {
                                password: true,
                        },
                        default: '',
                },
        ];

        // HERE!!! authenticate doesn't work n8n v1.80.3
        async authenticate(
                credentials: ICredentialDataDecryptedObject,
                requestOptions: IHttpRequestOptions,
        ): Promise<IHttpRequestOptions> {

            console.log('preAuthenticate called with credentials:', credentials);
            const apiKey = credentials.apiKey;
            const salt = 'jqsba2jxjnrjor';//crypto.randomBytes(16).toString('hex');
            const dateTime = new Date().toISOString();
            const signatureString =  dateTime + salt;

            const apiSecret = String(credentials.apiSecret);
            const signature = crypto.createHmac('sha256', apiSecret).update(signatureString).digest('hex');

            const authString = 'HMAC-SHA256 apiKey=' + apiKey  + ', date=' + dateTime + ', salt=' + salt + ', signature=' + signature;
            console.log("authString: ", authString);

//              requestOptions.headers!.Authorization = authString;
                requestOptions.headers = {
                        Accept: 'application/json',
                        'X-Ninja-Token': authString,
                };
                return requestOptions;
        }


/*  not using
        authenticate: IAuthenticateGeneric = {
                type: 'generic',
                properties: {
                        // This will be set dynamically in the `preAuthenticate` function
                        headers: {
                            'Authorization': 'authString',
                        },
                },
        };
not using */
}

What is the error message (if any)?

good working(v1.68.1) - same code

not working(v1.80.1) - same code

Please share your workflow

Information on your n8n setup

  • n8n version:1.80.3
  • Database (default: SQLite):default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • Operating system:ubuntu(linux)

Hey @taaho_ahn,

According to Solapi documentation here, you can use Header Auth or OAuth2.

In n8n you already have generic options for those:

After reading some of the documentation, I think OAuth2 is easier to configure in n8n, because their Header authentication is complex.

:point_right: If my reply answers your question, please remember to mark it as a solution.

I want to use api key with auth header.
But It is complex , so i am trying to make custom credential to make header string easy.
Is 'aync authebticate ’ working still?

i am using wrong version of . n8n-workflow library.
now it works with n8n-nodes-stater

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.