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

UPDATE: configurable auth provider #934

Merged
Merged
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
5 changes: 5 additions & 0 deletions src/Http/Middleware/AuthProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Http/Middleware/VerifyShopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/ShopifyAppProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
8 changes: 4 additions & 4 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/resources/config/shopify-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/resources/database/factories/ShopFactory.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Faker\Generator as Faker;
use Illuminate\Support\Facades\Config;
use Osiset\ShopifyApp\Util;

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

$factory->define($model, function (Faker $faker) {
return [
Expand Down