From 8783d20f835a6a49ca68b768cae8ed66f7c9f1ea Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 13 Nov 2025 16:58:31 +0100 Subject: [PATCH 1/4] fix(oauthimap): unable to save authorization code with Azure OAuth --- inc/application.class.php | 2 +- inc/provider/azure.class.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/application.class.php b/inc/application.class.php index 71dbcd1..6928c4e 100644 --- a/inc/application.class.php +++ b/inc/application.class.php @@ -534,7 +534,7 @@ private static function getProviderScopes(string $provider): array switch ($provider) { case Azure::class: $scopes = [ - 'openid', 'email', // required to be able to fetch owner details + 'openid', 'profile', 'email', // required to be able to fetch owner details 'offline_access', 'https://outlook.office.com/IMAP.AccessAsUser.All', ]; diff --git a/inc/provider/azure.class.php b/inc/provider/azure.class.php index 552fd82..f19fc12 100644 --- a/inc/provider/azure.class.php +++ b/inc/provider/azure.class.php @@ -56,6 +56,8 @@ public function getOwnerDetails(AccessToken $token): ?OwnerDetails $owner_details->email = $email; } elseif (($upn = $owner->claim('upn')) !== null) { $owner_details->email = $upn; + } elseif (($preferred_username = $owner->claim('preferred_username')) !== null) { + $owner_details->email = $preferred_username; } $owner_details->firstname = $owner->getFirstName(); $owner_details->lastname = $owner->getLastName(); From 7f82ea15c73d1073bf40451efd672d0e21907961 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 13 Nov 2025 17:08:12 +0100 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a16b0d1..ceb31e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +## Fix + +- Fix authorization code with Azure OAuth + ## [1.5.0] - 2025-09-29 ### Added From 57066ffc866998921af6af5d08a5a4758ee4c747 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 14 Nov 2025 16:11:18 +0100 Subject: [PATCH 3/4] add comment --- inc/application.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/inc/application.class.php b/inc/application.class.php index 6928c4e..9af392a 100644 --- a/inc/application.class.php +++ b/inc/application.class.php @@ -534,9 +534,11 @@ private static function getProviderScopes(string $provider): array switch ($provider) { case Azure::class: $scopes = [ - 'openid', 'profile', 'email', // required to be able to fetch owner details - 'offline_access', - 'https://outlook.office.com/IMAP.AccessAsUser.All', + 'openid', // OpenID Connect authentication + 'profile', // Required to get 'preferred_username' claim when 'email' is not available + 'email', // Required to get user email address + 'offline_access', // Required to get refresh token + 'https://outlook.office.com/IMAP.AccessAsUser.All', // IMAP access ]; break; case Google::class: From c4692ad4b3a8699bf30da2e71a3056c7e17d301d Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 17 Nov 2025 15:33:17 +0100 Subject: [PATCH 4/4] review --- inc/provider/azure.class.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/inc/provider/azure.class.php b/inc/provider/azure.class.php index f19fc12..ad4f41c 100644 --- a/inc/provider/azure.class.php +++ b/inc/provider/azure.class.php @@ -52,13 +52,10 @@ public function getOwnerDetails(AccessToken $token): ?OwnerDetails $owner = $this->getResourceOwner($token); $owner_details = new OwnerDetails(); - if (($email = $owner->claim('email')) !== null) { - $owner_details->email = $email; - } elseif (($upn = $owner->claim('upn')) !== null) { - $owner_details->email = $upn; - } elseif (($preferred_username = $owner->claim('preferred_username')) !== null) { - $owner_details->email = $preferred_username; - } + $owner_details->email = + $owner->claim('email') ?? + $owner->claim('upn') ?? + $owner->claim('preferred_username'); $owner_details->firstname = $owner->getFirstName(); $owner_details->lastname = $owner->getLastName();