凭证文件
凭证文件定义了节点的授权方法。此文件中的设置会影响 n8n 在
凭证模式中的显示内容,并且必须反映您所连接的服务的身份验证要求。在凭证文件中,您可以使用所有
n8n UI 元素。n8n 使用加密密钥对使用凭证存储的数据进行加密。凭证文件的结构
凭证文件遵循以下基本结构:
- 导入语句
- 为凭证创建一个类
- 在类中,定义控制节点身份验证的属性。
概要结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
参数
name#
字符串。对象的内部名称。用于从节点中的其他地方引用它。
displayName#
字符串。n8n 在 GUI 中使用的名称。
documentationUrl#
字符串。您的凭证文档的 URL。
properties#
每个对象包含:
- :n8n 在 GUI 中使用的名称。
- :对象的内部名称。用于从节点中的其他地方引用它。
- :期望的数据类型,例如。
- :n8n 应该用来测试凭证的 URL。
authenticate#
- :对象。包含告诉 n8n 如何将身份验证数据作为 API 请求的一部分注入的对象。
type#
字符串。如果您使用的身份验证方法在标头、正文或查询字符串中发送数据,请将其设置为。
properties#
对象。定义身份验证方法。选项包括:
-
:对象。在请求正文中发送身份验证数据。可以包含嵌套对象。
1 2 3 4 5 6 7 8 9
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { body: { username: '={{$credentials.username}}', password: '={{$credentials.password}}', }, }, }; -
:对象。在请求标头中发送身份验证数据。
1 2 3 4 5 6 7 8
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { header: { Authorization: '=Bearer {{$credentials.authToken}}', }, }, }; -
:对象。代表“查询字符串”。在请求查询字符串中发送身份验证数据。
1 2 3 4 5 6 7 8
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { qs: { token: '={{$credentials.token}}', }, }, }; -
:对象。用于基本身份验证。需要和作为键名。
1 2 3 4 5 6 7 8 9
authenticate: IAuthenticateGeneric = { type: 'generic', properties: { auth: { username: '={{$credentials.username}}', password: '={{$credentials.password}}', }, }, };
test#
提供一个包含 URL 和身份验证类型的对象,n8n 可以使用它来测试凭证。
1 2 3 4 5 6 | |