Search code examples
phpnode.jsagora.io

How do i generate the agora Chat App Temp Token when it expires after 24Hours


The documentation does not mention how to regenerate it. I have tried building a simple token server but the tokens it generates are not working. Link to token server: https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs

enter image description here


Solution

  • Nodejs Sample Code

    Nodejs sample Code to build appToken and userToken for AgoraChat below

    const ChatTokenBuilder = require("../src/ChatTokenBuilder").ChatTokenBuilder;
    const appId = "970CA35de60c44645bbae8a215061b33";
    const appCertificate = "5CFd2fd1755d40ecb72977518be15d3b";
    const userUuid = "a7180cb0-1d4a-11ed-9210-89ff47c9da5e";
    const expirationInSeconds = 600;
    
    const userToken = ChatTokenBuilder.buildUserToken(appId, appCertificate, userUuid, expirationInSeconds);
    console.log("Chat User Token: " + userToken + "\n");
    
    const appToken = ChatTokenBuilder.buildAppToken(appId, appCertificate, expirationInSeconds)
    console.log("Chat App Token: " + appToken);
    

    Link to sample code https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/nodejs/sample/ChatTokenBuilderSample.js

    Similar post here https://stackoverflow.com/a/75694520/21047572

    Hope this helps