使用OAuth令牌连接到Exchange imap时,Javamail OAuth身份验证失败

时间:2015-11-19 18:03:15

标签: oauth outlook javamail exchange-server

我尝试使用Javamail和OAuth连接到Exchange。我使用的是Javamail 1.5.3,我提到了this

1)我尝试连接的交换帐户位于组织域内。我知道我的OAuth令牌有效,因为我能够向https://outlook.office.com/api/v2.0/me发出Rest api请求以使用令牌获取用户配置文件。我的代码看起来像这样 -

Properties props = new Properties();
props.put("mail.imap.ssl.enable", "true);
props.put("mail.imap.sasl.enable", "true");
props.put("mail.imap.sasl.mechanisms", "XOAUTH2");
props.put("mail.imap.auth.login.disable", "true");
props.put("mail.imap.auth.plain.disable", "true");
Session session = Session.getInstance(props);
Store store = session.getStore("imap");
store.connect("imap-mail.outlook.com", "xxx@org.com", OAUTH_TOKEN);

我得到(javax.mail.AuthenticationFailedException)javax.mail.AuthenticationFailedException:[AUTHENTICATIONFAILED] OAuth身份验证失败

2)当我连接到xxx@outlook.com帐户时,我收到500:内部服务器错误,我无法使用上面的api请求使用我收到的OAuth令牌获取用户配置文件。

0 个答案:

没有答案