Skip to content

Instantly share code, notes, and snippets.

@richardhj
Last active May 24, 2021 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardhj/3a111f1e64f1db29d9a34f07c68db5e4 to your computer and use it in GitHub Desktop.
Save richardhj/3a111f1e64f1db29d9a34f07c68db5e4 to your computer and use it in GitHub Desktop.
<?php
class DropboxWebhook
{
/**
* Handle the dropbox webhook request
*/
public function handle()
{
global $container;
header('Content-Type: text/plain');
// Check get parameter
// Necessary for enabling the webhook via dropbox' app console
if (($challenge = \Input::get('challenge'))) {
die($challenge);
}
$rawData = file_get_contents('php://input');
$json = json_decode($rawData);
$appSecret = $container['dropbox.appSecret'];
// Check the signature for a valid request
if ($_SERVER['HTTP_X_DROPBOX_SIGNATURE'] !== hash_hmac('sha256', $rawData, $appSecret)) {
header('HTTP/1.0 403 Forbidden');
die('Invalid request');
}
// Return a response to the client before processing
// Dropbox wants a response quickly
header('Connection: close');
ob_start();
header('HTTP/1.0 200 OK');
ob_end_flush();
flush();
// Do all the stuff you want to
}
}
<?php
// Run the controller
$controller = new DropboxWebhook();
$controller->handle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment