Kyon147 / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
372 stars 110 forks source link

Support for App Bridge new CLOUD CDN URL #354

Open naqashm opened 1 month ago

naqashm commented 1 month ago

Shopify now recommends to include the App Bridge script in below format: <script src="https://cdn.shopify.com/shopifycloud/app-bridge.js"></script>

However, the current version of your package does not support this integration method. Could you please add support for an environment variable that allows us to specify the use of Shopify's Cloud CDN URL in layouts.default.blade.php? This would make it easier to follow Shopify's updated best practices. Thank you.

ajprod commented 1 month ago

Integrating the new Shopify App Bridge version requires additional work since it does not work the same as AppBridge v3. It's not a matter of just changing the script URL but it would be nice if an update is published to support this new version ;-)

jackthedev commented 2 weeks ago

This looks like its going to start affecting existing apps.

https://x.com/hcaz32000/status/1845857335358398903

ajprod commented 2 weeks ago

It’s now an official requirement: Shopify App Store apps must support the latest App Bridge.

I’ve started implementing App Bridge v4 using this package. It appears that updates are needed in the token_handler.blade.php file to utilize shopify.idToken() and in the VerifyShopify.php file to handle the id_token from the GET parameters. From my initial tests, App Bridge v4 seems to eliminate the need for the URL::tokenRoute() function in blade files.

However, I’ll wait for an official implementation from the package to confirm, as I’m not fully confident that my current solution is production-ready.

Kyon147 commented 1 week ago

As there is a year to implement this, I'd like to wait a little bit and see how this pans out for other app developers before committing to an approach in the main package.

I'll probably update my own apps first using overrides and seeing how that plays with it.

baristinaz87 commented 1 week ago

Shopify cannot approve the submitted app due to the use of the old appBridge version. I have tried many ways to solve the problem, but as we can see, we need to remove all appBridge definitions on all pages.

We use Livewire, so I applied all the code to token.blade.php. The application works fine but not in the authentication process. We are trying to solve the problem because our 2 applications are in the review process.

Kyon147 commented 1 week ago

@baristinaz87 I see, this is imposed for new apps right away?

If so, we might need to add a new config value to that other apps are backwards compatible for a little while.

baristinazvx commented 1 week ago

@baristinaz87 I see, this is imposed for new apps right away?

If so, we might need to add a new config value to that other apps are backwards compatible for a little while.

Yes, we submitted our apps the previous week. They didn't accept both. If you want to submit a new app after march 27 you have to use new the app bridge version

Shopify didn't say anything for published apps or didn't give any plan to migration. But they may will want to do it in the future.

Using new app bridge is simple, but our framework is litle bit complex. We were successfully that app work on first page with new appbridge but token route process should change and redirection has to be removed Thus It will work properly. I can't say exact thing to solve, now trying to solve our app problems for pass the reviewing.

ajprod commented 1 week ago

I was able to implement AppBridge v4 with this package successfully for an app but I'm doing some tests to see if it's stable enough.

In my implementation, I had to override a few files...

  1. token_handler.blade.php by updating the retrieveToken() function : window.sessionToken = await shopify.idToken();

  2. token.blade.php for the redirect :

    shopify.idToken().then((token) => {
                window.location.href = `{!! $target !!}{!! Str::contains($target, '?') ? '&' : '?' !!}id_token=${token}{{ Str::contains($target, 'host')? '' : '&host=${host}'}}`;
            });
  3. VerifiyShopify.php, especially the function getAccessTokenFromRequest() : return $request->get('token') ?? $request->get('id_token');

  4. I stopped using URL::tokenRoute()

I’ll check if I updated any other files, as it was a lot of back-and-forth work.