Hello @KevinTheJedi
I would like to confirm I got this to work by updating the scopes, V2.0 API and email attribute in the plugin. In fact the outlook.office365.com URLs/API had to be used instead of Graph.
class MicrosoftEmailOauth2Provider extends GenericOauth2Provider {
static $id = 'oauth2:msmail';
static $name = 'OAuth2 - Microsoft';
static $defaults = [
'urlAuthorize' => 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize',
'urlAccessToken' => 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',
'urlResourceOwnerDetails' => 'https://outlook.office.com/api/v2.0/me',
// scopes for offline access & mail (IMAP, POP & SMTP)
'scopes' => 'offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/POP.AccessAsUser.All https://outlook.office.com/SMTP.Send',
'attr_username' => 'EmailAddress', // This was "mail" before
'attr_email' => 'EmailAddress', // This was "mail" before
'attr_givenname' => 'givenname',
'attr_surname' => 'surname',
];
static $urlOptions = [
'tenant' => 'common',
'accessType' => 'offline_access',
];
}
With the https://outlook.office.com/api/v2.0/me API the email attribute is "EmailAddress" (https://outlook.office.com/api/v2.0/$metadata)
I must admit this is really confusing by Microsoft, if you use the new Graph API/scopes at all the IMAP authentication won't work (even though you successfully get an access token, but imap auth fails with "NO AUTHENTICATION FAILED"). Yet they announced the outlook.office365.com APIs will be decommissioned in November...
Edit, related issues:
https://github.com/MicrosoftDocs/office-developer-exchange-docs/issues/87#issuecomment-628590496
https://github.com/MicrosoftDocs/office-developer-exchange-docs/issues/100#issuecomment-847845126