agora-token-test
v2.0.0
Published
To enhance communication security, Agora uses tokens to authenticate users before they access the Agora service, or joining an RTC channel.
Downloads
2
Readme
Authenticate Users with a token
To enhance communication security, Agora uses tokens to authenticate users before they access the Agora service, or joining an RTC channel.
Code structure
Under the nodejs
directory:
/src/
contains the source code for generating a token, whereRtcTokenBuilder.js
is used for generating an RTC token, andRtmTokenBuilder.js
is used for generating an RTM token./sample/
contains the sample code for generating a token, whereRtcTokenBuilderSample.js
is used for generating an RTC token, andRtmTokenBuilderSample.js
is used for generating an RTM token.
Generate a token with the sample code
This section takes RtcTokenBuilderSample.js
as an example to show how to generate a token with the sample code.
Before proceeding, ensure that you have installed the LTS version of Node.js.
Run the following command to install the Node.js dependencies:
npm install
Download or clone the Tools repository.
Open the
DynamicKey/AgoraDynamicKey/nodejs/sample/RtcTokenBuilderSample.js
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.js
, and run the following command. The token is generated and printed in your Terminal window.node RtcTokenBuilderSample.js
Reference
For a complete authentication flow between the app server and app client, see Authenticate Your Users with Tokens.