Questions and discussions about using the Shopify CLI and Shopify-built libraries.
Hi,
I developed shopify app using following
1- PHP (for OAuth and redirection to react user interface only)
2- React (for user interface)
3- NodeJs (for Swyft's server communication)
Upon submitting the app for approval, i got response that i must use Shopify App Bridge because app experience is not consistent. It basically escape the iFrame on initial installation, otherwise it works in iFrame quite fine. I am handling OAuth using PHP (i tried it with nodejs, but UI was always escaping from iFrame), how can i implement shopify app bridge to make sure app does not escape the iframe even on initial installation?
index.php
<?php
require_once 'vendor/autoload.php';
try {
$config = array(
'ShopUrl' => $_GET['shop'],
'ApiKey' => '12345',
'SharedSecret' => 'some_secret',
);
\PHPShopify\ShopifySDK::config($config);
$scopes = 'read_orders,write_orders,read_customers,read_product_listings,read_products,read_shipping';
$redirectUrl = 'https://......./callback.php';
\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl);
} catch (\Throwable $th) {
var_dump($th);
}
callback.php
<?php
require_once './vendor/autoload.php';
require './db_functions.php';
try {
$config = array(
'ShopUrl' => $_GET['shop'],
'ApiKey' => '12345',
'SharedSecret' => 'some_secret',
);
PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
initializeClient($accessToken, $_GET['shop']);
session_start();
$_SESSION['accessToken'] = $accessToken;
$_SESSION['shop'] = $_GET['shop'];
setcookie('swyft-shopify-access-token', $accessToken);
setcookie('swyft-shopify-shop', $_GET['shop']);
header("X-Frame-Options: SAMEORIGIN"); // setting iframe header
header("Location: /?accessToken=" . $accessToken . "&shop=" . $_GET['shop']); // this redirects to React UI
exit();
} catch (\Throwable $th) {
var_dump($th);
}
@swyft hey did you find a solution to this, I am currently having the same problem.