Class: Agora::AgoraDynamicKey2::ApaasTokenBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/agora/dynamic_key2/apaas_token_builder.rb

Class Method Summary collapse

Class Method Details

.build_app_token(app_id, app_certificate, expire) ⇒ Object

Build app token.

app_id: The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing

from your kit. See Get an App ID.

app_certificate: Certificate of the application that you registered in the Agora Dashboard.

See Get an App Certificate.

expire: represented by the number of seconds elapsed since now. If, for example, you want to access the

Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).

return: The app token.



63
64
65
66
67
68
69
70
71
# File 'lib/agora/dynamic_key2/apaas_token_builder.rb', line 63

def self.build_app_token(app_id, app_certificate, expire)
  access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, expire)

  service_apaas = Agora::AgoraDynamicKey2::ServiceApaas.new
  service_apaas.add_privilege(Agora::AgoraDynamicKey2::ServiceApaas::PRIVILEGE_APP, expire)
  access_token.add_service(service_apaas)

  access_token.build
end

.build_room_user_token(app_id, app_certificate, room_uuid, user_uuid, role, expire) ⇒ Object

Build room user token.

app_id: The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing

from your kit. See Get an App ID.

app_certificate: Certificate of the application that you registered in the Agora Dashboard.

See Get an App Certificate.

room_uuid: The room’s id, must be unique. user_uuid: The user’s id, must be unique. role: The user’s role. expire: represented by the number of seconds elapsed since now. If, for example, you want to access the

Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).

return: The room user token.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/agora/dynamic_key2/apaas_token_builder.rb', line 15

def self.build_room_user_token(app_id, app_certificate, room_uuid, user_uuid, role, expire)
  access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, expire)

  chat_user_id = Digest::MD5.hexdigest user_uuid
  service_apaas = Agora::AgoraDynamicKey2::ServiceApaas.new(room_uuid, user_uuid, role)
  service_apaas.add_privilege(Agora::AgoraDynamicKey2::ServiceApaas::PRIVILEGE_ROOM_USER, expire)
  access_token.add_service(service_apaas)

  service_rtm = Agora::AgoraDynamicKey2::ServiceRtm.new(user_uuid)
  service_rtm.add_privilege(Agora::AgoraDynamicKey2::ServiceRtm::PRIVILEGE_JOIN_LOGIN, expire)
  access_token.add_service(service_rtm)

  service_chat = Agora::AgoraDynamicKey2::ServiceChat.new(chat_user_id)
  service_chat.add_privilege(Agora::AgoraDynamicKey2::ServiceChat::PRIVILEGE_USER, expire)
  access_token.add_service(service_chat)

  access_token.build
end

.build_user_token(app_id, app_certificate, user_uuid, expire) ⇒ Object

Build user token.

app_id: The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing

from your kit. See Get an App ID.

app_certificate: Certificate of the application that you registered in the Agora Dashboard.

See Get an App Certificate.

user_uuid: The user’s id, must be unique. expire: represented by the number of seconds elapsed since now. If, for example, you want to access the

Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).

return: The user token.



44
45
46
47
48
49
50
51
52
# File 'lib/agora/dynamic_key2/apaas_token_builder.rb', line 44

def self.build_user_token(app_id, app_certificate, user_uuid, expire)
  access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, expire)

  service_apaas = Agora::AgoraDynamicKey2::ServiceApaas.new('', user_uuid)
  service_apaas.add_privilege(Agora::AgoraDynamicKey2::ServiceApaas::PRIVILEGE_USER, expire)
  access_token.add_service(service_apaas)

  access_token.build
end