Skip to content
Snippets Groups Projects
Commit 420dfed2 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

allow to use dot notation on individual group members

parent bf300a6c
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,8 @@ class DotAccess ...@@ -20,6 +20,8 @@ class DotAccess
*/ */
public static function get($array, $key, $default = null) public static function get($array, $key, $default = null)
{ {
$key = trim($key, '.');
if (!static::accessible($array)) { if (!static::accessible($array)) {
return $default; return $default;
} }
......
...@@ -29,10 +29,18 @@ class action_plugin_oauthgeneric extends Adapter ...@@ -29,10 +29,18 @@ class action_plugin_oauthgeneric extends Adapter
$result = json_decode($raw, true); $result = json_decode($raw, true);
if (!$result) throw new OAuthException('Failed to parse data from userurl'); 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'), ''); $user = DotAccess::get($result, $this->getConf('json-user'), '');
$name = DotAccess::get($result, $this->getConf('json-name'), ''); $name = DotAccess::get($result, $this->getConf('json-name'), '');
$mail = DotAccess::get($result, $this->getConf('json-mail'), ''); $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 // type fixes
if (is_array($user)) $user = array_shift($user); if (is_array($user)) $user = array_shift($user);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment