Skip to content

Commit

Permalink
Merge pull request #1348 from christer77/Microsoft-email-Error-Ocurre…
Browse files Browse the repository at this point in the history
…d-when-attempting-gmail-oauth2-setup

fix(cypht): error ocurred when attempting microsoft's email oauth2 setup
  • Loading branch information
kroky authored Dec 13, 2024
2 parents b632b81 + e96468a commit 15ff855
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 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 @@ -250,6 +250,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 @@ -852,6 +852,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
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 15ff855

Please sign in to comment.