Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webhook] [auth] Use new authentication for retrieving the webhook. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions freemius-webhook-listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,25 @@ public static function listen() {
*/
protected static function mailchimp() {

// Retrieve the request's body and parse it as JSON
// Retrieve the request's body
$input = @file_get_contents("php://input");

$event_json = json_decode($input);
extract( self::$plugin );

// Verify the authenticity of the request.
$hash = hash_hmac('sha256', $input, $secret_key);

if ( ! isset( $event_json->id ) ) {
$signature = $_SERVER['HTTP_X_SIGNATURE'] ?? '';

if ( ! hash_equals($hash, $signature))
{
// Invalid signature, don't expose any data to attackers.
http_response_code(200);
exit;
}

/**
* Freemius PHP SDK can be downloaded from GitHub:
* https://github.com/Freemius/php-sdk
*/
require_once dirname(__FILE__) . '/includes/freemius/includes/sdk/Freemius.php';

extract( self::$plugin );

$fs = new Freemius_Api(
$type,
$id,
$public_key,
$secret_key
);

$fs_event = $fs->Api("/events/{$event_json->id}.json");
// Decode the request.
$fs_event = json_decode($input);

$user = $fs_event->objects->user;

Expand Down