-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft 365 OAUTH2 authentication workflow no longer works #9598
Comments
Hello, I think I have the same problem, but with a specific Tenant ID for my organization. I need Microsoft 365 login only in order to check another IMAP server. I think it should be possible. OS, PHP and Roundcube versionsOS: Ubuntu noble numbat 24.04.1 LTS Here follows my conf
Error log
|
@feroda You've included logs from two requests above. For your request 2rn7mnha, I'm guessing you tried to reload the page you were redirected to after authenticating in Microsoft's oauth login form - it would have sent a authorization grant token back to your roundcube instance that roundcube tried to redeem for an access token, but since you've already used the authorization grant token in a previous page load, it refuses to grant a new access token. The second request cnj94rgr is the same issue I was facing, the Invalid audience error is due to using scopes with the namespace https://outlook.office365.com instead of https://graph.microsoft.com to try to access the graph API. I was able to get my code to work by modifying the roundcube source as follows: config/defaults.inc.php
config/config.inc.php
prorgam/include/rcmail_oauth.php
In summary, the above changes:
I'll try to create a branch and a pull request at some point, running a bit low on time at the moment. |
Hello, at the end I had time to manage it working now. I have tried you solution @lambjs but it hasn't fit my needs. My problem is that I had not setup xoauth2 authentication in dovecot! So, in order to recap, I have followed the doc at https://github.com/roundcube/roundcubemail/wiki/Configuration:-OAuth2#prerequisites And I have configured the xoauth2 auth_mecanism in dovecot with the Microsoft Identity Platform in the backend so, from: https://doc.dovecot.org/2.3/configuration_manual/authentication/oauth2/ (@alecpl maybe you can add this link to the Oauth2 doc in requeirements as an example...) Just for the sake of completeness/SEO, CommonIn dovecot.conf put
BackendConfiguration file example for Microsoft Identity Platform https://learn.microsoft.com/en-us/entra/identity-platform/userinfo
thank you all guys |
@feroda I think I missed the fact that while you were hoping to use O365 for identity management, but you had set localhost as the server for IMAP and SMTP:
Seems like you're not intending to use M365 for incoming/outgoing services at all, just as an identity service (referencing the Graph backend), and using your local Dovecot server for sending/receiving mail. This is interesting and may be useful for select use cases, but I think the idea of setting up your relay falls outside the scope of Roundcube's OAUTH typical configuration. Is there a reason you wouldn't just use the following to skip the relay and go directly to 365 servers?
|
Prerequisites
Describe the issue
I may be doing something wrong here, but my attempts to get IMAP XOAUTH2 authentication working for a tenant in Microsoft 365 have failed on a new install. I'll provide a sample of my configuration below.
I can confirm that I have configured my application in Entra to include the requisite Graph API delegated permissions. I've also configured my scope for Multitenant without personal accounts ie. the Manifest for my application in Entra admin center shows "signInAudience": "AzureADMultipleOrgs". I've seen some other forums mention that this is required and it won't work with other SignInAudience values? Is this true, and if so, should it be added to the example configuration in defaults.inc.php?
When I connect with the above configuration, I get an incorrect audience error when attempting to fetch user details from the identity uri (graph.microsoft.com). When I use the graph namespace instead, I get "NO AUTHENTICATION failed." during IMAP login.
I created my own minimal oauth 365 proof of concept to see if I could rule out roundcube as the problem. Based on my findings, and skipping the identity uri call using the same scope as above, I was able to get imap auth working.
I think the problem may be that you cannot (can no longer? maybe this restriction was added recently?) use the same token on two different 365 resources. If you fetch a token that has scopes which are allowed to call the graph endpoint (prefixed with https://graph.microsoft.com), then the token fails for IMAP/SMTP. If you fetch a token which is allowed to authenticate for IMAP/SMTP (prefixed with https://outlook.office365.com), then the token fails for graph calls.
See this article:
https://stackoverflow.com/questions/48579143/one-or-more-scopes-are-not-compatible-with-each-other-error-when-retrieving-ac/48584417#48584417
The above url sounds like a similar issue, but with OneDrive and the 365 API instead of Graph and 365? It appears that you could make a call to the graph endpoint using graph scopes, then refresh the token with 365 scopes and use it for subsequent imap/smtp authentication. You would need to be able to define in config optional separate scopes for the identity fetch step, and then implement support for switching scopes after identity fetch is completed.
Can someone verify that this is a problem and I haven't missed something fundamental? If so, I think I can roll a pull-request that would fix by making updates to defaults.inc.php, rcube_imap_generic.php and rcmail_oauth.php.
What browser(s) are you seeing the problem on?
Chrome
What version of PHP are you using?
v8.0
What version of Roundcube are you using?
v1.5.8
JavaScript errors
No response
PHP errors
When Graph works:
20-Aug-2024 18:52:28 +0100]: IMAP Error: Login failed for --SNIP-- against outlook.office365.com from --SNIP--. AUTHENTICATE XOAUTH2: A0001 NO AUTHENTICATE failed. in /var/www/program/lib/Roundcube/rcube_imap.php on line 211 (GET /index.php/login/oauth?code=...
When Graph fails:
[20-Aug-2024 22:09:03 +0100]: PHP Error: OAuth token request failed: Client error:
GET https://graph.microsoft.com/v1.0/me
resulted in a401 Unauthorized
response:{"error":{"code":"InvalidAuthenticationToken","message":"Access token validation failure. Invalid audience.","innerError (truncated...)
; eb9d0294d4de GuzzleHttp/6.5.5 curl/7.68.0 PHP/8.0.30 - [20/Aug/2024:22:09:03 +0100] "GET /v1.0/me HTTP/1.1" 401 in /var/www/html/program/include/rcmail_oauth.php on line 317 ...
The text was updated successfully, but these errors were encountered: