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