To enhance communication security, Agora uses tokens to authenticate users before they access the Agora service, or joining an RTC channel.
Under the python3
directory:
/src/
contains the source code for generating a token, whereRtcTokenBuilder.py
is used for generating an RTC token, andRtmTokenBuilder.py
is used for generating an RTM token./sample/
contains the sample code for generating a token, whereRtcTokenBuilderSample.py
is used for generating an RTC token, andRtmTokenBuilderSample.py
is used for generating an RTM token.
This section takes RtcTokenBuilderSample.py
as an example to show how to generate a token with the sample code.
Before proceeding, ensure that you have Python 3 as the development environment. Use the following command to check your current Python version:
Python -V
-
Download or clone the Tools repository.
-
Open the
DynamicKey/AgoraDynamicKey/python/sample/RtcTokenBuilderSample.py
file, replace the value ofappID
,appCertificate
,channelName
, anduid
with your own, and comment out the code snippets ofbuildTokenWithUserAccount
. -
Open your Terminal, navigate to the same directory that holds
RtcTokenBuilderSample.py
, and run the following command. The token is generated and printed in your Terminal window:python RtcTokenBuilderSample.py
For a complete authentication flow between the app server and app client, see Authenticate Your Users with Tokens.