Dev Center
All Community
How do I use co-host token authentication?
Type: Integration issues    Platform: Android / iOS / macOS / Web / Windows / Unity / Cocos Creator / Electron / React Native / Flutter   Last Updated: 2020/11/11 21:56:37


In a live streaming channel, when an audience member applies to co-host, you can use a token to authenticate whether the user can publish a stream. This feature is co-host token authentication.

Enable authentication

To enable co-host token authentication, contact, and provide the App ID of your project. Ensure that your project has enabled the App Certificate in Console.

Once you have enabled co-host token authentication, you app user must fulfill both of the following requirements to publish a stream in a channel:

  • The user role is set as BROADCASTER in setClientRole.
  • The user joins the channel with a token that has the privilege of a publisher (by setting the role parameter in the buildToken method as publisher) .

Refer to the following logic to authenticate whether an app user can publish a stream:

  1. Before joining a channel, the app client applies for a token with the privilege of a subscriber. The app server generates a token, and passes it to the app client.
  2. The app client calls joinChannel and passes the token to the SDK.
  3. Before changing the user role, the app client applies for a token with the privilege of a publisher. The app client generates a second token, and passes it to the app client.
  4. The app client calls renewToken and passes the new token to the SDK.
  5. The app client calls setClientRole to change the user role from an audience member to a host.
  6. The Agora server authenticates the token when the app client calls setClientRole. If the token is generated with the privilege of a publisher, the app client can publish a stream.