I'm trying to achieve the authentication for office 365 accounts by using oauth 2.0 , i'm using PublicClientApplication and InteractiveRequestParameters method for acquiring access token and in result successfully received access token ,refresh token and id token but when i am using access_token to connect to imap, i am getting error as authentication failure, can anyone please help me out what am i missing here.
have given all the required permissions from azure portal. here is my code through which i am trying to connect to server
store.connect("outlook.office365.com", "my_email_id, access_token); //here store is imap
properties i have set are: properties.put("mail.smtp.port", "587"); properties.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.setProperty("mail.imap.socketFactory.fallback", "false"); properties.setProperty("mail.imap.port", "993"); properties.setProperty("mail.imap.socketFactory.port", "993"); properties.put("incomingHost", "outlook.office365.com"); properties.put("mail.imap.ssl.enable", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("outgoingHost", "smtp.office365.com"); properties.setProperty("mail.imaps.ssl.trust", "*");
Note: when i am providing password instead of access_token , i am successfully able to login but failure while using access_token.
Thank you !!