示例#1
0
    def test_(self):
        token = RtcTokenBuilder.build_token_with_uid(appID, appCertificate, channelName, uid, Role_Subscriber, expireTimestamp)
        parser = AccessToken()
        parser.fromString(token)

        self.assertEqual(parser.messages[kJoinChannel], expireTimestamp)
        self.assertNotIn(kPublishVideoStream, parser.messages)
        self.assertNotIn(kPublishAudioStream, parser.messages)
        self.assertNotIn(kPublishDataStream, parser.messages)
示例#2
0
 def test_token2(self):
     token = RtcTokenBuilder.buildTokenWithUidAndPrivilege(
         appID, appCertificate, channelName, uid, joinTs, audioTs, videoTs,
         dataTs)
     parser = AccessToken()
     parser.fromString(token)
     self.assertEqual(parser.messages[kJoinChannel], joinTs)
     self.assertEqual(parser.messages[kPublishAudioStream], audioTs)
     self.assertEqual(parser.messages[kPublishVideoStream], videoTs)
     self.assertEqual(parser.messages[kPublishDataStream], dataTs)
示例#3
0
 def buildTokenWithAccount(appId, appCertificate, channelName, account,
                           role, privilegeExpiredTs):
     token = AccessToken(appId, appCertificate, channelName, account)
     token.addPrivilege(kJoinChannel, privilegeExpiredTs)
     if role == Role_Attendee | role == Role_Admin | role == Role_Publisher:
         token.addPrivilege(kPublishVideoStream, privilegeExpiredTs)
         token.addPrivilege(kPublishAudioStream, privilegeExpiredTs)
         token.addPrivilege(kPublishDataStream, privilegeExpiredTs)
     return token.build()
class RtmTokenBuilder:
    def __init__(self, appID, appCertificate, userId):
        self.token = AccessToken(appID, appCertificate, userId, "")

    def initTokenBuilder(self, originToken):
        return self.token.fromString(originToken)

    def setPrivilege(self, privilege, expireTimestamp):
        self.token.messages[privilege] = expireTimestamp

    def removePrivilege(self, privilege):
        self.token.messages.pop(privilege)

    def buildToken(self):
        return self.token.build()
示例#5
0
 def buildTokenWithUserAccountAndPrivilege(appId, appCertificate,
                                           channelName, account,
                                           joinChannelPrivilegeExpiredTs,
                                           pubAudioPrivilegeExpiredTs,
                                           pubVideoPrivilegeExpiredTs,
                                           pubDataStreamPrivilegeExpiredTs):
     token = AccessToken(appId, appCertificate, channelName, account)
     token.addPrivilege(kJoinChannel, joinChannelPrivilegeExpiredTs)
     token.addPrivilege(kPublishAudioStream, pubAudioPrivilegeExpiredTs)
     token.addPrivilege(kPublishVideoStream, pubVideoPrivilegeExpiredTs)
     token.addPrivilege(kPublishDataStream, pubDataStreamPrivilegeExpiredTs)
     return token.build()
示例#6
0
def main():

    key = AccessToken.AccessToken(appID, appCertificate, channelName, uid)
    key.addPrivilege(AccessToken.kJoinChannel, expireTimestamp)

    result = key.build()
    print result
示例#7
0
class SimpleTokenBuilder:
    def __init__(self, appID, appCertificate, channelName, uid):
        self.token = AccessToken(appID, appCertificate, channelName, uid)

    def initPrivileges(self, role):
        self.token.messages = RolePrivileges[role]

    def initTokenBuilder(self, originToken):
        return self.token.fromString(originToken)

    def setPrivilege(self, privilege, expireTimestamp):
        self.token.messages[privilege] = expireTimestamp

    def removePrivilege(self, privilege):
        self.token.messages.pop(privilege)

    def buildToken(self):
        return self.token.build()
示例#8
0
def main():

    key = AccessToken.AccessToken(appID, appCertificate, channelName, uid)
    key.salt = salt
    key.ts = ts
    key.messages[AccessToken.kJoinChannel] = expiredTs

    result = key.build()
    print "Access Token:", result
    def test_(self):
        expected = "006970CA35de60c44645bbae8a215061b33IACV0fZUBw+72cVoL9eyGGh3Q6Poi8bgjwVLnyKSJyOXR7dIfRBXoFHlEAABAAAAR/QQAAEAAQCvKDdW"

        key = AccessToken.AccessToken(appID, appCertificate, channelName, uid)
        key.salt = salt
        key.ts = ts
        key.messages[AccessToken.kJoinChannel] = expireTimestamp

        result = key.build()
        self.assertEqual(expected, result)
示例#10
0
    def test_(self):
        # token = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, Role_Subscriber, expireTimestamp)
        # parser = AccessToken()
        # parser.fromString(token)

        # self.assertEqual(parser.messages[kJoinChannel], expireTimestamp)
        # self.assertNotIn(kPublishVideoStream, parser.messages)
        # self.assertNotIn(kPublishAudioStream, parser.messages)
        # self.assertNotIn(kPublishDataStream, parser.messages)

        token = RtcTokenBuilder.buildTokenWithUidAndPrivilege(
            appID, appCertificate, channelName, uid, joinTs, audioTs, videoTs,
            dataTs)

        print(token)
        parser = AccessToken()
        parser.fromString(token)
        self.assertEqual(parser.messages[kJoinChannel], joinTs)
        self.assertEqual(parser.messages[kPublishAudioStream], audioTs)
        self.assertEqual(parser.messages[kPublishVideoStream], videoTs)
        self.assertEqual(parser.messages[kPublishDataStream], dataTs)
class SimpleTokenBuilder:
    def __init__(self, appID, appCertificate, channelName, uid):
        self.token = AccessToken(appID, appCertificate, channelName, uid)
        random.seed(time.time())
        self.token.ts = int(time.time()) + 24 * 3600
        self.token.salt = random.randint(1, 99999999)
        self.token.messages = {}

    def initPriviliges(self, role):
        self.token.messages = RolePrivileges[role]

    def setPrivilege(self, privilege, timeoutFromNow):
        self.token.messages[privilege] = timeoutFromNow

    def removePrivilege(self, privilege):
        self.token.messages.pop(privilege)

    def buildToken(self):
        return self.token.build()
 def __init__(self, appID, appCertificate, channelName, uid):
     self.token = AccessToken(appID, appCertificate, channelName, uid)
     random.seed(time.time())
     self.token.ts = int(time.time()) + 24 * 3600
     self.token.salt = random.randint(1, 99999999)
     self.token.messages = {}
示例#13
0
 def buildToken(appId, appCertificate, userAccount, role,
                privilegeExpiredTs):
     token = AccessToken(appId, appCertificate, userAccount, "")
     token.addPrivilege(kRtmLogin, privilegeExpiredTs)
     return token.build()
示例#14
0
 def __init__(self, appID, appCertificate, userId):
     self.token = AccessToken(appID, appCertificate, userId, "")
示例#15
0
 def test_(self):
     token = RtmTokenBuilder.buildToken(appID, appCertificate, userAccount,
                                        Role_Rtm_User, expireTimestamp)
     parser = AccessToken()
     parser.fromString(token)
     self.assertEqual(parser.messages[kRtmLogin], expireTimestamp)
示例#16
0
 def __init__(self, appID, appCertificate, channelName, uid):
     self.token = AccessToken(appID, appCertificate, channelName, uid)
示例#17
0
 def test_(self):
     token = RtcTokenBuilder.build_token_with_uid(appID, appCertificate, channelName, uid, Role_Subscriber, expireTimestamp)
     parser = AccessToken()
     parser.fromString(token)