♻️ Add Bearer Token authentication section

This commit is contained in:
brianinoa 2022-06-16 11:53:57 +02:00
commit 35b1808ce0

View file

@ -1,7 +1,8 @@
import {
IAuthenticateHeaderAuth,
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from "n8n-workflow";
@ -11,11 +12,17 @@ export class HttpBinApi implements ICredentialType {
documentationUrl = "httpbin";
properties: INodeProperties[] = [
{
displayName: "API Key",
name: "apiKey",
displayName: "Token",
name: "token",
type: "string",
default: "",
},
// {
// displayName: "API Key",
// name: "apiKey",
// type: "string",
// default: "",
// },
{
displayName: "Domain",
name: "domain",
@ -23,17 +30,31 @@ export class HttpBinApi implements ICredentialType {
default: "https://httpbin.org",
},
];
authenticate = {
type: "headerAuth",
properties: {
name: "api-key",
value: "={{$credentials.apiKey}}",
},
} as IAuthenticateHeaderAuth;
// 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;
};
test: ICredentialTestRequest = {
request: {
baseURL: "={{$credentials?.domain}}/v3",
url: "/account",
baseURL: "={{$credentials?.domain}}",
url: "/bearer",
},
};
}