From 0aa531724d3725da76e2c45087a16aaa9efa163f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florencio=20Hern=C3=A1ndez?= Date: Tue, 17 Sep 2024 12:16:00 +0100 Subject: [PATCH] Add the ability to use a callback in bypassAuth in permissions --- src/Rbac/Rbac.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Rbac/Rbac.php b/src/Rbac/Rbac.php index a7be601..726e2e1 100644 --- a/src/Rbac/Rbac.php +++ b/src/Rbac/Rbac.php @@ -167,7 +167,11 @@ protected function _matchPermission(array $permission, $user, $role, ServerReque 'action' => $params['action'] ?? null, 'role' => $role, ]; - if (!$user && ($permission['bypassAuth'] ?? false) !== true) { + $bypass = $permission['bypassAuth'] ?? false; + if (is_callable($bypass)) { + $bypass = $bypass($user, $role, $request); + } + if (!$user && $bypass !== true) { return null; } foreach ($permission as $key => $value) {