Agora v2.0.0 Agora.AccessKey View Source
Agora.AccessKey performs the algorithm used by the authentication mechanism in the Agora SDK version 2.1.0 or greater.
Sample usage
Server
channel_name = "test"
user = %{id: "12345asdf"}
token = Agora.AccessKey.new_token(@app_id, @certificate, channel_name, user.id, [
:join_channel,
:publish_audio,
:publish_video
])
Client
// Using agora-rtc-sdk-ng
const client = AgoraRTC.createClient({ mode: 'live', codec: 'vp8' });
await client.join(appId, 'test', token, '12345asdf');
client.setClientRole('host');
Link to this section Summary
Functions
More direct way of generating tokens if you need to specify the salt and expiry manually.
Generate a signed token that expires after 1 day
Get the integer value that agora assigns to a specific privilege.
Return a map of all the raw privileges
Link to this section Functions
Link to this function
generate_signed_token(app_id, app_certificate, channel_name, uid, privileges, salt, ts)
View SourceSpecs
generate_signed_token( binary(), binary(), binary(), binary(), [{atom(), integer()}], integer(), integer() ) :: binary()
More direct way of generating tokens if you need to specify the salt and expiry manually.
Examples
iex> Agora.AccessKey.generate_signed_token("970CA35de60c44645bbae8a215061b33", "5CFd2fd1755d40ecb72977518be15d3b", "7d72365eb983485397e3e3f9d460bdda", "0", [{:join_channel, 1_446_455_471}], 1, 1_111_111)
"006970CA35de60c44645bbae8a215061b33IABNRUO/126HmzFc+J8lQFfnkssUdUXqiePeE2WNZ7lyubdIfRAh39v0EAABAAAAR/QQAAEAAQCvKDdW"
Specs
Generate a signed token that expires after 1 day
Usage
user = %{id: "12345"}
token = Agora.new_token("970CA35de60c44645bbae8a215061b33", "5CFd2fd1755d40ecb72977518be15d3b", "7d72365eb983485397e3e3f9d460bdda", user.id, [
:join_channel,
:publish_audio,
:publish_video,
:request_publish_audio,
:request_publish_video
])
Specs
Get the integer value that agora assigns to a specific privilege.
Examples
iex> Agora.AccessKey.privilege(:join_channel)
1
iex> Agora.AccessKey.privilege(:publish_video)
3
Specs
privileges() :: %{optional(<<_::64, _::_*8>>) => 1..1000}
Return a map of all the raw privileges