diff --git a/src/Http/Middleware/AuthProxy.php b/src/Http/Middleware/AuthProxy.php index ed77c78e..92a8a013 100644 --- a/src/Http/Middleware/AuthProxy.php +++ b/src/Http/Middleware/AuthProxy.php @@ -82,6 +82,11 @@ public function handle(Request $request, Closure $next) // Login the shop $shop = $this->shopQuery->getByDomain($shop); if ($shop) { + // Override auth guard + if (($guard = Util::getShopifyConfig('shop_auth_guard'))) { + $this->auth->setDefaultDriver($guard); + } + $this->auth->login($shop); } diff --git a/src/Http/Middleware/VerifyShopify.php b/src/Http/Middleware/VerifyShopify.php index 3f12cf67..4816d847 100644 --- a/src/Http/Middleware/VerifyShopify.php +++ b/src/Http/Middleware/VerifyShopify.php @@ -248,6 +248,11 @@ protected function loginShopFromToken(SessionToken $token, NullableSessionId $se return false; } + // Override auth guard + if (($guard = Util::getShopifyConfig('shop_auth_guard'))) { + $this->auth->setDefaultDriver($guard); + } + // All is well, login the shop $this->auth->login($shop); diff --git a/src/ShopifyAppProvider.php b/src/ShopifyAppProvider.php index f78960f2..eafff592 100644 --- a/src/ShopifyAppProvider.php +++ b/src/ShopifyAppProvider.php @@ -290,7 +290,7 @@ private function bootJobs(): void */ private function bootObservers(): void { - $model = $this->app['config']->get('auth.providers.users.model'); + $model = Util::getShopifyConfig('user_model'); $model::observe($this->app->make(ShopObserver::class)); } diff --git a/src/Util.php b/src/Util.php index 6ab2a6ed..ee88ebe3 100644 --- a/src/Util.php +++ b/src/Util.php @@ -164,10 +164,10 @@ public static function registerPackageRoute(string $routeToCheck, $routesToExclu */ public static function getShopifyConfig(string $key, $shop = null) { - $config = array_merge( - Config::get('shopify-app', []), - ['user_model' => Config::get('auth.providers.users.model')] - ); + $config = Config::get('shopify-app', []); + + $config['user_model'] = Config::get("auth.providers.{$config['shop_auth_provider']}.model", Config::get('auth.providers.users.model')); + if (Str::is('route_names.*', $key)) { // scope the Arr::get() call to the "route_names" array diff --git a/src/resources/config/shopify-app.php b/src/resources/config/shopify-app.php index 7186666f..08099f3e 100644 --- a/src/resources/config/shopify-app.php +++ b/src/resources/config/shopify-app.php @@ -65,6 +65,27 @@ 'webhook' => env('SHOPIFY_ROUTE_NAME_WEBHOOK', 'webhook'), ], + /* + |-------------------------------------------------------------------------- + | Shop auth guard + |-------------------------------------------------------------------------- + | + | This option allows you to override auth guard used by package middlewares + | + */ + 'shop_auth_guard' => env('SHOPIFY_SHOP_AUTH_GUARD', null), + + /* + |-------------------------------------------------------------------------- + | Shop auth provider + |-------------------------------------------------------------------------- + | + | This option allows you to override package's build-in auth model + | If you need to keep User model intact, add custom auth provider and route middlewares for it + | + */ + 'shop_auth_provider' => env('SHOPIFY_SHOP_AUTH_PROVIDER', 'users'), + /* |-------------------------------------------------------------------------- | Namespace diff --git a/src/resources/database/factories/ShopFactory.php b/src/resources/database/factories/ShopFactory.php index ab7edaec..d5af07e8 100644 --- a/src/resources/database/factories/ShopFactory.php +++ b/src/resources/database/factories/ShopFactory.php @@ -1,9 +1,9 @@ define($model, function (Faker $faker) { return [