Skip to content

HTTP 请求凭据#

¥HTTP Request credentials

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

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

¥HTTP Request

¥HTTP Request Tool (legacy)

先决条件#

¥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

  • 预定义凭证类型

¥Predefined credential type

  • 基本身份验证(通用凭证类型)

¥Basic auth (generic credential type)

  • 自定义身份验证(通用凭据类型)

¥Custom auth (generic credential type)

  • 摘要式身份验证(通用凭据类型)

¥Digest auth (generic credential type)

  • 标头身份验证(通用凭据类型)

¥Header auth (generic credential type)

  • Bearer 身份验证(通用凭证类型)

¥Bearer auth (generic credential type)

  • OAuth1(通用凭证类型)

¥OAuth1 (generic credential type)

  • OAuth2(通用凭证类型)

¥OAuth2 (generic credential type)

  • 查询身份验证(通用凭据类型)

¥Query auth (generic credential type)

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

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

Predefined credential types

n8n 建议在要连接的服务有可用凭据类型时,使用预定义的凭据类型。与配置通用凭据相比,它提供了一种更简便的凭据设置和管理方式。

¥n8n recommends using predefined credential types whenever there's a credential type available for the service you want to connect to. It offers an easier way to set up and manage credentials, compared to configuring generic credentials.

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

¥You can use Predefined credential types to perform custom operations with some APIs where n8n has a node for the platform. For example, n8n has an Asana node, and supports using your Asana credentials in the HTTP Request node. Refer to Custom operations for more information.

使用预定义凭据类型#

¥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 结尾。临时凭据将发送到此处,以提示用户完成授权。

¥An Authorization URL: Also known as the Resource Owner Authorization URI. This URL typically ends in /oauth1/authorize. The temporary credentials are sent here to prompt a user to complete authorization.

  • 访问令牌 URL:这是用于初始请求临时凭据的 URI。此 URL 通常以 /oauth1/request/oauth1/token 结尾。

¥An Access Token URL: This is the URI used for the initial request for temporary credentials. This URL typically ends in /oauth1/request or /oauth1/token.

  • 消费者密钥:也称为客户端密钥,类似于用户名。此步骤指定调用要使用的 oauth_consumer_key 值。

¥A Consumer Key: Also known as the client key, like a username. This specifies the oauth_consumer_key to use for the call.

  • 消费者密钥:也称为客户端密钥,类似于密码。

¥A Consumer Secret: Also known as the client secret, like a password.

  • 请求令牌 URL:这是授权后用于从临时凭据切换到长期凭据的 URI。此 URL 通常以 /oauth1/access 结尾。

¥A Request Token URL: This is the URI used to switch from temporary credentials to long-lived credentials after authorization. This URL typically ends in /oauth1/access.

  • 选择身份验证握手使用的签名方法。此步骤指定调用要使用的 oauth_signature_method 值。选项包括:

¥Select the Signature Method the auth handshake uses. This specifies the oauth_signature_method to use for the call. Options include:

  • 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.

阅读更多关于 OAuth1OAuth1 授权流程 的信息。

¥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

¥An Authorization URL

  • 访问令牌 URL

¥An Access Token URL

  • 客户端 ID:用于登录的 ID 或用户名。

¥A Client ID: The ID or username to log in with.

  • 客户端密钥:用于登录的密钥或密码。

¥A Client Secret: The secret or password used to log in with.

  • 可选的:为凭证输入一个或多个作用域。如果未指定,凭证将请求客户端可用的所有范围。

¥Optional: Enter one or more Scopes for the credential. If unspecified, the credential will request all scopes available to the client.

  • 可选的:某些服务需要更多查询参数。如果你的服务需要,请将其添加为身份验证 URI 查询参数。

¥Optional: Some services require more query parameters. If your service does, add them as Auth URI Query Parameters.

  • 身份验证类型:选择最适合你用例的选项。选项包括:

¥An Authentication type: Select the option that best suits your use case. Options include:

  • 标头:将凭据作为基本身份验证标头发送。

    ¥Header: Send the credentials as a basic auth header.

  • 正文:在请求正文中发送凭据。

    ¥Body: Send the credentials in the body of the request.

  • 可选的:选择是否忽略 SSL 问题。如果启用,即使 SSL 验证失败,n8n 也会连接。

