Skip to content

Commit

Permalink
Fetch default privacy scopes and set properties according to these in…
Browse files Browse the repository at this point in the history
…stead of using 'v2-local' (closed #1047)

Signed-off-by: Björn Bores <[email protected]>
  • Loading branch information
bjalbor committed Feb 7, 2025
1 parent c2605bc commit c1dd620
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/Service/ProvisioningService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\UserOIDC\Service;

use OC\Accounts\AccountManager;
use OCA\UserOIDC\AppInfo\Application;
use OCA\UserOIDC\Db\UserMapper;
use OCA\UserOIDC\Event\AttributeMappedEvent;
Expand Down Expand Up @@ -151,7 +152,10 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
}

$account = $this->accountManager->getAccount($user);
$scope = 'v2-local';
$fallbackScope = 'v2-local';
$defaultScopes = array_merge(AccountManager::DEFAULT_SCOPES,
$this->config->getSystemValue('account_manager.default_property_scope', []));


// Update displayname
if (isset($userName)) {
Expand Down Expand Up @@ -227,7 +231,7 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Phone mapping event dispatched');
if ($event->hasValue()) {
$account->setProperty('phone', $event->getValue(), $scope, '1', '');
$account->setProperty('phone', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_PHONE] ?? $fallbackScope, '1', '');
}

$addressParts = null;
Expand Down Expand Up @@ -266,15 +270,15 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Address mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('address', $event->getValue(), $scope, '1', '');
$account->setProperty('address', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS] ?? $fallbackScope, '1', '');
}

// Update the website
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_WEBSITE, $idTokenPayload, $website);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Website mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('website', $event->getValue(), $scope, '1', '');
$account->setProperty('website', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE] ?? $fallbackScope, '1', '');
}

// Update the avatar
Expand All @@ -290,23 +294,23 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Twitter mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('twitter', $event->getValue(), $scope, '1', '');
$account->setProperty('twitter', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_TWITTER] ?? $fallbackScope, '1', '');
}

// Update fediverse
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_FEDIVERSE, $idTokenPayload, $fediverse);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Fediverse mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('fediverse', $event->getValue(), $scope, '1', '');
$account->setProperty('fediverse', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_FEDIVERSE] ?? $fallbackScope, '1', '');
}

// Update the organisation
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_ORGANISATION, $idTokenPayload, $organisation);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Organisation mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('organisation', $event->getValue(), $scope, '1', '');
$account->setProperty('organisation', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_ORGANISATION] ?? $fallbackScope, '1', '');
}

// Update role
Expand All @@ -322,23 +326,25 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Headline mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('headline', $event->getValue(), $scope, '1', '');
$account->setProperty('headline', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_HEADLINE] ?? $fallbackScope, '1', '');
}

// Update the biography
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_BIOGRAPHY, $idTokenPayload, $biography);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Biography mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('biography', $event->getValue(), $scope, '1', '');
$account->setProperty('biography', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] ?? $fallbackScope, '1', '');
}

// Update the gender
// Since until now there is no default for property for gender we fallback to property birthday which IMHO comes as closest.
// In v31 there will be introduced PRONOUNS, which could be of better use
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_GENDER, $idTokenPayload, $gender);
$this->eventDispatcher->dispatchTyped($event);
$this->logger->debug('Gender mapping event dispatched');
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
$account->setProperty('gender', $event->getValue(), $scope, '1', '');
$account->setProperty('gender', $event->getValue(), $defaultScopes[\OCP\Accounts\IAccountManager::PROPERTY_BIRTHDAY] ?? $fallbackScope, '1', '');
}

$this->session->set('user_oidc.oidcUserData', $oidcGssUserData);
Expand Down

0 comments on commit c1dd620

Please sign in to comment.