mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-10-28 22:12:26 -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 {
|
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",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue