Skip to content

Commit

Permalink
[FIX]Error Ocurred when attempting Microsoft's email oauth2 setup
Browse files Browse the repository at this point in the history
  • Loading branch information
christer77 committed Nov 28, 2024
1 parent 437fae5 commit 48a816e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions config/oauth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
],
];
1 change: 1 addition & 0 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function get_oauth2_data($config) {
return [
'gmail' => $config->get('gmail',[]),
'outlook' => $config->get('outlook',[]),
'office365' => $config->get('office365',[]),
];
}}

Expand Down
3 changes: 3 additions & 0 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
1 change: 0 additions & 1 deletion modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ public function authenticate($username, $password) {
}
return $authed;
}


/**
* attempt starttls
Expand Down
4 changes: 2 additions & 2 deletions modules/nux/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
));

Expand Down
1 change: 0 additions & 1 deletion modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48a816e

Please sign in to comment.