Last active
January 9, 2023 06:32
-
-
Save airarm/8f3a3e97d20a7f8b349d17d8d2463919 to your computer and use it in GitHub Desktop.
This file contains 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 | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Arr; | |
class VerifyProxy | |
{ | |
public function handle(Request $request, Closure $next) | |
{ | |
if($request->has('shop') && $request->has('path_prefix') && $request->has('timestamp') && $request->has('signature')) | |
{ | |
$signature_verify_data = [ | |
'path_prefix' => $request->get('path_prefix'), | |
'shop' => $request->get('shop'), | |
'logged_in_customer_id' => !empty($request->get('logged_in_customer_id')) ? $request->get('logged_in_customer_id') : '', | |
'timestamp' => $request->get('timestamp'), | |
]; | |
ksort($signature_verify_data); | |
$signature = str_replace('&', '', urldecode(Arr::query($signature_verify_data))); | |
$verify_signature = hash_hmac('sha256', $signature, env('SHOPIFY_API_SECRET')); | |
if(!hash_equals($request->get('signature'), $verify_signature)) | |
{ | |
abort(401, 'Proxy verification failed'); | |
} | |
} | |
else | |
{ | |
abort(401, 'Proxy verification failed'); | |
} | |
return $next($request); | |
} | |
} |
This file contains 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 | |
if (! function_exists('proxy_response')) | |
{ | |
function proxy_response($content = '', $status = 200, array $headers = []) | |
{ | |
$headers['Content-Type'] = 'application/liquid'; | |
return response($content, $status, $headers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment