Skip to content

Instantly share code, notes, and snippets.

@airarm
Last active January 9, 2023 06:32
Show Gist options
  • Save airarm/8f3a3e97d20a7f8b349d17d8d2463919 to your computer and use it in GitHub Desktop.
Save airarm/8f3a3e97d20a7f8b349d17d8d2463919 to your computer and use it in GitHub Desktop.
<?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);
}
}
<?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