Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration flag to disable splitting keys on '.' #42

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Template/config/integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<?= $this->form->label(t('User ID Key'), 'oauth2_key_user_id') ?>
<?= $this->form->text('oauth2_key_user_id', $values) ?>

<?= $this->form->hidden('oauth2_split_keys', array('oauth2_split_keys' => 0)) ?>
<?= $this->form->checkbox('oauth2_split_keys', t('Use composite keys?'), 1, isset($values['oauth2_split_keys']) && $values['oauth2_split_keys'] == 1) ?>
<p class="form-help"><?= t('Interpret \'.\' in keys as keys for sub-objects') ?></p>

<?= $this->form->hidden('oauth2_account_creation', array('oauth2_account_creation' => 0)) ?>
<?= $this->form->checkbox('oauth2_account_creation', t('Allow Account Creation'), 1, isset($values['oauth2_account_creation']) && $values['oauth2_account_creation'] == 1) ?>

Expand Down
24 changes: 19 additions & 5 deletions User/GenericOAuth2UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ public function getExternalGroupIds()
return array();
}

if(!is_array($groups)) {
$groups = array($groups);
}

$groups = array_unique($groups);
$this->logger->debug('OAuth2: '.$this->getUsername().' groups are '. join(',', $groups));

Expand Down Expand Up @@ -274,11 +278,21 @@ public function validateDomainRestriction(array $profile, $domains)

protected function getKey($key)
{
$key = explode('.', $this->configModel->get($key));
$value = $this->userData;
foreach ($key as $k) {
$value = $value[$k];
if($this->configModel->get('oauth2_split_keys') == 1) {
$key = explode('.', $this->configModel->get($key));
$value = $this->userData;
foreach ($key as $k) {
$value = $value[$k];
}
return ! empty($key) && isset($value) ? $value : '';
} else {
$key = $this->configModel->get($key);
if(empty($key)) {
return '';
}

$value = $this->userData[$key];
return isset($value) ? $value : '';
}
return ! empty($key) && isset($value) ? $value : '';
}
}
Loading