我如何使用javascript(请没有nodejs)为sinch生成身份验证票我正在使用解析进行用户身份验证,然后我想将该会话传递给sinch
将这些加密库添加到您的 html 文件中
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-utf16-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
var userTicket = {
'identity': {'type': 'username', 'endpoint': user._serverData.username},
'expiresIn': 3600,
'applicationKey': sinchClient.applicationKey,
'created': new Date().toISOString()
}
var userTicketJson = JSON.stringify(userTicket).trim();
var userTicketBase64 = btoa(userTicketJson);
// TicketSignature = Base64 ( HMAC-SHA256 ( ApplicationSecret, UTF8 ( UserTicketJson ) ) )
var digest = CryptoJS.HmacSHA256(appSecret,userTicketJson);
var signature = CryptoJS.enc.Base64.stringify(digest);
// UserTicket = TicketData + ":" + TicketSignature
var signedUserTicket = userTicketBase64.replace('=','') + ':' + signature.replace('=','');
sinchClient.start({'userTicket':signedUserTicket})
.then(function(data) {
console.log(data)
})
.fail(function(error) {
console.log(error)
});