Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

agora-access-token

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agora-access-token - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

sample/README.md

10

index.js

@@ -1,6 +0,6 @@

const AccessToken = require('./src/AccessToken')
module.exports.AccessToken = {
Token: AccessToken.AccessToken,
Priviledges: AccessToken.priviledges
module.exports = {
RtcTokenBuilder: require('./src/RtcTokenBuilder').RtcTokenBuilder,
RtcRole: require('./src/RtcTokenBuilder').Role,
RtmTokenBuilder: require('./src/RtmTokenBuilder').RtmTokenBuilder,
RtmRole: require('./src/RtmTokenBuilder').Role
}
{
"name": "agora-access-token",
"version": "1.0.2",
"version": "2.0.0",
"description": "",
"homepage": "https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {

@@ -16,5 +13,5 @@ "test": "echo \"Error: no test specified\" && exit 1"

"dependencies": {
"crc-32": "^1.2.0",
"cuint": "^0.2.2"
"crc-32": "1.2.0",
"cuint": "0.2.2"
}
}

@@ -10,4 +10,3 @@ # How to use

```javascript
const {AccessToken} = require('./index')
const {Token, Priviledges} = AccessToken
const {RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole} = require('./index')
```

@@ -17,14 +16,25 @@

```javascript
var appID = "<Your app ID>";
var appCertificate = "<Your app certificate>";
var channel = "<The channel this token is generated for>";
var uid = <The uid this token is generated for>;
// Rtc Examples
const appID = '<Your app ID>';
const appCertificate = '<Your app certificate>';
const channelName = '<The channel this token is generated for>';
const uid = 2882341273;
const account = "2882341273";
const role = RtcRole.PUBLISHER;
// expire timestamp, 0 indicates never expire - note a key is valid for 24 hours maximum
var expireTimestamp = 0;
const expirationTimeInSeconds = 3600
var key = new Token(appID, appCertificate, channel, uid);
key.addPriviledge(Priviledges.kJoinChannel, expireTimestamp);
const currentTimestamp = Math.floor(Date.now() / 1000)
var token = key.build();
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds
// IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.
// Build token with uid
const tokenA = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs);
console.log("Token With Integer Number Uid: " + tokenA);
// Build token with user account
const tokenB = RtcTokenBuilder.buildTokenWithAccount(appID, appCertificate, channelName, account, role, privilegeExpiredTs);
console.log("Token With UserAccount: " + tokenB);
```

@@ -1,14 +0,46 @@

const {AccessToken} = require('./index')
const {Token, Priviledges} = AccessToken
const {RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole} = require('./index')
var appID = "970CA35de60c44645bbae8a215061b33";
var appCertificate = "5CFd2fd1755d40ecb72977518be15d3b";
var channel = "7d72365eb983485397e3e3f9d460bdda";
var uid = 2882341273;
var expireTimestamp = 0;
const generateRtcToken = () => {
// Rtc Examples
const appID = '970CA35de60c44645bbae8a215061b33';
const appCertificate = '5CFd2fd1755d40ecb72977518be15d3b';
const channelName = '7d72365eb983485397e3e3f9d460bdda';
const uid = 2882341273;
const account = "2882341273";
const role = RtcRole.PUBLISHER;
var key = new Token(appID, appCertificate, channel, uid);
key.addPriviledge(Priviledges.kJoinChannel, expireTimestamp);
const expirationTimeInSeconds = 3600
var token = key.build();
console.log(token);
const currentTimestamp = Math.floor(Date.now() / 1000)
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds
// IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.
// Build token with uid
const tokenA = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs);
console.log("Token With Integer Number Uid: " + tokenA);
// Build token with user account
const tokenB = RtcTokenBuilder.buildTokenWithAccount(appID, appCertificate, channelName, account, role, privilegeExpiredTs);
console.log("Token With UserAccount: " + tokenB);
}
const generateRtmToken = () => {
// Rtm Examples
const appID = "970CA35de60c44645bbae8a215061b33";
const appCertificate = "5CFd2fd1755d40ecb72977518be15d3b";
const account = "test_user_id";
const expirationTimeInSeconds = 3600
const currentTimestamp = Math.floor(Date.now() / 1000)
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds
const token = RtmTokenBuilder.buildToken(appID, appCertificate, account, RtmRole, privilegeExpiredTs);
console.log("Rtm Token: " + token);
}
generateRtcToken()
generateRtmToken()

