diff --git a/DotAccess.php b/DotAccess.php index c132400ac308150c0e82b7197b7a9dc93ecfa86b..db373e7b97a1cacea93dba76bc664f49a84bba09 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 ff97a57936867c6e989acc8f5f1dec8f5bbff456..d3d9b95306660dd2dde1198bc81f25ae5fd46644 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);