tencent cloud

Feedback

JWT Authentication Configuration

Last updated: 2024-06-28 11:31:37

    Overview

    TDMQ for Apache Pulsar provides the same JWT authentication method used by native Pulsar, which allows you to access TDMQ for Apache Pulsar resources by configuring the token in the client parameters. For directions on how to configure the relationships between different role tokens and TDMQ for Apache Pulsar resources in the console, see Roles and Permissions.
    This document describes how to configure JWT authentication in a TDMQ for Apache Pulsar client, so that you can securely use the client to produce and consume messages. You can also add a token when creating a client.

    Authentication Configuration

    Java client

    Configure JWT authentication in a Java client:
    Access sample for cluster on v2.7.1 or above
    Access sample for cluster on v2.6.1
    PulsarClient client = PulsarClient.builder()
    // Access address, which can be copied from **Access Address** in the **Operation** column on the **Cluster Management** page
    .serviceUrl("http://*")
    // Replace it with the role token displayed on the **Role Management** page
    .authentication(AuthenticationFactory.token("eyJh****"))
    .build();
    PulsarClient client = PulsarClient.builder()
    // Access address, which can be copied from the access point list in **Cluster Management**
    .serviceUrl("pulsar://*.*.*.*:6000/")
    // Replace it with the role token displayed on the **Role Management** page
    .authentication(AuthenticationFactory.token("eyJh****"))
    // Replace the value of `custom:` with the route ID in the access point list in **Cluster Management**
    .listenerName("custom:1********0/vpc-******/subnet-********")
    .build();

    Go client

    Configure JWT authentication in a Go client:
    Access sample for cluster on v2.7.1 or above
    Access sample for cluster on v2.6.1
    client, err := NewClient(ClientOptions{
    // Access address, which can be copied from the access point list in **Cluster Management**
    URL: "http://*",
    // Replace it with the role token displayed on the **Role Management** page
    Authentication: NewAuthenticationToken("eyJh****"),
    })
    client, err := NewClient(ClientOptions{
    // Access address, which can be copied from the access point list in **Cluster Management**
    URL: "pulsar://*.*.*.*:6000",
    // Replace it with the role token displayed on the **Role Management** page
    Authentication: NewAuthenticationToken("eyJh****"),
    // Replace the value of `custom:` with the route ID in the access point list in **Cluster Management**
    ListenerName: "custom:1300*****0/vpc-******/subnet-********",
    })
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support