@@ -76,3 +76,3 @@ var crypto = require('crypto');

var hexDecode = function(str) {
return new Buffer(str, 'hex');
return Buffer.from(str, 'hex');
};

@@ -82,3 +82,3 @@

var that = {
buffer: new Buffer(1024),
buffer: Buffer.alloc(1024),
position: 0

@@ -90,3 +90,3 @@ };

that.pack = function() {
var out = new Buffer(that.position);
var out = Buffer.alloc(that.position);
that.buffer.copy(out, 0, 0, out.length);

@@ -116,3 +116,3 @@ return out;

that.putString = function(str) {
return that.putBytes(new Buffer(str));
return that.putBytes(Buffer.from(str));
};

@@ -119,0 +119,0 @@

@@ -97,3 +97,4 @@ var crypto = require('crypto');

kInvitePublishDataStream: 12,
kAdministrateChannel: 101
kAdministrateChannel: 101,
kRtmLogin: 1000
};

@@ -107,3 +108,3 @@

var that = {
buffer: new Buffer(1024)
buffer: Buffer.alloc(1024)
, position: 0

@@ -115,3 +116,3 @@ };

that.pack = function () {
var out = new Buffer(that.position);
var out = Buffer.alloc(that.position);
that.buffer.copy(out, 0, 0, out.length);

@@ -141,3 +142,3 @@ return out;

that.putString = function (str) {
return that.putBytes(new Buffer(str));
return that.putBytes(Buffer.from(str));
};

@@ -200,3 +201,3 @@

var out = new Buffer(len);
var out = Buffer.alloc(len);
that.buffer.copy(out, 0, that.position, (that.position + len));

@@ -203,0 +204,0 @@ that.position += len;

@@ -75,3 +75,3 @@ var crypto = require('crypto');

var hexDecode = function(str) {
return new Buffer(str, 'hex');
return Buffer.from(str, 'hex');
};

@@ -81,3 +81,3 @@

var that = {
buffer: new Buffer(1024)
buffer: Buffer.alloc(1024)
, position: 0

@@ -89,3 +89,3 @@ };

that.pack = function() {
var out = new Buffer(that.position);
var out = Buffer.alloc(that.position);
that.buffer.copy(out, 0, 0, out.length);

@@ -115,3 +115,3 @@ return out;

that.putString = function(str) {
return that.putBytes(new Buffer(str));
return that.putBytes(Buffer.from(str));
};

@@ -118,0 +118,0 @@

@@ -6,5 +6,3 @@ /**

*/
var AccessToken = require('../src/AccessToken');
var SimpleTokenBuilder = require('../src/SimpleTokenBuilder');
var Role = require('../src/SimpleTokenBuilder').Role;
var AccessToken = require('../src/AccessToken').AccessToken;
var Priviledges = require('../src/AccessToken').priviledges;

@@ -48,14 +46,35 @@

exports.SimpleTokenBuilder_Test = function (test) {
var expected = "006970CA35de60c44645bbae8a215061b33IACV0fZUBw+72cVoL9eyGGh3Q6Poi8bgjwVLnyKSJyOXR7dIfRBXoFHlEAABAAAAR/QQAAEAAQCvKDdW";
const RtcRole = require("../src/RtcTokenBuilder").Role;
var builder = new SimpleTokenBuilder.SimpleTokenBuilder(appID, appCertificate, channel, uid);
builder.key.salt = salt;
builder.key.ts = ts;
builder.key.messages[Priviledges.kJoinChannel] = expireTimestamp;
exports.RtcTokenBuilder_Test = function (test) {
const appID = '970CA35de60c44645bbae8a215061b33';
const certificate = '5CFd2fd1755d40ecb72977518be15d3b';
const expected = "006970CA35de60c44645bbae8a215061b33IACMv3I+fsRSejxy6luEwzA/1t/zbEHWfJCJ5m8ssFP/fLdIfRBXoFHlIgABAAAAR/QQAAQAAQCvKDdWAgCvKDdWAwCvKDdWBACvKDdW";
var actual = builder.buildToken();
const channelName = "7d72365eb983485397e3e3f9d460bdda";
const uid = 2882341273;
const salt = 1;
const ts = 1111111;
const privilegeExpiredsTs = 1446455471;
const role = RtcRole.PUBLISHER;
const key = new AccessToken(appID, certificate, channelName, uid);
key.addPriviledge(Priviledges.kJoinChannel, privilegeExpiredsTs);
key.salt = salt;
key.ts = ts;
if (role == RtcRole.PUBLISHER ||
role == RtcRole.SUBSCRIBER ||
role == RtcRole.ADMIN) {
key.addPriviledge(Priviledges.kPublishAudioStream, privilegeExpiredsTs)
key.addPriviledge(Priviledges.kPublishVideoStream, privilegeExpiredsTs)
key.addPriviledge(Priviledges.kPublishDataStream, privilegeExpiredsTs)
}
const actual = key.build();
test.equal(expected, actual);
test.done();
};
}

@@ -6,5 +6,2 @@ /**

*/
var DynamicKey = require('../src/DynamicKey');
var DynamicKey3 = require('../src/DynamicKey3');
var DynamicKey4 = require('../src/DynamicKey4');
var DynamicKey5 = require('../src/DynamicKey5');

@@ -21,38 +18,2 @@

exports.DynamicKey_Test = function (test) {
var expected = "870588aad271ff47094eb622617e89d6b5b5a615970ca35de60c44645bbae8a215061b3314464554720383bbf5";
var actual = DynamicKey.generate(appID, appCertificate, channel, ts, r);
test.equal(expected, actual);
test.done();
};
exports.DynamicKey3_Test = function (test) {
var expected = "0037666966591a93ee5a3f712e22633f31f0cbc8f13970ca35de60c44645bbae8a215061b3314464554720383bbf528823412731446455471";
var actual = DynamicKey3.generate(appID, appCertificate, channel, ts, r, uid, expiredTs);
test.equal(expected, actual);
test.done();
};
exports.PublicSharingKey4_Test = function (test) {
var expected = "004ec32c0d528e58ef90e8ff437a9706124137dc795970ca35de60c44645bbae8a215061b3314464554720383bbf51446455471";
var actual = DynamicKey4.generatePublicSharingKey(appID, appCertificate, channel, ts, r, uid, expiredTs);
test.equal(expected, actual);
test.done();
};
exports.RecordingKey4_Test = function (test) {
var expected = "004e0c24ac56aae05229a6d9389860a1a0e25e56da8970ca35de60c44645bbae8a215061b3314464554720383bbf51446455471";
var actual = DynamicKey4.generateRecordingKey(appID, appCertificate, channel, ts, r, uid, expiredTs);
test.equal(expected, actual);
test.done();
};
exports.MediaChannelKey4_Test = function (test) {
console.log("MediaChannelKey4_Test");
var expected = "004d0ec5ee3179c964fe7c0485c045541de6bff332b970ca35de60c44645bbae8a215061b3314464554720383bbf51446455471";
var actual = DynamicKey4.generateMediaChannelKey(appID, appCertificate, channel, ts, r, uid, expiredTs);
test.equal(expected, actual);
test.done();
};
exports.PublicSharingKey5_Test = function(test) {

@@ -59,0 +20,0 @@ var expected = "005AwAoADc0QTk5RTVEQjI4MDk0NUI0NzUwNTk0MUFDMjM4MDU2NzIwREY3QjAQAJcMo13mDERkW7roohUGGzOwKDdW9buDA68oN1YAAA==";

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc