Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Fixed app-bridge redirect on fullpage_redirect auth view #1097

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Traits/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,21 @@ public function authenticate(Request $request, AuthenticateShop $authShop)
throw new MissingAuthUrlException('Missing auth url');
}

// Just return them straight to the OAUTH flow.
return Redirect::to($result['url']);
$shopDomain = $shopDomain->toNative();
$shopOrigin = $shopDomain ?? $request->user()->name;

return View::make(
'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->host ?? base64_encode($shopOrigin.'/admin'),
'shopDomain' => $shopDomain,
'shopOrigin' => $shopOrigin,
]
);

} else {
// Go to home route
return Redirect::route(
Expand Down
16 changes: 12 additions & 4 deletions src/resources/views/auth/fullpage_redirect.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<title>Redirecting...</title>

<script src="https://unpkg.com/@shopify/app-bridge{!! $appBridgeVersion !!}"></script>
<script src="https://unpkg.com/@shopify/app-bridge-utils{!! $appBridgeVersion !!}"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
var redirectUrl = "{!! $authUrl !!}";
Expand All @@ -17,11 +19,17 @@
normalizedLink = document.createElement('a');
normalizedLink.href = redirectUrl;

data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: redirectUrl },
var AppBridge = window['app-bridge'];
var createApp = AppBridge.default;
var Redirect = AppBridge.actions.Redirect;
var app = createApp({
apiKey: "{{!! $apiKey !!}}",
shopOrigin: "{{!! $shopOrigin !!}}",
host: "{{!! $host !!}}",
});
window.parent.postMessage(data, "https://{{ $shopDomain }}");

var redirect = Redirect.create(app);
redirect.dispatch(Redirect.Action.REMOTE, normalizedLink.href);
}
});
</script>
Expand Down