Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 4ad2518

Browse files
authored
Merge pull request #1572 from Murena-SAS/fix-oidc-sso-login
oidc login
2 parents d069ca0 + 3d0b166 commit 4ad2518

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,18 @@ public static function startApp(bool $handle = false)
9191
*/
9292
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
9393
try {
94-
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
95-
if ($oAccount && $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn) {
96-
$oActions->SetSignMeToken($oAccount);
94+
$ocSession = \OC::$server->getSession();
95+
if ($ocSession->get('is_oidc')) {
96+
$pwd = new \SnappyMail\SensitiveString($aCredentials[1]);
97+
$oAccount = $oActions->LoginProcess($aCredentials[1], $pwd);
98+
if ($oAccount) {
99+
$oActions->SetSignMeToken($oAccount);
100+
}
101+
} else {
102+
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
103+
if ($oAccount && $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DefaultOff) === \RainLoop\Enumerations\SignMeType::DefaultOn) {
104+
$oActions->SetSignMeToken($oAccount);
105+
}
97106
}
98107
} catch (\Throwable $e) {
99108
// Login failure, reset password to prevent more attempts
@@ -140,22 +149,22 @@ private static function getLoginCredentials() : array
140149
// If the current user ID is identical to login ID (not valid when using account switching),
141150
// this has the second priority.
142151
if ($ocSession['snappymail-nc-uid'] == $sUID) {
143-
/*
152+
144153
// If OpenID Connect (OIDC) is enabled and used for login, use this.
145154
// https://apps.nextcloud.com/apps/oidc_login
146-
// DISABLED https://github.com/the-djmaze/snappymail/issues/1420#issuecomment-1933045917
147155
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
148156
if ($ocSession->get('is_oidc')) {
149157
// IToken->getPassword() ???
150158
if ($sAccessToken = $ocSession->get('oidc_access_token')) {
151-
return [$sUID, 'oidc@nextcloud', $sAccessToken];
159+
$sEmail = $config->getUserValue($sUID, 'settings', 'email');
160+
return [$sUID, $sEmail, $sAccessToken];
152161
}
153162
\SnappyMail\Log::debug('Nextcloud', 'OIDC access_token missing');
154163
} else {
155164
\SnappyMail\Log::debug('Nextcloud', 'No OIDC login');
156165
}
157166
}
158-
*/
167+
159168
// Only use the user's password in the current session if they have
160169
// enabled auto-login using Nextcloud username or email address.
161170
$sEmail = '';

plugins/nextcloud/index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public function Init() : void
3535

3636
$this->addTemplate('templates/PopupsNextcloudFiles.html');
3737
$this->addTemplate('templates/PopupsNextcloudCalendars.html');
38-
/*
38+
3939
$this->addHook('login.credentials.step-2', 'loginCredentials2');
4040
$this->addHook('login.credentials', 'loginCredentials');
4141
$this->addHook('imap.before-login', 'beforeLogin');
4242
$this->addHook('smtp.before-login', 'beforeLogin');
4343
$this->addHook('sieve.before-login', 'beforeLogin');
44-
*/
44+
4545
} else {
4646
\SnappyMail\Log::debug('Nextcloud', 'NOT integrated');
4747
// \OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-no-embed');
@@ -87,7 +87,7 @@ public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) :
8787
public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void
8888
{
8989
$oSettings->username = \OC::$server->getUserSession()->getUser()->getUID();
90-
/*
90+
9191
// https://apps.nextcloud.com/apps/oidc_login
9292
// DISABLED https://github.com/the-djmaze/snappymail/issues/1420#issuecomment-1933045917
9393
if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false)
@@ -100,7 +100,7 @@ public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetCl
100100
\array_unshift($oSettings->SASLMechanisms, 'OAUTHBEARER');
101101
}
102102
}
103-
*/
103+
104104
}
105105

106106
/*

0 commit comments

Comments
 (0)