Oauth Office 365 and email collector

Hi,
I have a problem with OAuth services andemail collector. I generate the token but when I try to login in email collector I receive this error:

TAG1 AUTHENTICATE XOAUTH2 dX_blabla << NO AUTHENTICATE failed.

I tryed with differents scope outlook.office365 / outlook.office.com /graph.microsoft.com

Sign in to Outlook

But I still have the same issue…

Any suggestion??

Please let me know if i do something wrong.

Dolibarr version: 17.0 / PHP 7.4 or 8.1 is the same

I am also having problems with oauth2, spending hours and receiving auth problems, my installation of dolibarr was a step by step installation “dolibarr installation and hardening” and i found some problems with my php restrictions, another reason could be problems with the returning “url”, it cost me in the end too much time and not enough help or information on the internet.
I will be installing a test system in the near future where i can open all security settings, hopefully i find a solution.

Hi, me too. I spend a tons of hour to tried… but yesterday a glimpse of light… :partying_face:

premise: i’m not a programmer or developer of dolibarr… so I think it’s better to involve these persons…

Some article and test and test and test and test could be solve the problem…

interesting documentation:

https://blog.icewolf.ch/archive/2022/12/17/exchange-online-pop-and-imap-oauth-2-0-client-credentials.aspx

https://blog.icewolf.ch/archive/2022/12/20/exchange-online-other-ways-of-testing-imap-oauth2-client-credential.aspx

Based on these articles now oauth works…

I share with you the code to test in the hope that the real developer try to fix the problem… I don’t know if it’s correct the workaround but it works…

/core/lib/oauth.lib.php line 35:

$supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array('callbackfile' => 'microsoft', 'picto' => 'microsoft', 'urlforapp' => 'OAUTH_MICROSOFT_DESC', 'name'=>'Microsoft', 'urlforcredentials'=>'https://portal.azure.com/', 'availablescopes'=>'openid,offline_access,profile,email,User.Read,https://outlook.office.com/.default,https://outlook.office.com/.default', 'returnurl'=>'/core/modules/oauth/microsoft_oauthcallback.php');

/includes/OAuth/OAuth2/Service/Microsoft.php lines: 41 42

    const SOCPE_IMAP_ACCESSASUSERALL = 'https://outlook.office.com/.default';
    const SOCPE_SMTPSEND = 'https://outlook.office.com/.default';

I didn’t try to send an email… but the collector now works… sorry… but this is my personal fresh solution… I didn’t have time to try…
in the next days i’ll try

I tried your solution, but no luck, i am not sure about the scopes, in my azure i have Microsoft Graph an Office 365 Exchange Online, my App ist registered as WEB App and the API Scope looks like

“https: // ps.outlook. com / IMAP.AccessAsApp”

are these two files the only you changed?

/core/lib/oauth.lib.php line 35:
/includes/OAuth/OAuth2/Service/Microsoft.php lines: 41 42

Hi,
attached my scopes:

I forgot 1 passage:
in OAuth services I cofigure the permissions like the picture:

Another important things:
in Microsoft Azure inside Owner add your account if you are not admin.

If you still have a problem, please enable the debug ($debug = true; in Protocol.php file) and send me the error… I’ll try to help you

Ciao!

Ciao!
I’m busy but I tried with a fresh dolibarr installation (even 17.01).

I confirm: my solution works with office365 and email collector. I tried to send some email and it’s works.

Please if someone have my same issues please try my solution and if it works I suggest to developer of dolibarr to solve defenetily this bug.

Hi,
i will try again tomorrow with the debug option.
I am confused, becaus the token arrives, no problem, but get, setup authentication error, while collecting test.

i do not believe what happend

My Problem disappeared while removing not needed scopes, now it is collecting mails.

1 Like

Hi Plows,

Great that you got this to work. I used your setup to get it to work for me too (using dolibarr 17.01). It seems I’m almost there. OAuth2 works. Token is automatically renewed. That seems all good.

However, when I try the “Test collection” (from the module setup page) it redirects me to this page:
https://{my website}/admin/emailcollector_card.php?id=6&action=collecttest&token={myToken}

This throws a http 500 “{myWebsite} is currently unable to handle this request.” error. Have you noticed this as well? Does the test option work for you?

Hi,
i have the same redirection but no error, was the collector working before?

Hi guys,

i followed your instructions but it wont work.
If i try to send mails i get this error:
Fehler beim Senden der E-Mail (Absender=Robert Steinbacher steinbacher@sit-edv.de, Empfänger=steinbacher@sit-edv.de)
Error [120]: Ran into problems sending Mail. Response: 535 5.7.3 Authentication unsuccessful [XXXXXX.OUTLOOK.COM 2023-06-21T11:29:03.190Z 08DB71B1AD081F9E] Error [130]: Error when asking for AUTH XOAUTH2 Error [130]: Invalid Authentication Credentials.

When i try to receive mails theres is no error but when i count mails in source this error appears:
failed to refresh access token

if anyboy has it working and when how?

here is my config

Apologies for my delayed response. I’m only working on this for 1 day a week and had to work on other stuff first.

No, it hasn’t worked before yet. What I don’t understand is that if I navigate to the page itself it exists and there is no error.

By the way, I noticed in the file htdocs>includes>OAuth>OAuth2>Service>Microsoft.php that there are some SCOPE constants with the wrong name: the name starts with SOCPE instead of SCOPE. This is the case for the constants IMAP_ACCESSASUSERALL, SMTPSEND, USERREAD, MAILREAD, and MAILSEND. In the ServiceFactory it checks the provided scopes against the defined scopes, so the scopes above will never be resolved, correct?

If you are not able to send but only receive you have to follow this step:

Sending is now working very fine. just receiving isnt working. i corrected the SCOPE in htdocs>includes>OAuth>OAuth2>Service>Microsoft.php as mentioned
I am a little confused because i get an error in the collector when i check the mails in folder. it returns: Failed to refresh access token:

Hi,
i have a different Configuration

Hi,
the scope or socpe is not the problem. Please follow my “tutorial” and please check the scopes inside Microsoft Azure

Hi Jan,
i have the same Problem now, did you solve your http 500 error?

Hi,
i believe there are some PHP problems, this morning i installed the beta 19.0.0 (XAMPP - PHP 8.1.17) as a test version, now the mails are coming in again (some PHP Warnings), as before (Version 17.0.1 with Ubuntu PHP 7.4.33).
Sending was in all Versions never a Problem

@Plows and @FAdo84 Can you paste a screenshot of the setup you have for your the scopes in OAuth entry setup with the v19 ?
Do you use a different Oauth entry for sending/smtp ? If yes, can you also paste the one you have that work correctly with v19 ?