From 8a3a0ca3b75d81a433fff8682e3b705d417b215d Mon Sep 17 00:00:00 2001 From: enmaboya Date: Sun, 10 Nov 2024 05:06:42 +0400 Subject: [PATCH 1/9] remove old config parameters --- src/Traits/AuthController.php | 1 - src/resources/config/shopify-app.php | 33 ---------------------------- 2 files changed, 34 deletions(-) diff --git a/src/Traits/AuthController.php b/src/Traits/AuthController.php index ab443566..3e9ee209 100644 --- a/src/Traits/AuthController.php +++ b/src/Traits/AuthController.php @@ -64,7 +64,6 @@ public function authenticate(Request $request, AuthenticateShop $authShop) 'shopify-app::auth.fullpage_redirect', [ 'apiKey' => Util::getShopifyConfig('api_key', $shopOrigin), - 'appBridgeVersion' => Util::getShopifyConfig('appbridge_version') ? '@'.config('shopify-app.appbridge_version') : '', 'authUrl' => $result['url'], 'host' => $request->get('host'), 'shopDomain' => $shopDomain, diff --git a/src/resources/config/shopify-app.php b/src/resources/config/shopify-app.php index 6acbfd7a..34770d10 100644 --- a/src/resources/config/shopify-app.php +++ b/src/resources/config/shopify-app.php @@ -37,7 +37,6 @@ */ 'domain' => env('SHOPIFY_DOMAIN'), - /* |-------------------------------------------------------------------------- | Manual routes @@ -138,26 +137,6 @@ 'prefix' => env('SHOPIFY_APP_PREFIX', ''), - /* - |-------------------------------------------------------------------------- - | AppBridge Mode - |-------------------------------------------------------------------------- - | - | AppBridge (embedded apps) are enabled by default. Set to false to use legacy - | mode and host the app inside your own container. - | - */ - - 'appbridge_enabled' => (bool) env('SHOPIFY_APPBRIDGE_ENABLED', true), - - // Use semver range to link to a major or minor version number. - // Leaving empty will use the latest version - not recommended in production. - 'appbridge_version' => env('SHOPIFY_APPBRIDGE_VERSION', 'latest'), - - // Set a new CDN URL if you want to host the AppBridge JS yourself or unpkg goes down. - // DO NOT include a trailing slash. - 'appbridge_cdn_url' => env('SHOPIFY_APPBRIDGE_CDN_URL', 'https://unpkg.com'), - /* |-------------------------------------------------------------------------- | Shopify App Name @@ -513,18 +492,6 @@ 'config_api_callback' => null, - /* - |-------------------------------------------------------------------------- - | Enable Turbolinks or Hotwire Turbo - |-------------------------------------------------------------------------- - | - | If you use Turbolinks/Turbo and Livewire, turn on this setting to get - | the token assigned automatically. - | - */ - - 'turbo_enabled' => (bool) env('SHOPIFY_TURBO_ENABLED', false), - /* |-------------------------------------------------------------------------- | Customize Models and Table Name From 023c9514f39b116787c27da111b62f791e309080 Mon Sep 17 00:00:00 2001 From: enmaboya Date: Sun, 10 Nov 2024 05:07:08 +0400 Subject: [PATCH 2/9] use shopify global object from app bridge cdn --- .../views/auth/fullpage_redirect.blade.php | 23 +++---------- src/resources/views/auth/token.blade.php | 13 ++++--- .../views/billing/fullpage_redirect.blade.php | 23 ++++++------- src/resources/views/home/index.blade.php | 16 +++------ src/resources/views/layouts/default.blade.php | 23 ++----------- .../views/partials/flash_messages.blade.php | 22 ------------ .../views/partials/token_handler.blade.php | 34 +++++++------------ 7 files changed, 42 insertions(+), 112 deletions(-) delete mode 100644 src/resources/views/partials/flash_messages.blade.php diff --git a/src/resources/views/auth/fullpage_redirect.blade.php b/src/resources/views/auth/fullpage_redirect.blade.php index 8ed3435d..0c911ca4 100644 --- a/src/resources/views/auth/fullpage_redirect.blade.php +++ b/src/resources/views/auth/fullpage_redirect.blade.php @@ -3,32 +3,19 @@ + + Redirecting... - diff --git a/src/resources/views/auth/token.blade.php b/src/resources/views/auth/token.blade.php index 8433d57f..b021b5e6 100644 --- a/src/resources/views/auth/token.blade.php +++ b/src/resources/views/auth/token.blade.php @@ -35,12 +35,15 @@ @section('scripts') @parent - @if(config('shopify-app.appbridge_enabled')) - @endif @endsection diff --git a/src/resources/views/billing/fullpage_redirect.blade.php b/src/resources/views/billing/fullpage_redirect.blade.php index 300d96d4..0c911ca4 100644 --- a/src/resources/views/billing/fullpage_redirect.blade.php +++ b/src/resources/views/billing/fullpage_redirect.blade.php @@ -3,24 +3,21 @@ + + Redirecting... - + diff --git a/src/resources/views/home/index.blade.php b/src/resources/views/home/index.blade.php index 633a6b3d..5ab6e32b 100644 --- a/src/resources/views/home/index.blade.php +++ b/src/resources/views/home/index.blade.php @@ -5,6 +5,8 @@ @endsection @section('content') + +
@@ -17,20 +19,10 @@

 

@endsection - -@section('scripts') - @parent - - @if(config('shopify-app.appbridge_enabled')) - - @endif -@endsection diff --git a/src/resources/views/layouts/default.blade.php b/src/resources/views/layouts/default.blade.php index 313e2bfd..fb66892c 100644 --- a/src/resources/views/layouts/default.blade.php +++ b/src/resources/views/layouts/default.blade.php @@ -3,6 +3,8 @@ + + {{ \Osiset\ShopifyApp\Util::getShopifyConfig('app_name') }} @yield('styles') @@ -17,28 +19,9 @@
- @if(\Osiset\ShopifyApp\Util::getShopifyConfig('appbridge_enabled') && \Osiset\ShopifyApp\Util::useNativeAppBridge()) - - - + @if(\Osiset\ShopifyApp\Util::useNativeAppBridge()) @include('shopify-app::partials.token_handler') - @include('shopify-app::partials.flash_messages') @endif - @yield('scripts') diff --git a/src/resources/views/partials/flash_messages.blade.php b/src/resources/views/partials/flash_messages.blade.php deleted file mode 100644 index 5298a344..00000000 --- a/src/resources/views/partials/flash_messages.blade.php +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/src/resources/views/partials/token_handler.blade.php b/src/resources/views/partials/token_handler.blade.php index a13efaf6..e8fced08 100644 --- a/src/resources/views/partials/token_handler.blade.php +++ b/src/resources/views/partials/token_handler.blade.php @@ -1,18 +1,14 @@ - From 41e641d444325d97f955d8b7c31a6e4e680b5054 Mon Sep 17 00:00:00 2001 From: enmaboya Date: Sun, 10 Nov 2024 05:07:33 +0400 Subject: [PATCH 3/9] remove unsupported turbolinks --- src/Http/Middleware/VerifyShopify.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Http/Middleware/VerifyShopify.php b/src/Http/Middleware/VerifyShopify.php index f2f29cd7..4818e5cb 100644 --- a/src/Http/Middleware/VerifyShopify.php +++ b/src/Http/Middleware/VerifyShopify.php @@ -377,20 +377,9 @@ protected function getHmacFromRequest(Request $request): array */ protected function getAccessTokenFromRequest(Request $request): ?string { - if (Util::getShopifyConfig('turbo_enabled')) { - if ($request->bearerToken()) { - // Bearer tokens collect. - // Turbo does not refresh the page, values are attached to the same header. - $bearerTokens = Collection::make(explode(',', $request->header('Authorization', ''))); - $newestToken = Str::substr(trim($bearerTokens->last()), 7); - - return $newestToken; - } - - return $request->get('token'); - } - - return $this->isApiRequest($request) ? $request->bearerToken() : $request->get('token'); + return $this->isApiRequest($request) + ? $request->bearerToken() + : $request->get('token'); } /** From 78aaa4fb0a9099738cbec5430a5883e931e15573 Mon Sep 17 00:00:00 2001 From: enmaboya Date: Mon, 11 Nov 2024 17:53:32 +0400 Subject: [PATCH 4/9] update tests --- src/Traits/AuthController.php | 2 +- src/resources/views/auth/fullpage_redirect.blade.php | 2 +- src/resources/views/billing/fullpage_redirect.blade.php | 2 +- src/resources/views/layouts/default.blade.php | 2 +- src/resources/views/partials/token_handler.blade.php | 6 +++--- tests/Traits/AuthControllerTest.php | 2 +- tests/Traits/BillingControllerTest.php | 1 + tests/Traits/HomeControllerTest.php | 9 +++------ 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Traits/AuthController.php b/src/Traits/AuthController.php index 3e9ee209..4d034079 100644 --- a/src/Traits/AuthController.php +++ b/src/Traits/AuthController.php @@ -64,7 +64,7 @@ public function authenticate(Request $request, AuthenticateShop $authShop) 'shopify-app::auth.fullpage_redirect', [ 'apiKey' => Util::getShopifyConfig('api_key', $shopOrigin), - 'authUrl' => $result['url'], + 'url' => $result['url'], 'host' => $request->get('host'), 'shopDomain' => $shopDomain, 'locale' => $request->get('locale'), diff --git a/src/resources/views/auth/fullpage_redirect.blade.php b/src/resources/views/auth/fullpage_redirect.blade.php index 0c911ca4..e14175f0 100644 --- a/src/resources/views/auth/fullpage_redirect.blade.php +++ b/src/resources/views/auth/fullpage_redirect.blade.php @@ -10,7 +10,7 @@ - {{ \Osiset\ShopifyApp\Util::getShopifyConfig('app_name') }} + {{ config('shopify-app.app_name') }} @yield('styles') diff --git a/src/resources/views/partials/token_handler.blade.php b/src/resources/views/partials/token_handler.blade.php index e8fced08..a9194b2d 100644 --- a/src/resources/views/partials/token_handler.blade.php +++ b/src/resources/views/partials/token_handler.blade.php @@ -1,7 +1,8 @@ @endsection diff --git a/src/resources/views/layouts/default.blade.php b/src/resources/views/layouts/default.blade.php index b75afaa6..854af9fd 100644 --- a/src/resources/views/layouts/default.blade.php +++ b/src/resources/views/layouts/default.blade.php @@ -3,7 +3,7 @@ - + {{ config('shopify-app.app_name') }} From e1bf25c84c614b897b17e8e8515feab0622344d5 Mon Sep 17 00:00:00 2001 From: Luke Walsh Date: Tue, 12 Nov 2024 10:08:12 +0000 Subject: [PATCH 6/9] Add some defensive checks to the token blade file --- src/resources/views/auth/token.blade.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/resources/views/auth/token.blade.php b/src/resources/views/auth/token.blade.php index d27fef25..9914e5c4 100644 --- a/src/resources/views/auth/token.blade.php +++ b/src/resources/views/auth/token.blade.php @@ -35,10 +35,20 @@ @section('scripts') @parent @endsection From 8f7f81beeca88cccdaf43f90df016b3ab6079f5b Mon Sep 17 00:00:00 2001 From: Luke Walsh Date: Tue, 12 Nov 2024 10:39:32 +0000 Subject: [PATCH 8/9] use the helper --- src/resources/views/auth/fullpage_redirect.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/views/auth/fullpage_redirect.blade.php b/src/resources/views/auth/fullpage_redirect.blade.php index e14175f0..0811f501 100644 --- a/src/resources/views/auth/fullpage_redirect.blade.php +++ b/src/resources/views/auth/fullpage_redirect.blade.php @@ -3,7 +3,7 @@ - + Redirecting... From 54b2813a5e872171b2d175c9ac46133ee444aeed Mon Sep 17 00:00:00 2001 From: Luke Walsh Date: Tue, 12 Nov 2024 10:46:54 +0000 Subject: [PATCH 9/9] Update the test to still check for a correct api key --- tests/Traits/HomeControllerTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Traits/HomeControllerTest.php b/tests/Traits/HomeControllerTest.php index 2b928412..b34b5eb1 100644 --- a/tests/Traits/HomeControllerTest.php +++ b/tests/Traits/HomeControllerTest.php @@ -4,6 +4,7 @@ use Illuminate\Auth\AuthManager; use Osiset\ShopifyApp\Test\TestCase; +use Osiset\ShopifyApp\Util; class HomeControllerTest extends TestCase { @@ -26,7 +27,8 @@ public function testHomeRoute(): void $host = base64_encode($shop->getDomain()->toNative().'/admin'); $this->call('get', '/', ['token' => $this->buildToken(), 'host' => $host]) ->assertOk() - ->assertSee("https://cdn.shopify.com/shopifycloud/app-bridge.js"); + ->assertSee('name="shopify-api-key" content="'.Util::getShopifyConfig('api_key').'"', false) + ->assertSee('https://cdn.shopify.com/shopifycloud/app-bridge.js'); } public function testHomeRouteHostAdmin(): void @@ -36,6 +38,7 @@ public function testHomeRouteHostAdmin(): void $host = base64_encode('admin.shopify.com/store/shop-name'); $this->call('get', '/', ['token' => $this->buildToken(), 'host' => $host]) ->assertOk() - ->assertSee("https://cdn.shopify.com/shopifycloud/app-bridge.js"); + ->assertSee('name="shopify-api-key" content="'.Util::getShopifyConfig('api_key').'"', false) + ->assertSee('https://cdn.shopify.com/shopifycloud/app-bridge.js'); } }