1.6 KiB
[TODO: in com nodes release]
Simplify authentication setup for node creators
This release introduces a simpler way of handling authorization when building a node. All credentials should now contain an authenticate property that dictates how the credential is used in a request.
n8n has also simplified authentication types: instead of specifying an authentication type and using the correct interface, you can now set the type as "generic", and use the IAuthenticateGeneric interface.
You can use this approach for any authentication method where data is sent in the header, body, or query string. This includes methods like bearer and basic auth. You can't use this approach for more complex authentication types that require multiple calls, or for methods that don't pass authentication data. This includes OAuth.
For an example of the new authentication syntax, refer to n8n's Asana node{:target=_blank .external-link}.
// in AsanaApi.credentials.ts
import {
IAuthenticateGeneric,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
export class AsanaApi implements ICredentialType {
name = 'asanaApi';
displayName = 'Asana API';
documentationUrl = 'asana';
properties: INodeProperties[] = [
{
displayName: 'Access Token',
name: 'accessToken',
type: 'string',
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};
}