mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-10-28 14:12:24 -05:00
♻️ Add Bearer Token authentication section
This commit is contained in:
parent
f528f995a2
commit
35b1808ce0
1 changed files with 33 additions and 12 deletions
|
|
@ -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",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue