Shopify / shopify-api-php

MIT License
360 stars 166 forks source link

5.5.1 is a breaking change: CookieNotFoundException #350

Open bradsk88 opened 2 weeks ago

bradsk88 commented 2 weeks ago

Issue summary

I'm working a large Laravel project which makes use of this library. After updating from 5.5.0 → 5.5.1 my test suites began to fail with a CookieNotFoundException.

Expected behavior

Either:

  1. My code should continue to function, or ...
  2. The SDK version should be bumped to indicate a breaking change and provide recommendations for how to overcome the breakage, or...
  3. The change introduced in 5.5.1 should be rolled back

Actual behavior

We are unable to update this SDK without doing a deep investigation to understand the source of the exception.

Steps to reproduce the problem

To be honest, I'm a bit new to the project, so I was not able to strip away all the details and produce a sharable reproduction (though I tried 😄)

However, I can share this code, which ran without error in version 5.5.0 but now throws a CookieNotFoundException

<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Lib\CookieHandler;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Log;
use Shopify\Auth\OAuth;
use Shopify\Utils;
use Shopify\Webhooks\Registry;
use Shopify\Webhooks\Topics;

class ShopifyController extends Controller
{
    public function callback(Request $request): RedirectResponse
    {
        $session = OAuth::callback( // <------------------ This is the line which now raises an exception
            (array) $request->cookie(),
            (array) $request->query(),
            [CookieHandler::class, 'saveShopifyCookie'],
        );

        $host = strval($request->query('host'));
        $shop = Utils::sanitizeShopDomain(strval($request->query('shop')));

        abort_if(is_null($shop), Response::HTTP_BAD_REQUEST);

        $response = Registry::register(
            '/api/webhooks',
            Topics::APP_UNINSTALLED,
            $shop,
            $session->getAccessToken() ?? '',
        );
        if ($response->isSuccess()) {
            Log::debug("Registered APP_UNINSTALLED webhook for shop $shop");
        } else {
            Log::error(
                "Failed to register APP_UNINSTALLED webhook for shop $shop with response body: " .
                print_r($response->getBody(), true)
            );
        }

        return redirect(Utils::getEmbeddedAppUrl($host));
    }
}

Checklist

Kudze commented 2 weeks ago

Could it be that you're experiencing this issue: #352?