Skip to content

HTTP 请求凭据(HTTP Request credentials)#

你可以使用以下凭据验证以下节点:

🌐 You can use these credentials to authenticate the following nodes:

先决条件(Prerequisites)#

你必须使用要查询的应用或服务所需的身份验证方法。

🌐 You must use the authentication method required by the app or service you want to query.

如果你需要使用 SSL 证书来确保身份验证,请参阅 提供 SSL 证书 获取所需的信息。

🌐 If you need to secure the authentication with an SSL certificate, refer to Provide an SSL certificate for the information you'll need.

支持的身份验证方法(Supported authentication methods)#

  • 预定义凭证类型
  • 基本身份验证(通用凭证类型)
  • 自定义身份验证(通用凭据类型)
  • 摘要式身份验证(通用凭据类型)
  • 标头身份验证(通用凭据类型)
  • Bearer 身份验证(通用凭证类型)
  • OAuth1(通用凭证类型)
  • OAuth2(通用凭证类型)
  • 查询身份验证(通用凭据类型)

有关通用凭据类型的更多信息,请参阅 HTTP 身份验证

🌐 Refer to HTTP authentication for more information relating to generic credential types.

预定义凭证类型

n8n 建议在有可用的服务凭证类型时,使用预定义的凭证类型。与配置通用凭证相比,这提供了一种更简单的方式来设置和管理凭证。

您可以使用 预定义凭证类型 在 n8n 为该平台提供节点的一些 API 中执行自定义操作。例如,n8n 有一个 Asana 节点,并支持在 HTTP 请求节点中使用您的 Asana 凭证。有关更多信息,请参阅 自定义操作

使用预定义凭据类型(Using predefined credential type)#

To use a predefined credential type:

  1. Open your HTTP Request node, or add a new one to your workflow.
  2. In Authentication, select Predefined Credential Type.
  3. In Credential Type, select the API you want to use.
  4. In Credential for <API name>, you can:
    1. Select an existing credential for that platform, if available.
    2. Select Create New to create a new credential.

有关更多信息,请参阅 自定义 API 操作

🌐 Refer to Custom API operations for more information.

Using basic auth#

Use this generic authentication if your app or service supports basic authentication.

To configure this credential, enter:

  • The Username you use to access the app or service your HTTP Request is targeting
  • The Password that goes with that username

Using digest auth#

Use this generic authentication if your app or service supports digest authentication.

To configure this credential, enter:

  • The Username you use to access the app or service your HTTP Request is targeting
  • The Password that goes with that username

Using header auth#

Use this generic authentication if your app or service supports header authentication.

To configure this credential, enter:

  • The header Name you need to pass to the app or service your HTTP request is targeting
  • The Value for the header

Read more about HTTP headers

Using bearer auth#

Use this generic authentication if your app or service supports bearer authentication. This authentication type is actually just header authentication with the Name set to Authorization and the Value set to Bearer <token>.

To configure this credential, enter:

  • The Bearer Token you need to pass to the app or service your HTTP request is targeting

Read more about bearer authentication.

使用 OAuth1(Using OAuth1)#

如果你的应用或服务支持 OAuth1 身份验证,请使用此通用身份验证。

🌐 Use this generic authentication if your app or service supports OAuth1 authentication.

要配置此凭据,请输入:

🌐 To configure this credential, enter:

  • 一个授权 URL:也称为资源所有者授权 URI。此 URL 通常以 /oauth1/authorize 结尾。临时凭证会发送到此处以提示用户完成授权。
  • 一个访问令牌 URL:这是用于初始请求临时凭证的 URI。该 URL 通常以 /oauth1/request/oauth1/token 结尾。
  • 一个 消费者密钥:也称为客户端密钥,类似于用户名。它指定了用于调用的 oauth_consumer_key
  • 一个 消费者密钥:也称为客户端密钥,类似于密码。
  • 请求令牌 URL:这是在授权后用于将临时凭证切换为长期凭证的 URI。此 URL 通常以 /oauth1/access 结尾。
  • 选择认证握手使用的签名方法。这指定了调用中要使用的 oauth_signature_method。选项包括:
    • HMAC-SHA1
    • HMAC-SHA256
    • HMAC-SHA512

