tencent cloud

TDMQ for MQTT

Related Agreement
Política de privacidade
Contrato de Privacidade e Seguranca de dados
DocumentaçãoTDMQ for MQTT

Authenticating with an External HTTP Service

Modo Foco
Tamanho da Fonte
Última atualização: 2026-04-01 16:30:54

Overview

TDMQ for MQTT supports client authentication and simple authorization by integrating with third-party HTTP services. When a client initiates a connection (sending a CONNECT packet), MQTT constructs an HTTP request with the client's credentials (such as username and password). When the request reaches the designated HTTP authentication service, MQTT determines authentication success based on the HTTP response. If authentication succeeds, the client is allowed to connect to the server; if authentication fails, the connection is refused.

Authentication Principle

When an MQTT client connects to MQTT, MQTT, as the request client, must construct and send a request to the HTTP service in the required API format. The HTTP service must return results in the required format. The HTTP response status code is used to determine whether the authentication request succeeds. The HTTP authentication service must meet the following conditions:
The HTTP response Content-Type must be application / json.
The authentication result is indicated by result in the body. Valid values: allow, deny, or ignore.
Whether the client is a superuser is indicated by is_superuser in the body. Valid values: true or false.
The response must return HTTP Status Code 200 or 204.
Other response codes, such as 4xxand 5xx, are treated as HTTP authentication request failures. In this case, the authentication result uses the default value ignore, and execution continues along the authentication chain. If the current HTTP authenticator is the last one in the chain, authentication fails, and the client connection is refused.
Response Example:
HTTP/1.1 200 OK
Headers: Content-Type: application/json
...
Body:
{
"result": "allow", // "allow" | "deny" | "ignore"
"client_attrs": {
"role": "admin",
"sn": "10c61f1a1f47"
}
"expire_at": 1654254601, // Optional. Indicates the expiration time of the current authentication policy
"acl": // Optional. Used for the existing HTTP authentication service to support simple authorization. The authorization policy is cached on the MQTT server and updated when triggered again
[
{
"effect": "allow",
"action": ["publish","subscribe","connect"],
"topic": "topic/AA/#",
"qos": [1]
},
{
"effect": "deny",
"action": ["publish","connect"],
"topic": "topic/BB"
}
]
}

Operation Steps

1. Log in to the MQTT Console.
2. In the left sidebar, choose Resource Management > Cluster Management. Select a region, click the target cluster ID, and enter the Cluster Basic Information page.
3. On the Cluster Basic Information page, select the Authentication Management tab, choose External HTTP Authentication as the secondary tab, and click Create Authentication.
Request Method: Select the HTTP request method. Options: POST, GET.
Service Address: Enter the HTTP(S) service URL.
Headers: HTTP request header configuration. You can add multiple headers. When entering the value, you can use constants and template variables. The format is "${variable name}". Typing "${" triggers suggestions.
Body: Request template. When entering the value, you can use constants and template variables. The format is "${variable name}". Typing "${" triggers suggestions.
Maximum Request Concurrency: Sets the maximum number of concurrent requests. Value range: 1-10.
Connection Timeout: Sets the connection timeout duration. Value range: 1-30 seconds.
Request Timeout: Sets the request timeout duration. Value range: 1-30 seconds.
Description: Optional. Enter as needed. The description cannot exceed 128 characters.

4. Click Confirm to complete the creation. After creation, click

in the upper right to test the authentication configuration.

Template Variables

Client Variable Field

Variable
Description
InstanceID
MQTT instance ID
ClientId
MQTT Client ID
Username
MQTT client connection username
Password
MQTT client connection password
Clientip
MQTT client IP address
Certificate.Pem
PEM content of the client certificate
Certificate.ChainSn
Serial number of the certificate chain

Certificate Subject Field

Variable
Description
Certificate.Subject.Organization
Subject - Organization name
Certificate.Subject.OrganizationalUnit
Subject - Organizational unit
Certificate.Subject.State
Subject - State/Province
Certificate.Subject.CommonName
Subject - Common name
Certificate.Subject.SerialNumber
Subject - Serial number
Certificate.Subject.Title
Subject - Title
Certificate.Subject.Surname
Subject - Surname
Certificate.Subject.GivenName
Subject - Given name
Certificate.Subject.Initials
Subject - Initials
Certificate.Subject.Pseudonym
Subject - Pseudonym
Certificate.Subject.GenerationQualifier
Subject - Generation qualifier
Certificate.Subject.DistinguishedNameQualifier
Subject - Distinguished name qualifier
Certificate.Subject.Country
Subject - Country/Region code

Certificate Issuer Field

Variable
Description
Certificate.Issuer.Organization
Issuer - Organization name
Certificate.Issuer.OrganizationalUnit
Issuer - Organizational unit
Certificate.Issuer.State
Issuer - State/Province
Certificate.Issuer.CommonName
Issuer - Common name
Certificate.Issuer.SerialNumber
Issuer - Serial number
Certificate.Issuer.Title
Issuer - Title
Certificate.Issuer.Surname
Issuer - Surname
Certificate.Issuer.GivenName
Issuer - Given name
Certificate.Issuer.Initials
Issuer - Initials
Certificate.Issuer.Pseudonym
Issuer - Pseudonym
Certificate.Issuer.GenerationQualifier
Issuer - Generation qualifier
Certificate.Issuer.DistinguishedNameQualifier
Issuer - Distinguished name qualifier
Certificate.Issuer.Country
Issuer - Country/Region code

Alternate Name Field

Variable
Description
Certificate.Subject.AlternativeName.RFC822Name
Subject alternative name - Email address
Certificate.Subject.AlternativeName.DNSName
Subject alternative name - DNS domain name
Certificate.Subject.AlternativeName.DirectoryName
Subject alternative name - Directory name
Certificate.Subject.AlternativeName.UniformResourceIdentifier
Subject alternative name - Uniform resource identifier
Certificate.Subject.AlternativeName.IPAddress
Subject alternative name - IP address
Certificate.Issuer.AlternativeName.RFC822Name
Issuer alternative name - Email address
Certificate.Issuer.AlternativeName.DNSName
Issuer alternative name - DNS domain name
Certificate.Issuer.AlternativeName.DirectoryName
Issuer alternative name - Directory name
Certificate.Issuer.AlternativeName.UniformResourceIdentifier
Issuer alternative name - Uniform resource identifier
Certificate.Issuer.AlternativeName.IPAddress
Issuer alternative name - IP address


Ajuda e Suporte

Esta página foi útil?

comentários