Skip to content

Commit

Permalink
Also check if the account has been defined in setting
Browse files Browse the repository at this point in the history
  • Loading branch information
akhil1508 committed Aug 8, 2024
1 parent 25428c7 commit ae74f21
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions plugins/nextcloud/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,24 @@ public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) :
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');
Expand Down

0 comments on commit ae74f21

Please sign in to comment.