Skip to main content

Deploy a middleware server

To streamline the use of token authentication and RESTful APIs within your infrastructure, Agora’s developer community offers the open-source Agora Go Backend Middleware. The backend provides RESTful APIs for tasks such as token generation, cloud recording management, and real-time transcription. This guide shows you how to implement a token server using the community middleware.

Understand the tech​

The following figure illustrates the architecture of the middleware token generation micro service.

Set up and run the Go backend middleware​

Take the following steps to set up and run the middleware project:

  1. Clone the repository


    _1
    git clone https://github.com/AgoraIO-Community/agora-go-backend-middleware.git

  2. Install dependencies
    Ensure you have Go installed on your system. Navigate to the project directory and install the project dependencies:


    _2
    cd agora-go-backend-middleware
    _2
    go mod download

  3. Configure environment variables

    1. Copy the example .env file.


      _1
      cp .env.example .env

    2. Update the following variables in the .env file:

      • APP_ID: Your Agora App ID.
      • APP_CERTIFICATE: Your Agora App Certificate.
  4. Run the middleware:

    Start the middleware server using the following command:


    _1
    go run cmd/main.go

    The middleware runs on the default port, for example localhost:8080.

Generate tokens​

Refer to the following curl example to test the middleware's token generation API endpoint.

info

The command-line examples in this guide are for demonstration purposes only. Do not use them directly in a production environment. Implement RESTful API requests through your application server.

POST: /token/getNew


_9
curl -X POST http://localhost:8080/token/getNew \
_9
-H "Content-Type: application/json" \
_9
-d '{
_9
"tokenType": "rtc",
_9
"channel": "testChannel",
_9
"role": "publisher",
_9
"uid": "12345",
_9
"expire": 3600
_9
}'

info

Replace localhost:8080 with your server's address.

Reference​

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

Middleware token generation API​

This section provides details about the middleware token generation API endpoints.

Generate Token​

Generates a Video SDK, Signaling, or Chat token based on the provided parameters.

Endpoint​

POST /token/getNew

Request Body​


_7
{
_7
"tokenType": "rtc|rtm|chat",
_7
"channel": "string",
_7
"uid": "string",
_7
"role": "publisher|subscriber",
_7
"expire": int
_7
}

Response​


_3
{
_3
"token": "string"
_3
}