¥Optional: Choose whether to Ignore SSL Issues. If turned on, n8n will connect even if SSL validation fails.

客户端凭证授权类型#

¥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 结尾。

¥An Access Token URL: The URL to hit to begin the OAuth2 flow. Typically this URL ends in /token.

  • 客户端 ID:用于登录客户端的 ID 或用户名。

¥A Client ID: The ID or username to use to log in to the client.

  • 客户端密钥:用于登录客户端的密钥或密码。

¥A Client Secret: The secret or password used to log in to the client.

  • 可选的:为凭证输入一个或多个作用域。大多数服务不支持客户端凭据授权类型的作用域;仅当你的组件支持时才在此处输入范围。

¥Optional: Enter one or more Scopes for the credential. Most services don't support scopes for Client Credentials grant types; only enter scopes here if yours does.

  • 身份验证类型:选择最适合你用例的选项。选项包括:

¥An Authentication type: Select the option that best suits your use case. Options include:

  • 标头:将凭据作为基本身份验证标头发送。

    ¥Header: Send the credentials as a basic auth header.

  • 正文:在请求正文中发送凭据。

    ¥Body: Send the credentials in the body of the request.

  • 可选的:选择是否忽略 SSL 问题。如果启用,即使 SSL 验证失败,n8n 也会连接。

¥Optional: Choose whether to Ignore SSL Issues. If turned on, n8n will connect even if SSL validation fails.

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

¥An Authorization URL

  • 访问令牌 URL

¥An Access Token URL

  • 客户端 ID:用于登录的 ID 或用户名。

¥A Client ID: The ID or username to log in with.

  • 客户端密钥:用于登录的密钥或密码。

¥A Client Secret: The secret or password used to log in with.

  • 可选的:为凭证输入一个或多个作用域。如果未指定,凭证将请求客户端可用的所有范围。

¥Optional: Enter one or more Scopes for the credential. If unspecified, the credential will request all scopes available to the client.

  • 可选的:某些服务需要更多查询参数。如果你的服务需要,请将其添加为身份验证 URI 查询参数。

¥Optional: Some services require more query parameters. If your service does, add them as Auth URI Query Parameters.

  • 身份验证类型:选择最适合你用例的选项。选项包括:

¥An Authentication type: Select the option that best suits your use case. Options include:

  • 标头:将凭据作为基本身份验证标头发送。

    ¥Header: Send the credentials as a basic auth header.

  • 正文:在请求正文中发送凭据。

    ¥Body: Send the credentials in the body of the request.

  • 可选的:选择是否忽略 SSL 问题。如果启用,即使 SSL 验证失败,n8n 也会连接。

¥Optional: Choose whether to Ignore SSL Issues. If turned on, n8n will connect even if SSL validation fails.

使用查询身份验证#

¥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:

  • 查询参数键或名称。

¥A query parameter key or Name

  • 查询参数值

¥A query parameter Value

使用自定义身份验证#

¥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

你可以将 SSL 证书随 HTTP 请求一起发送。创建 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 证书”。

¥In the HTTP Request node Settings, turn on SSL Certificates. 2. 在“参数”选项卡中,将现有的 SSL 证书凭据添加到“SSL 证书凭据”中,或创建一个新的凭据。

¥On the Parameters tab, add an existing SSL Certificate credential to Credential for SSL Certificates or create a new one.

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

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

  • 证书颁发机构 (CA) 包

¥The Certificate Authority CA bundle

  • 证书 (CRT):也可能显示为公钥,具体取决于你的颁发 CA 及其证书格式。

¥The Certificate (CRT): May also appear as a Public Key, depending on who your issuing CA was and how they format the cert

  • 私钥 (KEY)

¥The Private Key (KEY)

  • 可选的:如果私钥已加密,请输入私钥的密码。

¥Optional: If the Private Key is encrypted, enter a Passphrase for the private 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:

  • 输入公钥/证书。

¥Enter the Public Key/CRT as the Certificate

  • 在该字段中输入私钥/密钥

¥Enter the Private Key/KEY in that field