🔀 Merge master

This commit is contained in:
Iván Ovejero 2022-06-30 17:09:31 +02:00
commit b4cce8d55c
4 changed files with 99 additions and 47 deletions

View file

@ -1,23 +1,56 @@
import { ICredentialType, INodeProperties } from 'n8n-workflow';
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
export class ExampleCredentials implements ICredentialType {
name = 'exampleCredentials';
displayName = 'Example Credentials';
properties: INodeProperties[] = [
// Credential data to request from the user, saved in encrypted format.
// Credential properties are defined exactly like node properties.
// The credentials to get from user and save encrypted.
// Properties can be defined exactly in the same way
// as node properties.
{
displayName: 'Base URL',
name: 'url',
displayName: 'User Name',
name: 'username',
type: 'string',
default: '',
placeholder: 'https://example.com',
},
{
displayName: 'Access Token',
name: 'accessToken',
displayName: 'Password',
name: 'password',
type: 'string',
typeOptions: {
password: true,
},
default: '',
},
];
// This credential is currently not used by any node directly
// but the HTTP Request node can use it to make requests.
// The credential is also testable due to the `test` property below
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
auth: {
username: '={{ $credentials.username }}',
password: '={{ $credentials.password }}',
},
qs: {
// Send this as part of the query string
n8n: 'rocks',
},
},
};
// The block below tells how this credential can be tested
test: ICredentialTestRequest = {
request: {
baseURL: 'https://example.com/',
url: '',
},
};
}

View file

@ -1,8 +1,7 @@
import {
ICredentialDataDecryptedObject,
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
@ -17,12 +16,6 @@ export class HttpBinApi implements ICredentialType {
type: 'string',
default: '',
},
// {
// displayName: "API Key",
// name: "apiKey",
// type: "string",
// default: "",
// },
{
displayName: 'Domain',
name: 'domain',
@ -31,26 +24,20 @@ export class HttpBinApi implements ICredentialType {
},
];
// authenticate = {
// type: "headerAuth",
// properties: {
// name: "api-key",
// value: "={{$credentials.apiKey}}",
// },
// } as IAuthenticateHeaderAuth;
authenticate = async (
credentials: ICredentialDataDecryptedObject,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> => {
const headers = requestOptions.headers || {};
const authentication = { Authorization: `Bearer ${credentials.token}` };
Object.assign(requestOptions, {
headers: { ...authentication, ...headers },
});
return requestOptions;
};
// This allows the credential to be used by other parts of n8n
// stating how this credential is injected as part of the request
// An example is the Http Request node that can make generic calls
// reusing this credential
authenticate = {
type: 'generic',
properties: {
headers: {
Authorization: '={{"Bearer " + $credentials.token}}',
},
},
} as IAuthenticateGeneric;
// The block below tells how this credential can be tested
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials?.domain}}',