On this page

Authenticating server-to-server callbacks


To enhance data security, developers should perform local signature calculations when receiving callbacks from the ZEGOCLOUD server, and compare them with the provided signature to determine if the request is legitimate.

Please refer to the following method to verify if the callback request is initiated by the ZEGOCLOUD cloud player.

Verification Method

Developers need to compare the calculated signature value with the signature value in the callback result to determine if they match. This is used to verify if the request is initiated by the ZEGOCLOUD cloud player.

The process of calculating the signature value is as shown in the following diagram:

  • nonce: A random number in the callback request.
  • timestamp: Unix timestamp in the callback request.
  • callbacksecret: The server-side verification key. It is generated when registering a project in the ZEGOCLOUD Console and can be viewed in "Console > Project Configuration > Project Information > Configuration Information".

Sample code

The following sample code is used to generate and verify the signature.

  $signature = $_POST["signature"];
  $timestamp = $_POST["timestamp"];
  $nonce = $_POST["nonce"];

  $secret = callbacksecret;//Callback secret obtained from the backend.
  $tmpArr = array($secret, $timestamp, $nonce);
  sort($tmpArr, SORT_STRING);
  $tmpStr = implode( $tmpArr );
  $tmpStr = sha1( $tmpStr );

  if( $tmpStr == $signature ){
      return true;
  } else {
      return false;
  }

Output example

$timestamp = 1470820198;
$nonce = 123412;
$secret = 'secret';

The original string to be encrypted after sorting and concatenation is: 1234121470820198secret
The encrypted result is: 5bd59fd62953a8059fb7eaba95720f66d19e4517

Previous

Describe upload tasks

Next

Callback

On this page

Back to top