From 48a816e46c9318accf9119b0fbd8aceefc3169fc Mon Sep 17 00:00:00 2001 From: christer kahasha <62720246+christer77@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:26:52 +0100 Subject: [PATCH] [FIX]Error Ocurred when attempting Microsoft's email oauth2 setup --- .env.example | 8 ++++++++ config/oauth2.php | 10 ++++++++++ modules/core/functions.php | 1 + modules/imap/functions.php | 3 +++ modules/imap/hm-imap.php | 1 - modules/nux/services.php | 4 ++-- modules/sievefilters/modules.php | 1 - tests/phpunit/modules/core/functions.php | 2 +- 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 899e8bab87..c51d242ae1 100644 --- a/.env.example +++ b/.env.example @@ -173,6 +173,14 @@ OUTLOOK_AUTH_URI=https://login.live.com/oauth20_authorize.srf OUTLOOK_TOKEN_URI=https://login.live.com/oauth20_token.srf OUTLOOK_REFRESH_URI=https://login.live.com/oauth20_token.srf +#office365 +OFFICE365_CLIENT_ID= +OFFICE365_CLIENT_SECRET= +OFFICE365_CLIENT_URI=http://localhost/?page=home +OFFICE365_AUTH_URI=https://login.live.com/oauth20_authorize.srf +OFFICE365_TOKEN_URI=https://login.live.com/oauth20_token.srf +OFFICE365_REFRESH_URI=https://login.live.com/oauth20_token.srf + #ldap.php LDAP_SERVER=localhost LDAP_ENABLE_TLS=true diff --git a/config/oauth2.php b/config/oauth2.php index 35c3912803..21f5a812cc 100644 --- a/config/oauth2.php +++ b/config/oauth2.php @@ -39,4 +39,14 @@ 'token_uri' => env('OUTLOOK_TOKEN_URI', 'https://login.live.com/oauth20_token.srf'), 'refresh_uri' => env('OUTLOOK_REFRESH_URI', 'https://login.live.com/oauth20_token.srf') ], + + //[office365] + 'office365' => [ + 'client_id' => env('OFFICE365_CLIENT_ID', ''), + 'client_secret' => env('OFFICE365_CLIENT_SECRET', ''), + 'client_uri' => env('OFFICE365_CLIENT_URI', 'http://localhost/?page=home'), + 'auth_uri' => env('OFFICE365_AUTH_URI', 'https://login.live.com/oauth20_authorize.srf'), + 'token_uri' => env('OFFICE365_TOKEN_URI', 'https://login.live.com/oauth20_token.srf'), + 'refresh_uri' => env('OFFICE365_REFRESH_URI', 'https://login.live.com/oauth20_token.srf') + ], ]; diff --git a/modules/core/functions.php b/modules/core/functions.php index bea403918b..d4bc8f80ba 100644 --- a/modules/core/functions.php +++ b/modules/core/functions.php @@ -255,6 +255,7 @@ function get_oauth2_data($config) { return [ 'gmail' => $config->get('gmail',[]), 'outlook' => $config->get('outlook',[]), + 'office365' => $config->get('office365',[]), ]; }} diff --git a/modules/imap/functions.php b/modules/imap/functions.php index 60bb98cd11..d2f4f82575 100644 --- a/modules/imap/functions.php +++ b/modules/imap/functions.php @@ -853,6 +853,9 @@ function imap_refresh_oauth2_token($server, $config) { elseif ($server['server'] == 'imap-mail.outlook.com') { $details = $oauth2_data['outlook']; } + elseif ($server['server'] == 'imap-mail.office365.com') { + $details = $oauth2_data['office365']; + } if (!empty($details)) { $oauth2 = new Hm_Oauth2($details['client_id'], $details['client_secret'], $details['client_uri']); $result = $oauth2->refresh_token($details['refresh_uri'], $server['refresh_token']); diff --git a/modules/imap/hm-imap.php b/modules/imap/hm-imap.php index dba860da47..96977849ac 100644 --- a/modules/imap/hm-imap.php +++ b/modules/imap/hm-imap.php @@ -320,7 +320,6 @@ public function authenticate($username, $password) { } return $authed; } - /** * attempt starttls diff --git a/modules/nux/services.php b/modules/nux/services.php index 39c97d0d91..c17ca633db 100644 --- a/modules/nux/services.php +++ b/modules/nux/services.php @@ -62,9 +62,9 @@ 'name' => 'Office365', 'scope' => 'wl.imap', 'smtp' => array( - 'server' => 'outlook.office365.com', + 'server' => 'smtp.office365.com', 'port' => 587, - 'tls'=> 'yes' + 'tls'=> false ) )); diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php index 35b1579310..9daf4565ba 100644 --- a/modules/sievefilters/modules.php +++ b/modules/sievefilters/modules.php @@ -1292,7 +1292,6 @@ function sieve_enabled_callback($val) { return $val; } class Hm_Output_enable_sieve_filter_setting extends Hm_Output_Module { protected function output() { $settings = $this->get('user_settings'); - // exit(var_dump($settings['enable_sieve_filter'])); if ((array_key_exists('enable_sieve_filter', $settings) && $settings['enable_sieve_filter']) || DEFAULT_ENABLE_SIEVE_FILTER) { $checked = ' checked="checked"'; $reset = ''; diff --git a/tests/phpunit/modules/core/functions.php b/tests/phpunit/modules/core/functions.php index 818cf4018e..a358f3f1f4 100644 --- a/tests/phpunit/modules/core/functions.php +++ b/tests/phpunit/modules/core/functions.php @@ -84,7 +84,7 @@ public function test_is_email_address() { */ public function test_get_oauth2_data() { $mock_config = new Hm_Mock_Config(); - $this->assertEquals(array('gmail' => [],'outlook' => []), (get_oauth2_data($mock_config))); + $this->assertEquals(array('gmail' => [],'outlook' => [],'office365' => []), (get_oauth2_data($mock_config))); } /** * @preserveGlobalState disabled