对于大多数 OAuth1 集成,你需要配置一个应用、服务或集成来生成这些字段的大部分值。在 n8n 中使用 OAuth 重定向 URL 作为此类服务的重定向 URL 或重定向 URI。

🌐 For most OAuth1 integrations, you'll need to configure an app, service, or integration to generate the values for most of these fields. Use the OAuth Redirect URL in n8n as the redirect URL or redirect URI for such a service.

阅读更多关于 OAuth1 以及 OAuth1 授权流程 的内容。

🌐 Read more about OAuth1 and the OAuth1 authorization flow.

使用 OAuth2(Using OAuth2)#

如果你的应用或服务支持 OAuth2 身份验证,请使用此通用身份验证。

🌐 Use this generic authentication if your app or service supports OAuth2 authentication.

配置此凭据的要求取决于所选择的 授权类型。有关每种授权类型的更多信息,请参阅 OAuth 授权类型

🌐 Requirements to configure this credential depend on the Grant Type selected. Refer to OAuth Grant Types for more information on each grant type.

对于大多数 OAuth2 集成,你需要配置一个应用、服务或集成。在 n8n 中使用 OAuth 重定向 URL 作为此类服务的重定向 URL 或重定向 URI。

🌐 For most OAuth2 integrations, you'll need to configure an app, service, or integration. Use the OAuth Redirect URL in n8n as the redirect URL or redirect URI for such a service.

查看更多关于 OAuth2 的信息。

🌐 Read more about OAuth2.

授权码授权类型(Authorization Code grant type)#

使用授权码授权类型将授权码兑换为访问令牌。授权流程使用重定向 URL 将用户返回到客户端。然后应用从 URL 中获取授权码,并使用它来请求访问令牌。更多信息请参阅授权码请求

🌐 Use Authorization Code grant type to exchange an authorization code for an access token. The auth flow uses the redirect URL to return the user to the client. Then the application gets the authorization code from the URL and uses it to request an access token. Refer to Authorization Code Request for more information.

要配置此凭证,请将 授权类型 选择为 授权代码

🌐 To configure this credential, select Authorization Code as the Grant Type.

然后输入:

🌐 Then enter:

  • 一个 授权网址
  • 一个 访问令牌 URL
  • A 客户端 ID:用于登录的 ID 或用户名。
  • 客户端密钥:用于登录的密钥或密码。
  • 可选: 输入一个或多个凭证的范围。如果未指定,凭证将请求客户端可用的所有范围。
  • 可选: 一些服务需要更多的查询参数。如果您的服务需要,请将它们添加为 Auth URI 查询参数
  • 一种认证类型:选择最适合你使用场景的选项。选项包括:
    • 标题:将凭证作为基本身份验证头发送。
    • 正文:在请求的正文中发送凭证。
  • 可选: 选择是否 忽略 SSL 问题。如果开启,即使 SSL 验证失败,n8n 也会进行连接。

客户端凭证授权类型(Client Credentials grant type)#

当应用请求访问令牌以访问自己的资源,而不是代表用户访问资源时,请使用客户端凭据授权类型。有关更多信息,请参阅客户端凭据

🌐 Use the Client Credentials grant type when applications request an access token to access their own resources, not on behalf of a user. Refer to Client Credentials for more information.

要配置此凭证,请将 授予类型 选择为 客户端凭证

🌐 To configure this credential, select Client Credentials as the Grant Type.

然后输入:

🌐 Then enter:

  • 访问令牌 URL:用于启动 OAuth2 流程的 URL。通常该 URL 以 /token 结尾。
  • A 客户端 ID:用于登录客户端的 ID 或用户名。
  • 客户端密钥:用于登录客户端的秘密或密码。
  • (可选): 为凭证输入一个或多个作用域。大多数服务不支持客户端凭证授权类型的作用域;只有在您的服务支持时才在此输入作用域。
  • 一种认证类型:选择最适合你使用场景的选项。选项包括:
    • 标题:将凭证作为基本身份验证头发送。
    • 正文:在请求的正文中发送凭证。
  • 可选: 选择是否 忽略 SSL 问题。如果开启,即使 SSL 验证失败,n8n 也会进行连接。

PKCE 授权类型(PKCE grant type)#

