Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multi-account in nc with oauth login #1699

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ public function setPersonal(): JSONResponse {
]);
}

// Logout as the credentials have changed
SnappyMailHelper::loadApp();
\RainLoop\Api::Actions()->DoLogout();

return new JSONResponse([
'status' => 'success',
'Message' => $this->l->t('Saved successfully'),
'Email' => $sEmail
]);
} catch (Exception $e) {
// Logout as the credentials might have changed, as exception could be in one attribute
// TODO: Handle both exceptions separately?
SnappyMailHelper::loadApp();
\RainLoop\Api::Actions()->DoLogout();

return new JSONResponse([
'status' => 'error',
'Message' => $e->getMessage()
Expand Down
16 changes: 16 additions & 0 deletions plugins/nextcloud/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +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
$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,
// 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
Loading