From ae74f21242e1c8e04db6730fec0284deb7793f9c Mon Sep 17 00:00:00 2001 From: Akhil Date: Thu, 8 Aug 2024 21:58:56 +0530 Subject: [PATCH] Also check if the account has been defined in setting --- plugins/nextcloud/index.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index c3a769eb6..80a0a8f66 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -90,15 +90,24 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void { // https://apps.nextcloud.com/apps/oidc_login - $ocUser = \OC::$server->getUserSession()->getUser(); - $sNcEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress(); + $config = \OC::$server->getConfig(); + $oUser = \OC::$server->getUserSession()->getUser(); + $sUID = $oUser->getUID(); + + $sEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email'); + $sPassword = $config->getUserValue($sUID, 'snappymail', 'passphrase') + ?: $config->getUserValue($sUID, 'snappymail', 'snappymail-password'); + $bAccountDefinedExplicitly = ($sEmail && $sPassword) && $sEmail === $oSettings->username; + + $sNcEmail = $oUser->getEMailAddress() ?: $oUser->getPrimaryEMailAddress(); // Only login with OIDC access token if - // it is enabled in config, the user is currently logged in with OIDC - // and the current snappymail account is the OIDC account + // it is enabled in config, the user is currently logged in with OIDC, + // the current snappymail account is the OIDC account and no account defined explicitly if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false) && \OC::$server->getSession()->get('is_oidc') && $sNcEmail === $oSettings->username + && !$bAccountDefinedExplicitly // && $oClient->supportsAuthType('OAUTHBEARER') // v2.28 ) { $sAccessToken = \OC::$server->getSession()->get('oidc_access_token');