Last active
May 24, 2021 16:17
-
-
Save richardhj/3a111f1e64f1db29d9a34f07c68db5e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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