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

Commit

Permalink
Simplify the auth flow by removing the full page redirect. (#1075)
Browse files Browse the repository at this point in the history
* Simplify the auth flow by removing the full page redirect.
  • Loading branch information
Kyon147 authored Apr 27, 2022
1 parent baa6248 commit 8eb0181
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
12 changes: 3 additions & 9 deletions src/Traits/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\View;
use Osiset\ShopifyApp\Actions\AuthenticateShop;
use Osiset\ShopifyApp\Exceptions\MissingAuthUrlException;
Expand Down Expand Up @@ -51,17 +50,12 @@ public function authenticate(Request $request, AuthenticateShop $authShop)
// Show exception, something is wrong
throw new SignatureVerificationException('Invalid HMAC verification');
} elseif ($status === false) {
if (! $result['url']) {
if (!$result['url']) {
throw new MissingAuthUrlException('Missing auth url');
}

return View::make(
'shopify-app::auth.fullpage_redirect',
[
'authUrl' => $result['url'],
'shopDomain' => $shopDomain->toNative(),
]
);
// Just return them straight to the OAUTH flow.
return Redirect::to($result['url']);
} else {
// Go to home route
return Redirect::route(
Expand Down
9 changes: 3 additions & 6 deletions tests/Traits/AuthControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ public function testAuthRedirectsToShopifyWhenNoCode(): void
// Run the request
$response = $this->call('post', '/authenticate', ['shop' => 'example.myshopify.com']);

// Check the view
$response->assertViewHas('shopDomain', 'example.myshopify.com');
$response->assertViewHas(
'authUrl',
'https://example.myshopify.com/admin/oauth/authorize?client_id='.Util::getShopifyConfig('api_key').'&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate'
);
// Check the redirect happens and location is set properly in the header.
$response->assertStatus(302);
$response->assertHeader('location', 'https://example.myshopify.com/admin/oauth/authorize?client_id='.Util::getShopifyConfig('api_key').'&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate');
}

public function testAuthAcceptsShopWithCode(): void
Expand Down

0 comments on commit 8eb0181

Please sign in to comment.