Skip to content

Commit 1403097

Browse files
authored
Merge pull request #27 from seka19/feature/custom-scopes-validation
feat: custom scopes validation
2 parents 70644ec + 33f2a92 commit 1403097

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/ShopifyApp/Middleware/AuthShop.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,24 @@ function (\stdClass $row): string {
376376
explode(',', Config::get('shopify-app.api_scopes'))
377377
);
378378

379+
$customValidator = Config::get('shopify-app.api_scopes_validator');
380+
if (is_array($customValidator) && class_exists($customValidator[0])) {
381+
$class = app($customValidator[0]);
382+
if (method_exists($class, $customValidator[1])) {
383+
$ok = call_user_func_array(
384+
[$class, $customValidator[1]],
385+
[$shop, $scopes_actual]
386+
);
387+
if ($ok) {
388+
return null;
389+
}
390+
return Redirect::route(
391+
'authenticate',
392+
['shop' => $shop->shopify_domain]
393+
);
394+
}
395+
}
396+
379397
if (empty(array_diff($scopes_required, $scopes_actual))) {
380398
return null;
381399
}

src/ShopifyApp/resources/config/shopify-app.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@
161161
*/
162162
'api_scopes_validation' => (bool) env('SHOPIFY_API_SCOPES_VALIDATION', true),
163163

164+
/*
165+
* Custom scopes validation
166+
*
167+
* Correct value: [\App\Services\Shop::class, 'checkScopes']
168+
*
169+
* Expected method signature: public function checkScopes(\App\Models\Shop $shop, array $scopesActual): bool
170+
*/
171+
'api_scopes_validator' => null,
172+
164173
/*
165174
|--------------------------------------------------------------------------
166175
| Shopify API Grant Mode

0 commit comments

Comments
 (0)