From 420dfed28d253914c75cca0384d8d36b8f5a226b Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Thu, 21 Mar 2024 09:23:27 +0100 Subject: [PATCH] allow to use dot notation on individual group members --- DotAccess.php | 2 ++ action.php | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/DotAccess.php b/DotAccess.php index c132400..db373e7 100644 --- a/DotAccess.php +++ b/DotAccess.php @@ -20,6 +20,8 @@ class DotAccess */ public static function get($array, $key, $default = null) { + $key = trim($key, '.'); + if (!static::accessible($array)) { return $default; } diff --git a/action.php b/action.php index ff97a57..d3d9b95 100644 --- a/action.php +++ b/action.php @@ -29,10 +29,18 @@ class action_plugin_oauthgeneric extends Adapter $result = json_decode($raw, true); if (!$result) throw new OAuthException('Failed to parse data from userurl'); + $grpdots = sexplode('[]', $this->getConf('json-grps'), 2); $user = DotAccess::get($result, $this->getConf('json-user'), ''); $name = DotAccess::get($result, $this->getConf('json-name'), ''); $mail = DotAccess::get($result, $this->getConf('json-mail'), ''); - $grps = DotAccess::get($result, $this->getConf('json-grps'), []); + $grps = DotAccess::get($result, $grpdots[0], []); + + // use dot notation on each group + if(is_array($grps) && $grpdots[1]) { + $grps = array_map(function($grp) use ($grpdots) { + return DotAccess::get($grp, $grpdots[1], ''); + }, $grps); + } // type fixes if (is_array($user)) $user = array_shift($user); -- GitLab