How to access to a shared mail box using Oauth2 with Java

Anonymous
2022-04-27T08:11:26.497+00:00

I'm trying to access a shared mailbox using an Oauth2 and IMAP Protocol, but I have an error saying that the authentification have failed.

Note that I have successfuly connected to my user mailbox (user@harsh.com .com) with a token previously retrieved. But now, I have an issue with trying to connect to my shared mailbox.

Any ideas of how we can access a shared mailbox when it come to an Oauth2 protocol?

In my code Java, I set an object Properties:

Properties props = new Properties();
props.put("mail.imap.ssl.enable", "true");
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put("mail.imap.auth.login.disable", "true");
props.put("mail.imap.auth.plain.disable", "true");
props.put("mail.debug", "false");
props.put("mail.debug.auth", "false");
System.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true");
System.setProperty("mail.mime.multipart.allowempty", "true");
props.setProperty("mail.imaps.auth.ntlm.disable", "true");

and I'm trying to connect after getting my session:

Session session = Session.getInstance(props);
final Store store = session.getStore("imaps");
store.connect(serveur, 993, "user@harsh.com .com/shared_mail_box", accessToken);

But the authentification have failed when I added my (/shared_mail_box) to access my shared mail box, in contrary when I use only my user account (user@harsh.com .com).

Thank you!

Exchange | Exchange Server | Development
Microsoft Security | Microsoft Authenticator
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.