代码交换密钥验证 (PKCE) 授权类型是对授权码流程的扩展,用于防止 CSRF 和授权码注入攻击。

🌐 Proof Key for Code Exchange (PKCE) grant type is an extension to the Authorization Code flow to prevent CSRF and authorization code injection attacks.

要配置此凭证,请将 授权类型 选择为 PKCE

🌐 To configure this credential, select PKCE as the Grant Type.

然后输入:

🌐 Then enter:

  • 一个 授权网址
  • 一个 访问令牌 URL
  • A 客户端 ID:用于登录的 ID 或用户名。
  • 客户端密钥:用于登录的密钥或密码。
  • 可选: 输入一个或多个凭证的范围。如果未指定,凭证将请求客户端可用的所有范围。
  • 可选: 一些服务需要更多的查询参数。如果您的服务需要,请将它们添加为 Auth URI 查询参数
  • 一种认证类型:选择最适合你使用场景的选项。选项包括:
    • 标题:将凭证作为基本身份验证头发送。
    • 正文:在请求的正文中发送凭证。
  • 可选: 选择是否 忽略 SSL 问题。如果开启,即使 SSL 验证失败,n8n 也会进行连接。

使用查询身份验证(Using query auth)#

如果你的应用或服务支持以单个键/值查询参数传递身份验证,请使用此通用身份验证。(对于多个查询参数,请使用 自定义身份验证。)

🌐 Use this generic authentication if your app or service supports passing authentication as a single key/value query parameter. (For multiple query parameters, use Custom Auth.)

要配置此凭据,请输入:

🌐 To configure this credential, enter:

  • 查询参数键或名称
  • 查询参数

使用自定义身份验证(Using custom auth)#

如果你的应用或服务支持将身份验证作为多个键/值查询参数传递,或者你需要比其他通用身份验证选项更灵活的方式,请使用此通用身份验证。

🌐 Use this generic authentication if your app or service supports passing authentication as multiple key/value query parameters or you need more flexibility than the other generic auth options.

自定义认证 凭证需要 JSON 数据来定义你的凭证。你可以使用 headersqsbody 或其组合。请查看下面的示例以开始操作。

🌐 The Custom Auth credential expects JSON data to define your credential. You can use headers, qs, body or a mix. Review the examples below to get started.

发送两个标头(Sending two headers)#

1
2
3
4
5
6
{
	"headers": {
		"X-AUTH-USERNAME": "username",
		"X-AUTH-PASSWORD": "password"
	}
}

主体(Body)#

1
2
3
4
5
6
{
	 "body" : {
		"user": "username",
		"pass": "password"
	}
}

查询字符串(Query string)#

1
2
3
4
5
6
{
	"qs": { 
		"appid": "123456",
		"apikey": "my-api-key"
	}
}

发送标头和查询字符串(Sending header and query string)#

1
2
3
4
5
6
7
8
{
	"headers": {
		"api-version": "202404"
	},
	"qs": {
		"apikey": "my-api-key"
	}
}

提供 SSL 证书(Provide an SSL certificate)#

您可以在 HTTP 请求中发送 SSL 证书。请将 SSL 证书作为单独的凭证创建,以供节点使用:

🌐 You can send an SSL certificate with your HTTP request. Create the SSL certificate as a separate credential for use by the node:

  1. 在 HTTP 请求节点的 设置 中,开启 SSL 证书
  2. 参数选项卡中,将现有的 SSL 证书凭据添加到SSL 证书凭据,或创建一个新的凭据。

要配置 SSL 证书凭据,你需要添加:

🌐 To configure your SSL Certificates credential, you'll need to add:

  • 证书授权机构 CA
  • 证书 (CRT):根据颁发你的证书的CA以及他们如何格式化证书,可能也会以公钥的形式出现
  • 私钥(KEY)
  • (可选):如果私钥已加密,请为私钥输入密码短语

如果你的 SSL 证书在单个文件中(例如 .pfx 文件),你需要打开该文件以复制其中的详细信息,然后将其粘贴到相应的字段中:

🌐 If your SSL certificate is in a single file (such as a .pfx file), you'll need to open the file to copy details from it to paste into the appropriate fields:

  • 将公钥/CRT 输入为 证书
  • 在该字段中输入 私钥/KEY