Shopify / Shopify/shopify-api-php

5.5.1 is a breaking change: CookieNotFoundException

Open
#350 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
473
Forks
193
Avg merge
5h 8m
Merged PRs (30d)
1

Description

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

  • I have described this issue in a way that is actionable (if possible)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at OAuth::callback in the provided ShopifyController callback and inspect how CookieHandler::saveShopifyCookie is used. Compare the 5.5.0 and 5.5.1 behavior around the callback and CookieNotFoundException, then determine whether compatibility, a versioning and migration change, or a rollback is appropriate. Done means the breaking behavior and an actionable resolution are documented or fixed.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.