Written in Golang, using Gin framework to create a RESTful webservice for generating user tokens for use with the Agora.io platform.
Agora Advanced Guide: Token Management.
Set the APP_ID and APP_CERTIFICATE env variables.
cp .env.example .env
go run cmd/main.go
Without using .env
, you can also set the environment variables as such:
APP_ID=app_id APP_CERTIFICATE=app_cert go run cmd/main.go
The pre-compiled binaries are also available in releases.
#1. To build the container, with app id and certificate:
docker build -t agora-token-service --build-arg APP_ID=$APP_ID APP_CERTIFICATE=$APP_CERTIFICATE .
#2. Run the container
docker run agora-token-service
Note: for testing locally
docker run -p 8080:8080 agora-token-service
endpoint structure
/ping
response:
{"message":"pong"}
The rtc
token endpoint requires a tokenType
(uid || userAccount), channelName
, and the user's uid
(type varies based on tokenType
).
expiry(optional)
Pass an integer to represent the token lifetime in seconds.
endpoint structure
/rtc/:channelName/:role/:tokenType/:rtcuid/?expiry=3600
response:
{"rtcToken":" "}
The rtm
token endpoint requires the user's rtmuid
.
expiry(optional)
Pass an integer to represent the privelege lifetime in seconds.
endpoint structure
/rtm/:rtmuid/?expiry=3600
response:
{"rtmToken":" "}
The rte
token endpoint generates both the rtc
and rtm
tokens with a single request. This endpoint requires a tokenType
(uid || userAccount), channelName
, the user's rtcuid
(type varies String/Int
based on tokenType
) and rtmuid
which is a String
. Omitting rtmuid
will assume it's the same as rtcuid
.
expiry(optional)
Pass an integer to represent the token lifetime in seconds.
endpoint structure
/rte/:channelName/:role/:tokenType/:rtcuid/:rtmuid/?expiry=3600
response:
{
"rtcToken":"rtc-token-djfkaljdla",
"rtmToken":"rtm-token-djfkaljdla"
}