Skip to content

Commit

Permalink
feat: option to disable webhooks validation
Browse files Browse the repository at this point in the history
  • Loading branch information
seka19 committed Aug 1, 2021
1 parent 9423192 commit eafbcba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/ShopifyApp/Middleware/AuthWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Response;
use OhMyBrew\ShopifyApp\Facades\ShopifyApp;

Expand All @@ -16,7 +17,7 @@ class AuthWebhook
* Handle an incoming request to ensure webhook is valid.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param \Closure $next
*
* @return mixed
*/
Expand All @@ -26,11 +27,13 @@ public function handle(Request $request, Closure $next)
$shop = $request->header('x-shopify-shop-domain');
$data = $request->getContent();

$hmacLocal = ShopifyApp::createHmac(['data' => $data, 'raw' => true, 'encode' => true]);
if (!hash_equals($hmac, $hmacLocal) || empty($shop)) {
if (!Config::get('shopify-app.skip_webhook_validation')) {
$hmacLocal = ShopifyApp::createHmac(['data' => $data, 'raw' => true, 'encode' => true]);
if (!hash_equals($hmac, $hmacLocal) || empty($shop)) {

// Issue with HMAC or missing shop header
return Response::make('Invalid webhook signature.', 401);
// Issue with HMAC or missing shop header
return Response::make('Invalid webhook signature.', 401);
}
}

// All good, process webhook
Expand Down
8 changes: 7 additions & 1 deletion src/ShopifyApp/resources/config/shopify-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@
/**
* Use only for test mode!
* Disable redirects to Shopify to get token, confirm scopes etc.
* and suppose any logged in shop is authorized
* and suppose any logged-in shop is authorized
*/
'skip_auth_redirect' => (bool)env('SHOPIFY_SKIP_AUTH_REDIRECT', false),

/**
* Use only for test mode!
* Accept and process webhooks ignoring HMAC signature
*/
'skip_webhook_validation' => (bool)env('SHOPIFY_SKIP_WEBHOOK_VALIDATION', false),

/*
|--------------------------------------------------------------------------
| Shopify App Name
Expand Down

0 comments on commit eafbcba

Please sign in to comment.