Authentication in Declarative nodes

Hi,

As this is my first question here I’d like to take the opportunity to say how fun it has been to play around with N8N until now and how great I think the tool is.

I’ve been experimenting with creating my own nodes, and was trying to use declarative nodes only. I was wondering if it was possible to use Digest authentification using declarative nodes (and maybe even Oauth) ?

I’ve used it without issues with Basic auth until now, but I need to transition to Digest and can’t figure it out. My guess was that I could do something in the routing/credentials to solve my issue, but I couldn’t find the solution nor a clear yes/no in the documentation.

Any help would be great !

Welcome to the community @Alelf !

Really great to hear that you are having a good time with n8n and that it is helpful for you.

Regarding your questions.

Digest auth:
I just checked, but did not test it myself, but it should work pretty much the same as basic auth with the difference that additionally, sendImmediately has to be set to false. So you would define on the credential something like that:

authenticate: IAuthenticateGeneric = {
  type: 'generic',
  properties: {
    user: '={{$credentials.user}}',
    pass: '={{$credentials.password}}',
    sendImmediately: false,
  }
};

OAuth:
There should actually be nothing special to be done. You just create an OAuth2 credential type and tell the node via the credentials property that it should be used. So something like that:

{
  displayName: 'MyNode',
  name: 'myNode',
  version: 1,
  defaults: {
    name: 'MyNode',
  },
  inputs: ['main'],
  outputs: ['main'],
  ...
  credentials: [
    {
      name: 'myNodeOAuth2Api',
      required: true,
    },
  ],
  ...
}

Please report back if that all worked fine.

Hi,

Thanks a lot for the quick answer. I’ve done a few tests and here are my issues:

Using the suggested syntax, I get the following error:

 error TS2322: Type '{ username: string; password: string; sendImmediately: false; }' is not assignable to type '{ username: string; password: string; }'. Object literal may only specify known properties, and 'sendImmediately' does not exist in type '{ username: string; password: string; }'.

The expected type comes from property 'auth' which is declared here on type 'IRequestOptionsSimplifiedAuth'

Which makes sense I guess given the definition of IRequestOptionsSimplifiedAuth. So I’ve tried the following syntax:

authenticate = {
	type: 'generic',
	properties: {
		auth: {
			username: '={{$credentials.user}}', 
			password: '={{$credentials.password}}', 
			sendImmediately: false,
			},
		},
	} as IAuthenticateGeneric;

Which I can build but then will throw me an error in the Workflow (parameterValue.charAt). I’ve tried a few variants without much success. Am I using the right type with IAuthenticateGeneric ?

Thanks!

Hi Again,

So I’ve done countless tests since my last post, but I really can’t figure this out. I don’t know if I’m missing something obvious, or if it’s not as simple as it looks; it works without issues with the http request node, but I can’t get it to work with my declarative node.

Here is my full credentials file:

import {
	IAuthenticateGeneric,
	ICredentialType,
	INodeProperties,
} from 'n8n-workflow';


export class TestWSAPI implements ICredentialType {
	name = 'TestWSAPI';
	displayName = 'TestWSAPI';
	genericAuth = true;
	properties: INodeProperties[] = [
		{
			displayName: 'Digest Auth - User',
			name: 'user',
			type: 'string',
			default: '',
		},
		{
			displayName: 'Digest Auth - Password',
			name: 'password',
			type: 'string',
			typeOptions: {
				password: true,
			},
			default: '',
		},
	];
	authenticate = {
		type: 'generic',
		properties: {
			auth: {
				username: '={{$credentials.user}}', 
				password: '={{$credentials.password}}', 
				sendImmediately: false,
			},
		},

	} as IAuthenticateGeneric;
}

This builds fine, but throws an error:

NodeApiError: UNKNOWN ERROR - check the detailed error for more information
    at RoutingNode.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/RoutingNode.js:112:23)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:694:23)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:590:53

I’ve tried to analyze and modify a bit Routing.ts but it’s a rabbit hole I’d rather avoid (and it wasn’t going great for me). I’ve also tried to look for other nodes that implement sendImmediately but couldn’t find any (at least declarative).

Anyways I’m open to ideas !

Best,

Hey @Alelf,

I will make a note to take a look at this on Monday, my initial thought would have been that digest auth is not currently supported for the authenticate function.

To get up and running with your node you can use the other way to build nodes and don’t have the authentication in the credential file.

Hi @Jon,

Thanks a lot for your feedback.

If it turns out it is not currently supported, do you think it’s fairly easy to implement ? My feeling is that it’s just a matter of “carrying” the parameter from auth. to the request in the Routing, but I might be underestimating the side-effects.

I am just trying to determine if it’s worth for me waiting before I convert my node or just wait for an implementation of sendImmediately in the Routing.

Side question that is related to the previous one, can you confirm OAuth is supported in declarative nodes ? I can’t currently test it with my setup but if not I might as well start converting to programmatic nodes right away as I will need this towards September.

Thanks a lot for all the work and the support!

Hey @Alelf,

OAuth is supported, technically you could also use digest auth it would be a case of moving the authentication out of the credential and into the node itself.

If it isn’t currently supported I suspect it will be fairly quick to add although I have not touched that part of n8n yet so it will be fun to find out :slightly_smiling_face:

I will let you know what I find.

Very sorry @Alelf did not find time to check it out earlier.

It was not supported in the past. Created the following PR which should change that:

2 Likes

Thanks a lot !

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

New version [email protected] got released which includes the GitHub PR 5676.