diff --git a/credentials/HttpBinApi.credentials.ts b/credentials/HttpBinApi.credentials.ts index 0b74def..efd8639 100644 --- a/credentials/HttpBinApi.credentials.ts +++ b/credentials/HttpBinApi.credentials.ts @@ -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 => { + 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", }, }; }