feat(core) Simplify authentication type (#3578)

*  Add generic auth type

*  Remove queryAuth

*  Remove bearer

*  Remove headerAuth

*  Remove basicAuth

*  Adjust tests

*  Small improvements

* 👕 Fix lint issue
This commit is contained in:
Jan Oberhauser
2022-06-26 15:55:51 -07:00
committed by GitHub
parent 1e4fd9e4df
commit 86721fc496
15 changed files with 207 additions and 281 deletions

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateBearer,
IAuthenticateGeneric,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -17,9 +17,13 @@ export class AsanaApi implements ICredentialType {
},
];
authenticate = {
type: 'bearer',
properties: {},
} as IAuthenticateBearer;
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};
}

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateQueryAuth,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -24,13 +24,14 @@ export class CalApi implements ICredentialType {
},
];
authenticate = {
type: 'queryAuth',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
key: 'apiKey',
value: '={{$credentials.apiKey}}',
qs: {
apiKey: '={{$credentials.apiKey}}',
},
},
} as IAuthenticateQueryAuth;
};
test: ICredentialTestRequest = {
request: {

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateHeaderAuth,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -30,13 +30,16 @@ export class GithubApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateHeaderAuth = {
type: 'headerAuth',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
name: 'Authorization',
value: '=token {{$credentials?.accessToken}}',
headers: {
Authorization: '=token {{$credentials?.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials?.server}}',

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateHeaderAuth,
IAuthenticateGeneric,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -26,11 +26,13 @@ export class HttpHeaderAuth implements ICredentialType {
default: '',
},
];
authenticate = {
type: 'headerAuth',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
name: '={{credentials.name}}',
value: '={{credentials.value}}',
headers: {
'={{$credentials.name}}': '={{$credentials.value}}',
},
},
} as IAuthenticateHeaderAuth;
};
}

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateBearer,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -30,8 +30,12 @@ export class Magento2Api implements ICredentialType {
},
};
authenticate = {
type: 'bearer',
properties: {},
} as IAuthenticateBearer;
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};
}

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateBasicAuth,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -30,13 +30,17 @@ export class MailjetEmailApi implements ICredentialType {
description: 'Whether to allow to run the API call in a Sandbox mode, where all validations of the payload will be done without delivering the message',
},
];
authenticate: IAuthenticateBasicAuth = {
type: 'basicAuth',
properties: {
userPropertyName: 'apiKey',
passwordPropertyName: 'secretKey',
},
};
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
auth: {
username: '={{$credentials.apiKey}}',
password: '={{$credentials.secretKey}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: `https://api.mailjet.com`,

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateHeaderAuth,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -17,13 +17,16 @@ export class MailjetSmsApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateHeaderAuth = {
type: 'headerAuth',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
name: 'Authorization',
value: '=Bearer {{$credentials.token}}',
headers: {
Authorization: '=Bearer {{$credentials.token}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: `https://api.mailjet.com`,

View File

@@ -1,6 +1,5 @@
import {
IAuthenticateQueryAuth,
ICredentialTestRequest,
IAuthenticateGeneric,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
@@ -19,11 +18,12 @@ export class PipedriveApi implements ICredentialType {
},
];
authenticate = {
type: 'queryAuth',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
key: 'api_token',
value: '={{$credentials.apiToken}}',
qs: {
api_token: '={{$credentials.apiToken}}',
},
},
} as IAuthenticateQueryAuth;
};
}

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateBasicAuth,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -40,10 +40,17 @@ export class ServiceNowBasicApi implements ICredentialType {
required: true,
},
];
authenticate: IAuthenticateBasicAuth = {
type: 'basicAuth',
properties: {},
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
auth: {
username: '={{$credentials.user}}',
password: '={{$credentials.password}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '=https://{{$credentials?.subdomain}}.service-now.com',

View File

@@ -1,6 +1,5 @@
import {
IAuthenticateBearer,
IAuthenticateQueryAuth,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -19,12 +18,16 @@ export class SlackApi implements ICredentialType {
required: true,
},
];
authenticate: IAuthenticateBearer = {
type: 'bearer',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
tokenPropertyName: 'accessToken',
headers: {
Authorization: '=Bearer {{$credentials.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://slack.com',

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateBearer,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -18,12 +18,14 @@ export class TodoistApi implements ICredentialType {
];
authenticate = {
type: 'bearer',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
tokenPropertyName: 'apiKey',
headers: {
Authorization: '=Bearer {{$credentials.apiKey}}',
},
},
} as IAuthenticateBearer;
};
test: ICredentialTestRequest = {
request: {

View File

@@ -1,5 +1,5 @@
import {
IAuthenticateBearer,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
@@ -17,12 +17,15 @@ export class TwakeCloudApi implements ICredentialType {
default: '',
},
];
authenticate = {
type: 'bearer',
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
tokenPropertyName: 'workspaceKey',
headers: {
Authorization: '=Bearer {{$credentials.workspaceKey}}',
},
},
} as IAuthenticateBearer;
};
test: ICredentialTestRequest = {
request: {