From 11a148e6374e58827a91226d15c9395d6982ac96 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 4 Apr 2024 23:42:04 +0530 Subject: [PATCH 01/21] sso login snappy --- lib/AppInfo/Application.php | 8 +-- lib/Listeners/AccessTokenUpdatedListener.php | 49 +++++++++++++++++++ ... => BeforeTemplateRenderedListener.php-bk} | 0 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 lib/Listeners/AccessTokenUpdatedListener.php rename lib/Listeners/{BeforeTemplateRenderedListener.php => BeforeTemplateRenderedListener.php-bk} (100%) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b8070465..62001a0b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,7 +26,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\AppInfo; -use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; + use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Listeners\TwoFactorStateChangedListener; use OCA\EcloudAccounts\Listeners\UserChangedListener; @@ -36,10 +36,11 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\IUserManager; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; +use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; +use OCA\EcloudAccounts\Listeners\AccessTokenUpdatedListener; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; @@ -49,7 +50,8 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + //$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + $context->registerEventListener(AccessTokenUpdatedEvent::class, AccessTokenUpdatedListener::class); $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); $context->registerEventListener(StateChanged::class, TwoFactorStateChangedListener::class); diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php new file mode 100644 index 00000000..52e87c52 --- /dev/null +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -0,0 +1,49 @@ +userSession = $userSession; + $this->session = $session; + $this->appManager = $appManager; + } + + public function handle(Event $event): void { + if (!($event instanceof AccessTokenUpdatedEvent) || !$this->userSession->isLoggedIn() || !$this->session->exists('is_oidc')) { + return; + } + + // just-in-case checks(also maybe useful for selfhosters) + if (!$this->appManager->isEnabledForUser(self::SNAPPYMAIL_APP_ID) || !$this->appManager->isEnabledForUser(self::OIDC_LOGIN_APP_ID)) { + return; + } + + $accessToken = $event->getAccessToken(); + if (!$accessToken) { + return; + } + + $username = $this->userSession->getUser()->getUID(); + + $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); + } +} diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php-bk similarity index 100% rename from lib/Listeners/BeforeTemplateRenderedListener.php rename to lib/Listeners/BeforeTemplateRenderedListener.php-bk -- GitLab From 3d95b2f948048b612d29ec9e13f3d4c92392f571 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 4 Apr 2024 23:44:01 +0530 Subject: [PATCH 02/21] sso login snappy --- lib/AppInfo/Application.php | 5 ++--- lib/Listeners/AccessTokenUpdatedListener.php | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 62001a0b..cec8b4f8 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,11 +26,12 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\AppInfo; - +use OCA\EcloudAccounts\Listeners\AccessTokenUpdatedListener; use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Listeners\TwoFactorStateChangedListener; use OCA\EcloudAccounts\Listeners\UserChangedListener; use OCA\EcloudAccounts\Service\LDAPConnectionService; +use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; use OCA\TwoFactorTOTP\Event\StateChanged; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -39,8 +40,6 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\IUserManager; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; -use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; -use OCA\EcloudAccounts\Listeners\AccessTokenUpdatedListener; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 52e87c52..766548e1 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; -use OCP\EventDispatcher\Event; -use OCP\IUserSession; -use OCP\ISession; -use OCP\App\IAppManager; use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; use OCA\SnappyMail\Util\SnappyMailHelper; +use OCP\App\IAppManager; +use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\ISession; +use OCP\IUserSession; class AccessTokenUpdatedListener implements IEventListener { private IUserSession $userSession; -- GitLab From 32cd02d5ceb2826b899deb04ada60bf4c4839ddb Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 4 Apr 2024 23:51:01 +0530 Subject: [PATCH 03/21] test log --- lib/Listeners/AccessTokenUpdatedListener.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 766548e1..facc81b4 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -28,21 +28,24 @@ class AccessTokenUpdatedListener implements IEventListener { } public function handle(Event $event): void { + \OC::$server->getLogger()->error("call1"); if (!($event instanceof AccessTokenUpdatedEvent) || !$this->userSession->isLoggedIn() || !$this->session->exists('is_oidc')) { return; } - + \OC::$server->getLogger()->error("call2"); // just-in-case checks(also maybe useful for selfhosters) if (!$this->appManager->isEnabledForUser(self::SNAPPYMAIL_APP_ID) || !$this->appManager->isEnabledForUser(self::OIDC_LOGIN_APP_ID)) { return; } - + \OC::$server->getLogger()->error("call3"); $accessToken = $event->getAccessToken(); if (!$accessToken) { return; } - + \OC::$server->getLogger()->error($accessToken); + $username = $this->userSession->getUser()->getUID(); + \OC::$server->getLogger()->error($username); $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } -- GitLab From e25186c056900e20e62845dc2e3617ad2c0052d8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 4 Apr 2024 23:52:48 +0530 Subject: [PATCH 04/21] test log --- lib/Listeners/AccessTokenUpdatedListener.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index facc81b4..29ec16b4 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -28,16 +28,16 @@ class AccessTokenUpdatedListener implements IEventListener { } public function handle(Event $event): void { - \OC::$server->getLogger()->error("call1"); + \OC::$server->getLogger()->error("call1"); if (!($event instanceof AccessTokenUpdatedEvent) || !$this->userSession->isLoggedIn() || !$this->session->exists('is_oidc')) { return; } - \OC::$server->getLogger()->error("call2"); + \OC::$server->getLogger()->error("call2"); // just-in-case checks(also maybe useful for selfhosters) if (!$this->appManager->isEnabledForUser(self::SNAPPYMAIL_APP_ID) || !$this->appManager->isEnabledForUser(self::OIDC_LOGIN_APP_ID)) { return; } - \OC::$server->getLogger()->error("call3"); + \OC::$server->getLogger()->error("call3"); $accessToken = $event->getAccessToken(); if (!$accessToken) { return; @@ -45,7 +45,7 @@ class AccessTokenUpdatedListener implements IEventListener { \OC::$server->getLogger()->error($accessToken); $username = $this->userSession->getUser()->getUID(); - \OC::$server->getLogger()->error($username); + \OC::$server->getLogger()->error($username); $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } -- GitLab From 014a3762adad7c394e3966048cb9ed9f813550ff Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 5 Apr 2024 00:05:19 +0530 Subject: [PATCH 05/21] test log --- lib/Listeners/AccessTokenUpdatedListener.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 29ec16b4..6152a88b 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -46,7 +46,10 @@ class AccessTokenUpdatedListener implements IEventListener { $username = $this->userSession->getUser()->getUID(); \OC::$server->getLogger()->error($username); - - $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); + + \OC::$server->getSession()['snappymail-nc-uid'] = $username; + OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($accessToken, $username); + + //$this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } } -- GitLab From 7a876fbc87e7fcafb297555ffd7a9cb57754454e Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 5 Apr 2024 00:08:58 +0530 Subject: [PATCH 06/21] test log --- lib/Listeners/AccessTokenUpdatedListener.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 6152a88b..538ad82c 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -47,8 +47,10 @@ class AccessTokenUpdatedListener implements IEventListener { $username = $this->userSession->getUser()->getUID(); \OC::$server->getLogger()->error($username); - \OC::$server->getSession()['snappymail-nc-uid'] = $username; - OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($accessToken, $username); + //\OC::$server->getSession()['snappymail-nc-uid'] = $username; + //OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($accessToken, $username); + $this->session->set('snappymail-nc-uid', SnappyMailHelper::encodePassword($accessToken, $username)); + $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); //$this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } -- GitLab From 5e37f1976d1b6d055dcd376b40813d30e0795fe2 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 5 Apr 2024 00:48:15 +0530 Subject: [PATCH 07/21] test password set --- lib/Listeners/AccessTokenUpdatedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 538ad82c..e17ca337 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -52,6 +52,6 @@ class AccessTokenUpdatedListener implements IEventListener { $this->session->set('snappymail-nc-uid', SnappyMailHelper::encodePassword($accessToken, $username)); $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); - //$this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); + $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } } -- GitLab From 8962133c71277e389637f578e7eeceda3aad310e Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 16 Apr 2024 19:17:43 +0530 Subject: [PATCH 08/21] access token added --- lib/Listeners/AccessTokenUpdatedListener.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index e17ca337..d4da5669 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -49,9 +49,11 @@ class AccessTokenUpdatedListener implements IEventListener { //\OC::$server->getSession()['snappymail-nc-uid'] = $username; //OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($accessToken, $username); - $this->session->set('snappymail-nc-uid', SnappyMailHelper::encodePassword($accessToken, $username)); + //$this->session->set('snappymail-nc-uid', SnappyMailHelper::encodePassword($accessToken, $username)); + $this->session->set('snappymail-nc-uid', $username); $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); - + $this->session->set('oidc_access_token',$accessToken); + $this->session->set('is_oidc',1); $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } } -- GitLab From 841dabb445449a0724a03f962c167aa5daf59a2e Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 16 Apr 2024 19:19:06 +0530 Subject: [PATCH 09/21] access token added --- lib/Listeners/AccessTokenUpdatedListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index d4da5669..f75af5de 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -52,8 +52,8 @@ class AccessTokenUpdatedListener implements IEventListener { //$this->session->set('snappymail-nc-uid', SnappyMailHelper::encodePassword($accessToken, $username)); $this->session->set('snappymail-nc-uid', $username); $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); - $this->session->set('oidc_access_token',$accessToken); - $this->session->set('is_oidc',1); + $this->session->set('oidc_access_token', $accessToken); + $this->session->set('is_oidc', 1); $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } } -- GitLab From 0ac8fbf5f829cfdeb5f07a4a0885a354bf061f9a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 24 Apr 2024 13:22:38 +0530 Subject: [PATCH 10/21] snappymail UID --- lib/Listeners/AccessTokenUpdatedListener.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index f75af5de..e71b6af9 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -42,7 +42,10 @@ class AccessTokenUpdatedListener implements IEventListener { if (!$accessToken) { return; } + $sUID = $event->getUser()->getUID(); + $this->session->set('snappymail-nc-uid', $sUID); \OC::$server->getLogger()->error($accessToken); + \OC::$server->getLogger()->error("snappymail-nc-uid:".$sUID); $username = $this->userSession->getUser()->getUID(); \OC::$server->getLogger()->error($username); @@ -53,7 +56,6 @@ class AccessTokenUpdatedListener implements IEventListener { $this->session->set('snappymail-nc-uid', $username); $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); $this->session->set('oidc_access_token', $accessToken); - $this->session->set('is_oidc', 1); $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } } -- GitLab From 9733eb936b974c5548f7b2af9165e98b79f8d498 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 24 Apr 2024 13:28:54 +0530 Subject: [PATCH 11/21] snappymail UID --- lib/Listeners/AccessTokenUpdatedListener.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index e71b6af9..996bea0b 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -42,13 +42,9 @@ class AccessTokenUpdatedListener implements IEventListener { if (!$accessToken) { return; } - $sUID = $event->getUser()->getUID(); - $this->session->set('snappymail-nc-uid', $sUID); - \OC::$server->getLogger()->error($accessToken); - \OC::$server->getLogger()->error("snappymail-nc-uid:".$sUID); $username = $this->userSession->getUser()->getUID(); - \OC::$server->getLogger()->error($username); + \OC::$server->getLogger()->error("ecloudaccounts-username".$username); //\OC::$server->getSession()['snappymail-nc-uid'] = $username; //OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($accessToken, $username); -- GitLab From 40e7c69be5519a0dc965e45f47e15ee317d0f62e Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 7 May 2024 22:30:11 +0530 Subject: [PATCH 12/21] call refresh token if access token expired --- lib/AppInfo/Application.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index cec8b4f8..a98346ed 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -40,6 +40,9 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\IUserManager; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; +use OCP\ISession; +use OCP\IUserSession; +use OCA\OIDCLogin\Service\TokenService; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; @@ -63,5 +66,15 @@ class Application extends App implements IBootstrap { $c->get(IUserManager::class) ); }); + + $userSession = $serverContainer->get(IUserSession::class); + $session = $serverContainer->get(ISession::class); + $tokenService = $serverContainer->get(TokenService::class); + $accessTokenExpiresAt = $this->session->get('oidc_access_token_expires_at'); + $now = time(); + if ($now > $accessTokenExpiresAt) { + $tokenService->refreshTokens(); + } + } } -- GitLab From 467ebd6e16cdca7f800802061bb38b9b47ab6788 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 7 May 2024 22:34:29 +0530 Subject: [PATCH 13/21] lint fix --- lib/AppInfo/Application.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a98346ed..51de6cfa 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,17 +32,17 @@ use OCA\EcloudAccounts\Listeners\TwoFactorStateChangedListener; use OCA\EcloudAccounts\Listeners\UserChangedListener; use OCA\EcloudAccounts\Service\LDAPConnectionService; use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; +use OCA\OIDCLogin\Service\TokenService; use OCA\TwoFactorTOTP\Event\StateChanged; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\ISession; use OCP\IUserManager; +use OCP\IUserSession; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; -use OCP\ISession; -use OCP\IUserSession; -use OCA\OIDCLogin\Service\TokenService; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; @@ -68,13 +68,13 @@ class Application extends App implements IBootstrap { }); $userSession = $serverContainer->get(IUserSession::class); - $session = $serverContainer->get(ISession::class); + $session = $serverContainer->get(ISession::class); $tokenService = $serverContainer->get(TokenService::class); $accessTokenExpiresAt = $this->session->get('oidc_access_token_expires_at'); $now = time(); if ($now > $accessTokenExpiresAt) { $tokenService->refreshTokens(); - } + } } } -- GitLab From 922ba74d9e53b14b72ff00864599c22e7868bb5f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 7 May 2024 23:36:30 +0530 Subject: [PATCH 14/21] fix session --- lib/AppInfo/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 51de6cfa..a5c6a226 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -70,7 +70,7 @@ class Application extends App implements IBootstrap { $userSession = $serverContainer->get(IUserSession::class); $session = $serverContainer->get(ISession::class); $tokenService = $serverContainer->get(TokenService::class); - $accessTokenExpiresAt = $this->session->get('oidc_access_token_expires_at'); + $accessTokenExpiresAt = $session->get('oidc_access_token_expires_at'); $now = time(); if ($now > $accessTokenExpiresAt) { $tokenService->refreshTokens(); -- GitLab From aa7b7facea1cf731fa9d52f13b3f6c4924a5b886 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 8 May 2024 00:46:00 +0530 Subject: [PATCH 15/21] removed logs --- lib/Listeners/AccessTokenUpdatedListener.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 996bea0b..4e34aafe 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -28,27 +28,19 @@ class AccessTokenUpdatedListener implements IEventListener { } public function handle(Event $event): void { - \OC::$server->getLogger()->error("call1"); if (!($event instanceof AccessTokenUpdatedEvent) || !$this->userSession->isLoggedIn() || !$this->session->exists('is_oidc')) { return; } - \OC::$server->getLogger()->error("call2"); // just-in-case checks(also maybe useful for selfhosters) if (!$this->appManager->isEnabledForUser(self::SNAPPYMAIL_APP_ID) || !$this->appManager->isEnabledForUser(self::OIDC_LOGIN_APP_ID)) { return; } - \OC::$server->getLogger()->error("call3"); $accessToken = $event->getAccessToken(); if (!$accessToken) { return; } $username = $this->userSession->getUser()->getUID(); - \OC::$server->getLogger()->error("ecloudaccounts-username".$username); - - //\OC::$server->getSession()['snappymail-nc-uid'] = $username; - //OC::$server->getSession()['snappymail-passphrase'] = SnappyMailHelper::encodePassword($accessToken, $username); - //$this->session->set('snappymail-nc-uid', SnappyMailHelper::encodePassword($accessToken, $username)); $this->session->set('snappymail-nc-uid', $username); $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); $this->session->set('oidc_access_token', $accessToken); -- GitLab From 4ed3f7fccffecf29fa8cb3443dc918c0f86eb4a8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 20 May 2024 19:35:07 +0530 Subject: [PATCH 16/21] resolved conflicts --- lib/AppInfo/Application.php | 4 +- .../BeforeTemplateRenderedListener.php | 36 ++++++++ .../BeforeTemplateRenderedListener.php-bk | 86 ------------------- 3 files changed, 39 insertions(+), 87 deletions(-) create mode 100644 lib/Listeners/BeforeTemplateRenderedListener.php delete mode 100644 lib/Listeners/BeforeTemplateRenderedListener.php-bk diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a5c6a226..2b479e01 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\AppInfo; +use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; use OCA\EcloudAccounts\Listeners\AccessTokenUpdatedListener; use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Listeners\TwoFactorStateChangedListener; @@ -38,6 +39,7 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\ISession; use OCP\IUserManager; use OCP\IUserSession; @@ -52,7 +54,7 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - //$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); $context->registerEventListener(AccessTokenUpdatedEvent::class, AccessTokenUpdatedListener::class); $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php new file mode 100644 index 00000000..74876cd7 --- /dev/null +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -0,0 +1,36 @@ +appName = $appName; + $this->request = $request; + $this->util = $util; + } + + public function handle(Event $event): void { + if (!($event instanceof BeforeTemplateRenderedEvent)) { + return; + } + $pathInfo = $this->request->getPathInfo(); + + if (strpos($pathInfo, '/apps/ecloud-accounts/accounts') !== false) { + $this->util->addStyle($this->appName, $this->appName . '-userregistration'); + } + + } + +} diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php-bk b/lib/Listeners/BeforeTemplateRenderedListener.php-bk deleted file mode 100644 index adece9c3..00000000 --- a/lib/Listeners/BeforeTemplateRenderedListener.php-bk +++ /dev/null @@ -1,86 +0,0 @@ -appName = $appName; - $this->userSession = $userSession; - $this->request = $request; - $this->session = $session; - $this->config = $config; - $this->appManager = $appManager; - $this->util = $util; - } - - public function handle(Event $event): void { - if (!($event instanceof BeforeTemplateRenderedEvent)) { - return; - } - if ($this->userSession->isLoggedIn() && $this->appManager->isEnabledForUser(self::SNAPPYMAIL_APP_ID) && strpos($this->request->getPathInfo(), self::SNAPPYMAIL_URL) !== false) { - $this->autoLoginWebmail(); - } - $pathInfo = $this->request->getPathInfo(); - - if (strpos($pathInfo, '/apps/ecloud-accounts/accounts') !== false) { - $this->util->addStyle($this->appName, $this->appName . '-userregistration'); - } - - } - - - private function autoLoginWebmail() { - $isOidcLogin = $this->session->get('is_oidc'); - if (!$isOidcLogin) { - return; - } - $accountId = $this->getAccountId(); - $actions = \RainLoop\Api::Actions(); - - if (empty($accountId) || $actions->getMainAccountFromToken(false)) { - return; - } - - // Just send over '1' as password to trigger login as the plugin will set the correct access token - $password = self::SNAPPYMAIL_AUTOLOGIN_PWD; // As we cannot pass by reference to LoginProcess - $account = $actions->LoginProcess($accountId, $password, false); - if ($account) { - $actions->Plugins()->RunHook('login.success', array($account)); - $actions->SetAuthToken($account); - } - } - - private function getAccountId(): string { - $username = $this->userSession->getUser()->getUID(); - if ($this->config->getAppValue('snappymail', 'snappymail-autologin', false)) { - return $username; - } - if ($this->config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) { - return $this->config->getUserValue($username, 'settings', 'email', ''); - } - } -} -- GitLab From 65e901c4029d0b00b36e68d186c452970aafc5d6 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 20 May 2024 19:37:02 +0530 Subject: [PATCH 17/21] lint fix --- lib/AppInfo/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 2b479e01..d9de676f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,8 +26,8 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\AppInfo; -use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; use OCA\EcloudAccounts\Listeners\AccessTokenUpdatedListener; +use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Listeners\TwoFactorStateChangedListener; use OCA\EcloudAccounts\Listeners\UserChangedListener; -- GitLab From 0862067f9a28ac00e08b80b6b5deadd43d8e7732 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 22 May 2024 00:02:01 +0530 Subject: [PATCH 18/21] removed refreshtokens call as its already called on logout --- lib/AppInfo/Application.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d9de676f..2448cc31 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -33,16 +33,13 @@ use OCA\EcloudAccounts\Listeners\TwoFactorStateChangedListener; use OCA\EcloudAccounts\Listeners\UserChangedListener; use OCA\EcloudAccounts\Service\LDAPConnectionService; use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; -use OCA\OIDCLogin\Service\TokenService; use OCA\TwoFactorTOTP\Event\StateChanged; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; -use OCP\ISession; use OCP\IUserManager; -use OCP\IUserSession; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; @@ -69,14 +66,5 @@ class Application extends App implements IBootstrap { ); }); - $userSession = $serverContainer->get(IUserSession::class); - $session = $serverContainer->get(ISession::class); - $tokenService = $serverContainer->get(TokenService::class); - $accessTokenExpiresAt = $session->get('oidc_access_token_expires_at'); - $now = time(); - if ($now > $accessTokenExpiresAt) { - $tokenService->refreshTokens(); - } - } } -- GitLab From 9449d70ddc612a2267d3da7566d4083131c4646b Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 22 May 2024 17:41:36 +0530 Subject: [PATCH 19/21] removed snappy phasephase --- lib/Listeners/AccessTokenUpdatedListener.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 4e34aafe..4a8de49c 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -42,8 +42,6 @@ class AccessTokenUpdatedListener implements IEventListener { $username = $this->userSession->getUser()->getUID(); $this->session->set('snappymail-nc-uid', $username); - $this->session->set('snappymail-passphrase', SnappyMailHelper::encodePassword($accessToken, $username)); $this->session->set('oidc_access_token', $accessToken); - $this->session->set('snappymail-password', SnappyMailHelper::encodePassword($accessToken, $username)); } } -- GitLab From 483e9bd03da7200bf8466f9ee8a8c2059eb7a855 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 22 May 2024 18:29:17 +0530 Subject: [PATCH 20/21] lint fix --- lib/Listeners/AccessTokenUpdatedListener.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index 4a8de49c..f8d94d69 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent; -use OCA\SnappyMail\Util\SnappyMailHelper; use OCP\App\IAppManager; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -- GitLab From 9046a3e06d563b6b0476480f24d0f7c2376ad4f3 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 29 May 2024 22:06:56 +0530 Subject: [PATCH 21/21] removed access token as it already used in oidc app --- lib/Listeners/AccessTokenUpdatedListener.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Listeners/AccessTokenUpdatedListener.php b/lib/Listeners/AccessTokenUpdatedListener.php index f8d94d69..2edf5a3b 100644 --- a/lib/Listeners/AccessTokenUpdatedListener.php +++ b/lib/Listeners/AccessTokenUpdatedListener.php @@ -41,6 +41,5 @@ class AccessTokenUpdatedListener implements IEventListener { $username = $this->userSession->getUser()->getUID(); $this->session->set('snappymail-nc-uid', $username); - $this->session->set('oidc_access_token', $accessToken); } } -- GitLab