This page describes the authentication mechanism used by the Agora SDK, as well as providing the related code for generating AccessToken (v2.1.0) or Dynamic Key (v2.0.2 or earlier).
For users who want a quick deployable sample server to test with, please look at here
AccessToken is more powerful than the legacy Dynamic Key. It encapsulates several privileges in one token to cover various services provided by Agora.
AccessToken is available as of SDK 2.1.0.
Sample usage,
AccessToken a(appID, appCertificate, channelName, uid);
a.AddPrivilege(AccessToken::kJoinChannel);
a.AddPrivilege(AccessToken::kPublishAudioStream);
std::string token = a.Build();Sample Code for generating AccessToken are available on the following platforms:
- C++
- Go
- Java
- Node.js
- Python
- PHP
- Perl
- CSharp
You can use either the following SimpleTokenBuilder or AccessToken sample code to generate an AccessToken. SimpleTokenBuilder encapsulates the underlying AccessToken sample code and is easy to use.
- https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/perl/src/Agora/SimpleTokenBuilder.pm
- https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/perl/src/Agora/AccessToken.pm
If you have implemented our algorithm in other languages, kindly file a pull request with us. We are delighted to merge any of the implementations that are correct and have test cases. Many thanks.
The Dynamic Key is used by Agora SDKs of versions earlier than 2.1.
- To join a media channel, use generateMediaChannelKey.
- For recording services, use generateRecordingKey.
Following are samples for C++, Go, Java, Nodejs, PHP and Python.
If you are using the Agora SDK of a version earlier than 2.1 and looking at implementing the function of publishing with a permission key, Agora recommends that you upgrade to DynamicKey5.
| Dynamic Key Version | UID | SDK Version |
|---|---|---|
| DynamicKey5 | specify the permission | 1.7.0 or later |
| Dynamic Key Version | UID | SDK Version |
|---|---|---|
| DynamicKey5 | specify uid of user | 1.3.0 or later |
| DynamicKey4 | specify uid of user | 1.3.0 or later |
| DynamicKey3 | specify uid of user | 1.2.3 or later |
| DynamicKey | NA | NA |
| Dynamic Key Version | UID | SDK Version |
|---|---|---|
| DynamicKey5 | 0 | All |
| DynamicKey4 | 0 | All |
| DynamicKey3 | 0 | All |
| DynamicKey | All | All |