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

Commit b442357

Browse files
UPDATE: configurable auth provider (#934)
* Configurable shop model * Configurable shop model (factory & shopify app provider) * Configurable shop model (revert middleware configuration) * Update ShopFactory.php * Configurable auth guard (necessary if custom shop model is used) * Configurable auth guard: lint cleanup Co-authored-by: Lucas Michot <lucas@semalead.com>
1 parent d08cea2 commit b442357

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

src/Http/Middleware/AuthProxy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public function handle(Request $request, Closure $next)
8282
// Login the shop
8383
$shop = $this->shopQuery->getByDomain($shop);
8484
if ($shop) {
85+
// Override auth guard
86+
if (($guard = Util::getShopifyConfig('shop_auth_guard'))) {
87+
$this->auth->setDefaultDriver($guard);
88+
}
89+
8590
$this->auth->login($shop);
8691
}
8792

src/Http/Middleware/VerifyShopify.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ protected function loginShopFromToken(SessionToken $token, NullableSessionId $se
248248
return false;
249249
}
250250

251+
// Override auth guard
252+
if (($guard = Util::getShopifyConfig('shop_auth_guard'))) {
253+
$this->auth->setDefaultDriver($guard);
254+
}
255+
251256
// All is well, login the shop
252257
$this->auth->login($shop);
253258

src/ShopifyAppProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private function bootJobs(): void
290290
*/
291291
private function bootObservers(): void
292292
{
293-
$model = $this->app['config']->get('auth.providers.users.model');
293+
$model = Util::getShopifyConfig('user_model');
294294
$model::observe($this->app->make(ShopObserver::class));
295295
}
296296

src/Util.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ public static function registerPackageRoute(string $routeToCheck, $routesToExclu
164164
*/
165165
public static function getShopifyConfig(string $key, $shop = null)
166166
{
167-
$config = array_merge(
168-
Config::get('shopify-app', []),
169-
['user_model' => Config::get('auth.providers.users.model')]
170-
);
167+
$config = Config::get('shopify-app', []);
168+
169+
$config['user_model'] = Config::get("auth.providers.{$config['shop_auth_provider']}.model", Config::get('auth.providers.users.model'));
170+
171171

172172
if (Str::is('route_names.*', $key)) {
173173
// scope the Arr::get() call to the "route_names" array

src/resources/config/shopify-app.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@
6565
'webhook' => env('SHOPIFY_ROUTE_NAME_WEBHOOK', 'webhook'),
6666
],
6767

68+
/*
69+
|--------------------------------------------------------------------------
70+
| Shop auth guard
71+
|--------------------------------------------------------------------------
72+
|
73+
| This option allows you to override auth guard used by package middlewares
74+
|
75+
*/
76+
'shop_auth_guard' => env('SHOPIFY_SHOP_AUTH_GUARD', null),
77+
78+
/*
79+
|--------------------------------------------------------------------------
80+
| Shop auth provider
81+
|--------------------------------------------------------------------------
82+
|
83+
| This option allows you to override package's build-in auth model
84+
| If you need to keep User model intact, add custom auth provider and route middlewares for it
85+
|
86+
*/
87+
'shop_auth_provider' => env('SHOPIFY_SHOP_AUTH_PROVIDER', 'users'),
88+
6889
/*
6990
|--------------------------------------------------------------------------
7091
| Namespace

src/resources/database/factories/ShopFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

33
use Faker\Generator as Faker;
4-
use Illuminate\Support\Facades\Config;
4+
use Osiset\ShopifyApp\Util;
55

6-
$model = Config::get('auth.providers.users.model');
6+
$model = Util::getShopifyConfig('user_model');
77

88
$factory->define($model, function (Faker $faker) {
99
return [

0 commit comments

Comments
 (0)