Created
September 15, 2015 17:21
-
-
Save steveneaston/469191d0df7b17d9521e to your computer and use it in GitHub Desktop.
Revisions
-
steveneaston created this gist
Sep 15, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ <?php namespace App\Http\Middleware; use Closure; class VerifyShopifyWebhook { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (! $this->verifyShopifySignature($request)) { abort(401); } return $next($request); } private function verifyShopifySignature($request) { return ($request->header('x-shopify-hmac-sha256') == $this->calculateHmac()); } private function calculateHmac() { $data = file_get_contents('php://input'); return base64_encode(hash_hmac('sha256', $data, env('SHOPIFY_APP_SECRET'), true)); } }