Skip to content

Commit

Permalink
Merge pull request #729 from nextcloud/fix/661/additional-attributes
Browse files Browse the repository at this point in the history
Fix/661/additional attributes
  • Loading branch information
julien-nc authored Dec 18, 2023
2 parents 65b75d8 + b7cc45f commit 9a5e996
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 28 deletions.
78 changes: 74 additions & 4 deletions lib/Command/UpsertProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,23 @@ protected function configure() {
->addOption('mapping-quota', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the quota')
->addOption('mapping-uid', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the user id')
->addOption('extra-claims', null, InputOption::VALUE_OPTIONAL, 'Extra claims to request when getting tokens')

->addOption('mapping-website', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the website')
->addOption('mapping-avatar', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the avatar')
->addOption('mapping-twitter', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of twitter')
->addOption('mapping-fediverse', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the fediverse')
->addOption('mapping-organisation', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the organisation')
->addOption('mapping-role', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the role')
->addOption('mapping-headline', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the headline')
->addOption('mapping-biography', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the biography')
->addOption('mapping-phone', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the phone')
->addOption('mapping-gender', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the gender')
->addOption('mapping-address', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the address')
->addOption('mapping-street_address', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the street address')
->addOption('mapping-postal_code', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the postal code')
->addOption('mapping-locality', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the locality')
->addOption('mapping-region', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the region')
->addOption('mapping-country', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the country')
->addOption('mapping-groups', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the groups')
->addOption(
'output',
null,
Expand Down Expand Up @@ -106,8 +122,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$updateOptions = array_filter($input->getOptions(), static function ($value, $option) {
return in_array($option, [
'identifier', 'clientid', 'clientsecret', 'discoveryuri',
'scope', 'unique-uid', 'check-bearer', 'endsessionendpointuri',
'mapping-uid', 'mapping-display-name', 'mapping-email', 'mapping-quota',
'scope', 'unique-uid', 'check-bearer', 'endsessionendpointuri', 'mapping-uid',
'mapping-display-name', 'mapping-email', 'mapping-quota', 'mapping-fediverse',
'mapping-address', 'mapping-street_address', 'mapping-postal_code', 'mapping-website',
'mapping-avatar', 'mapping-twitter', 'mapping-locality', 'mapping-region',
'mapping-country', 'mapping-organisation', 'mapping-role', 'mapping-headline',
'mapping-biography', 'mapping-phone', 'mapping-gender', 'mapping-groups',
'extra-claims'
]) && $value !== null;
}, ARRAY_FILTER_USE_BOTH);
Expand Down Expand Up @@ -165,7 +185,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
if (($uniqueUid = $input->getOption('unique-uid')) !== null) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_UNIQUE_UID, (string)$uniqueUid === '0' ? '0' : '1');
}

if ($mapping = $input->getOption('mapping-display-name')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_DISPLAYNAME, $mapping);
}
Expand All @@ -178,6 +197,57 @@ protected function execute(InputInterface $input, OutputInterface $output) {
if ($mapping = $input->getOption('mapping-uid')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_UID, $mapping);
}
if ($mapping = $input->getOption('mapping-fediverse')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_FEDIVERSE, $mapping);
}
if ($mapping = $input->getOption('mapping-groups')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_GROUPS, $mapping);
}
if ($mapping = $input->getOption('mapping-address')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_ADDRESS, $mapping);
}
if ($mapping = $input->getOption('mapping-street_address')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_STREETADDRESS, $mapping);
}
if ($mapping = $input->getOption('mapping-postal_code')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_POSTALCODE, $mapping);
}
if ($mapping = $input->getOption('mapping-locality')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_LOCALITY, $mapping);
}
if ($mapping = $input->getOption('mapping-region')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_REGION, $mapping);
}
if ($mapping = $input->getOption('mapping-country')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_COUNTRY, $mapping);
}
if ($mapping = $input->getOption('mapping-website')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_WEBSITE, $mapping);
}
if ($mapping = $input->getOption('mapping-avatar')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_AVATAR, $mapping);
}
if ($mapping = $input->getOption('mapping-twitter')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_TWITTER, $mapping);
}
if ($mapping = $input->getOption('mapping-organisation')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_ORGANISATION, $mapping);
}
if ($mapping = $input->getOption('mapping-role')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_ROLE, $mapping);
}
if ($mapping = $input->getOption('mapping-headline')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_HEADLINE, $mapping);
}
if ($mapping = $input->getOption('mapping-biography')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_BIOGRAPHY, $mapping);
}
if ($mapping = $input->getOption('mapping-phone')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_PHONE, $mapping);
}
if ($mapping = $input->getOption('mapping-gender')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_MAPPING_GENDER, $mapping);
}
if ($extraClaims = $input->getOption('extra-claims')) {
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_EXTRA_CLAIMS, $extraClaims);
}
Expand Down
32 changes: 32 additions & 0 deletions lib/Service/ProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ class ProviderService {
public const SETTING_MAPPING_EMAIL = 'mappingEmail';
public const SETTING_MAPPING_QUOTA = 'mappingQuota';
public const SETTING_MAPPING_GROUPS = 'mappingGroups';
public const SETTING_MAPPING_ADDRESS = 'mappingAddress';
public const SETTING_MAPPING_STREETADDRESS = 'mappingStreetaddress';
public const SETTING_MAPPING_POSTALCODE = 'mappingPostalcode';
public const SETTING_MAPPING_LOCALITY = 'mappingLocality';
public const SETTING_MAPPING_REGION = 'mappingRegion';
public const SETTING_MAPPING_COUNTRY = 'mappingCountry';
public const SETTING_MAPPING_WEBSITE = 'mappingWebsite';
public const SETTING_MAPPING_AVATAR = 'mappingAvatar';
public const SETTING_MAPPING_TWITTER = 'mappingTwitter';
public const SETTING_MAPPING_FEDIVERSE = 'mappingFediverse';
public const SETTING_MAPPING_ORGANISATION = 'mappingOrganisation';
public const SETTING_MAPPING_ROLE = 'mappingRole';
public const SETTING_MAPPING_HEADLINE = 'mappingHeadline';
public const SETTING_MAPPING_BIOGRAPHY = 'mappingBiography';
public const SETTING_MAPPING_PHONE = 'mappingPhonenumber';
public const SETTING_MAPPING_GENDER = 'mappingGender';
public const SETTING_EXTRA_CLAIMS = 'extraClaims';
public const SETTING_JWKS_CACHE = 'jwksCache';
public const SETTING_JWKS_CACHE_TIMESTAMP = 'jwksCacheTimestamp';
Expand Down Expand Up @@ -141,6 +157,22 @@ private function getSupportedSettings(): array {
self::SETTING_MAPPING_QUOTA,
self::SETTING_MAPPING_UID,
self::SETTING_MAPPING_GROUPS,
self::SETTING_MAPPING_ADDRESS,
self::SETTING_MAPPING_STREETADDRESS,
self::SETTING_MAPPING_POSTALCODE,
self::SETTING_MAPPING_LOCALITY,
self::SETTING_MAPPING_REGION,
self::SETTING_MAPPING_COUNTRY,
self::SETTING_MAPPING_WEBSITE,
self::SETTING_MAPPING_AVATAR,
self::SETTING_MAPPING_TWITTER,
self::SETTING_MAPPING_FEDIVERSE,
self::SETTING_MAPPING_ORGANISATION,
self::SETTING_MAPPING_ROLE,
self::SETTING_MAPPING_HEADLINE,
self::SETTING_MAPPING_BIOGRAPHY,
self::SETTING_MAPPING_PHONE,
self::SETTING_MAPPING_GENDER,
self::SETTING_UNIQUE_UID,
self::SETTING_CHECK_BEARER,
self::SETTING_SEND_ID_TOKEN_HINT,
Expand Down
Loading

0 comments on commit 9a5e996

Please sign in to comment.