├── LICENSE.txt ├── PKG-INFO ├── README.md ├── agora_token_builder.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt └── top_level.txt ├── agora_token_builder ├── AccessToken.py ├── RtcTokenBuilder.py ├── RtmTokenBuilder.py └── __init__.py ├── dist └── agora_token_builder-1.0.0.tar.gz ├── setup.cfg └── setup.py /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2021 Agora.io 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | SOFTWARE. -------------------------------------------------------------------------------- /PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: agora_token_builder 3 | Version: 2.2.5 4 | Summary: Agora Token Builder. RTC & RTM 5 | Home-page: UNKNOWN 6 | Author: Dennis 7 | Author-email: 8 | License: UNKNOWN 9 | Keywords: python,agora,token-builder 10 | Platform: UNKNOWN 11 | Classifier: Development Status :: 1 - Planning 12 | Classifier: Intended Audience :: Developers 13 | Classifier: Programming Language :: Python :: 3 14 | Classifier: Operating System :: Unix 15 | Classifier: Operating System :: MacOS :: MacOS X 16 | Classifier: Operating System :: Microsoft :: Windows 17 | Description-Content-Type: text/markdown 18 | License-File: LICENSE.txt 19 | 20 | # Agora Token Generator 21 | 22 | 23 | # Description 24 | Token generator for building a token server with Python & the Agora RTM & RTC 25 | 26 | ## Installation 27 | ```pip install agora-token-builder``` 28 | 29 | ## How to use it? 30 | 31 | ###### Importing for RTC 32 | ```from agora_token_builder import RtcTokenBuilder``` 33 | 34 | ###### Importing for RTM 35 | ```from agora_token_builder import RtmTokenBuilder``` 36 | 37 | ## License 38 | 39 | © 2021 Agora.io 40 | 41 | This repository is licensed under the MIT license. See LICENSE for details. 42 | 43 | 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Agora Token Generator 2 | 3 | 4 | # Description 5 | Token generator for building a token server with Python & the Agora RTM/RTC 6 | 7 | ## Installation 8 | ------------ 9 | 10 | ```pip install agora-token-builder``` 11 | 12 | ## Usage 13 | ------------ 14 | 15 | ###### RTC Live Video Calling & Chat SDK 16 | 17 | Build token with `int` UID: 18 | ```python 19 | from agora_token_builder import RtcTokenBuilder 20 | 21 | #Build token with uid 22 | token = RtcTokenBuilder.buildTokenWithUid(appId, appCertificate, channelName, uid, role, privilegeExpiredTs) 23 | ``` 24 | Build token with `string` UserAccount: 25 | ```python 26 | from agora_token_builder import RtcTokenBuilder 27 | 28 | #Build token with userAccount 29 | token = RtcTokenBuilder.buildTokenWithAccount(appId, appCertificate, channelName, account, role, privilegeExpiredTs) 30 | ``` 31 | 32 | ###### RTM Real-Time Messaging & Chat SDK 33 | Build RTM token. 34 | ```python 35 | from agora_token_builder import RtmTokenBuilder 36 | 37 | token = RtmTokenBuilder.buildToken(appID, appCertificate, userAccount, role, privilegeExpiredTs) 38 | ``` 39 | 40 | 41 | 42 | ## Variable Definitions 43 | 44 | ```appID``` 45 |
46 | The App ID issued to you by Agora. Apply for a new App ID from the gora Dashboard if it is missing from your kit. See Get an App ID. 47 | 48 | ```appCertificate``` 49 |
50 | Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate. 51 | 52 | ```channelName``` 53 |
54 | Unique channel name for the AgoraRTC session in the string format 55 | 56 | ```uid``` 57 |
58 | User ID. A 32-bit unsigned integer with a value ranging from 1 to (232-1). optionalUid must be unique. 59 | 60 | ```userAccount``` 61 | A unique identifier used for to represent a user account. This value will be a string and can contain numbers, letters and any special characters. 62 | 63 | ```role``` 64 |
65 | Role_Publisher = 1: A broadcaster (host) in a live-broadcast profile. Role_Subscriber = 2: (Default) A audience in a live-broadcast profile. 66 | 67 | ```privilegeExpireTs``` 68 |
69 | Represented by the number of seconds elapsed since 1/1/1970. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expireTimestamp as the current 70 | 71 | 72 | ## License 73 | 74 | © 2021 Agora.io 75 | 76 | This repository is licensed under the MIT license. See LICENSE for details. 77 | -------------------------------------------------------------------------------- /agora_token_builder.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: agora-token-builder 3 | Version: 1.0.0 4 | Summary: Agora Token Builder. RTC & RTM 5 | Home-page: https://github.com/AgoraIO-Community/python-token-builder 6 | Author: Dennis 7 | Author-email: 8 | License: UNKNOWN 9 | Keywords: python,agora,token-builder 10 | Platform: UNKNOWN 11 | Classifier: Development Status :: 1 - Planning 12 | Classifier: Intended Audience :: Developers 13 | Classifier: Programming Language :: Python :: 3 14 | Description-Content-Type: text/markdown 15 | License-File: LICENSE.txt 16 | 17 | # Agora Token Generator 18 | 19 | 20 | # Description 21 | Token generator for building a token server with Python & the Agora RTM/RTC 22 | 23 | ## Installation 24 | ------------ 25 | 26 | ```pip install agora-token-builder``` 27 | 28 | ## Usage 29 | ------------ 30 | 31 | ###### RTC Live Video Calling & Chat SDK 32 | 33 | Build token with `int` UID: 34 | ```python 35 | from agora_token_builder import RtcTokenBuilder 36 | 37 | #Build token with uid 38 | token = RtcTokenBuilder.buildTokenWithUid(appId, appCertificate, channelName, uid, role, privilegeExpiredTs) 39 | ``` 40 | Build token with `string` UserAccount: 41 | ```python 42 | from agora_token_builder import RtcTokenBuilder 43 | 44 | #Build token with userAccount 45 | token = RtcTokenBuilder.buildTokenWithAccount(appId, appCertificate, channelName, account, role, privilegeExpiredTs) 46 | ``` 47 | 48 | ###### RTM Real-Time Messaging & Chat SDK 49 | Build RTM token. 50 | ```python 51 | from agora_token_builder import RtmTokenBuilder 52 | 53 | token = RtmTokenBuilder.buildToken(appID, appCertificate, userAccount, role, privilegeExpiredTs) 54 | ``` 55 | 56 | 57 | 58 | ## Variable Definitions 59 | 60 | ```appID``` 61 |
62 | The App ID issued to you by Agora. Apply for a new App ID from the gora Dashboard if it is missing from your kit. See Get an App ID. 63 | 64 | ```appCertificate``` 65 |
66 | Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate. 67 | 68 | ```channelName``` 69 |
70 | Unique channel name for the AgoraRTC session in the string format 71 | 72 | ```uid``` 73 |
74 | User ID. A 32-bit unsigned integer with a value ranging from 1 to (232-1). optionalUid must be unique. 75 | 76 | ```userAccount``` 77 | A unique identifier used for to represent a user account. This value will be a string and can contain numbers, letters and any special characters. 78 | 79 | ```role``` 80 |
81 | Role_Publisher = 1: A broadcaster (host) in a live-broadcast profile. Role_Subscriber = 2: (Default) A audience in a live-broadcast profile. 82 | 83 | ```privilegeExpireTs``` 84 |
85 | Represented by the number of seconds elapsed since 1/1/1970. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expireTimestamp as the current 86 | 87 | 88 | ## License 89 | 90 | © 2021 Agora.io 91 | 92 | This repository is licensed under the MIT license. See LICENSE for details. 93 | 94 | 95 | -------------------------------------------------------------------------------- /agora_token_builder.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE.txt 2 | README.md 3 | setup.cfg 4 | setup.py 5 | agora_token_builder/AccessToken.py 6 | agora_token_builder/RtcTokenBuilder.py 7 | agora_token_builder/RtmTokenBuilder.py 8 | agora_token_builder/__init__.py 9 | agora_token_builder.egg-info/PKG-INFO 10 | agora_token_builder.egg-info/SOURCES.txt 11 | agora_token_builder.egg-info/dependency_links.txt 12 | agora_token_builder.egg-info/top_level.txt -------------------------------------------------------------------------------- /agora_token_builder.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /agora_token_builder.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | agora_token_builder 2 | -------------------------------------------------------------------------------- /agora_token_builder/AccessToken.py: -------------------------------------------------------------------------------- 1 | import hmac 2 | from hashlib import sha256 3 | import base64 4 | import struct 5 | from zlib import crc32 6 | import secrets 7 | import time 8 | from collections import OrderedDict 9 | 10 | kJoinChannel = 1 11 | kPublishAudioStream = 2 12 | kPublishVideoStream = 3 13 | kPublishDataStream = 4 14 | kRtmLogin = 1000 15 | 16 | VERSION_LENGTH = 3 17 | APP_ID_LENGTH = 32 18 | 19 | 20 | def getVersion(): 21 | return '006' 22 | 23 | 24 | def packUint16(x): 25 | return struct.pack('