Deploy a middleware server
Updated
Set up and run the Agora community middleware to generate authentication tokens for Video Calling.
To streamline token authentication and REST API workflows in 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 for Video Calling.
Understand the tech
The following figure illustrates the architecture of the middleware token generation microservice.
Set up and run the Go backend middleware
Take the following steps to set up and run the middleware project:
-
Clone the repository
git clone https://github.com/AgoraIO-Community/agora-go-backend-middleware.git -
Install dependencies
Ensure you have Go installed on your system. Navigate to the project directory and install the project dependencies:
cd agora-go-backend-middleware
go mod download-
Configure environment variables
Copy the example
.envfile.cp .env.example .envUpdate the following variables in the
.envfile:APP_ID: Your Agora App ID.APP_CERTIFICATE: Your Agora App Certificate.
-
Run the middleware
Start the middleware server using the following command:
go run cmd/main.goThe 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.
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
curl -X POST http://localhost:8080/token/getNew \
-H "Content-Type: application/json" \
-d '{
"tokenType": "rtc",
"channel": "testChannel",
"role": "publisher",
"uid": "12345",
"expire": 3600
}'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
{
"tokenType": "rtc|rtm|chat",
"channel": "string",
"uid": "string",
"role": "publisher|subscriber",
"expire": 0
}Response
{
"token": "string"
}