小编Vin*_*und的帖子

JavaMail 连接到 Office 365 XOAUTH2 进行 IMAP 身份验证失败

面对 OAuth2.0 在线 Office365 的连接问题,我已经设置了应用程序权限以及 IMAP 和 SMTP 连接。基本身份验证似乎工作正常。我相信 IMAP 已启用。我的应用程序配置为任何组织目录(任何 Azure AD 目录 - 多租户)中的帐户,并使用授予类型授权代码。

并添加了 委派的 Microsoft Graph 范围https://graph.microsoft.com/IMAP.AccessAsUser.All :添加了客户端范围

使用https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/authorize?response_type=code&client_id=1223&redirect_uri=http://localhost:5555请求 身份验证代码访问令牌请求https://login.microsoftonline。 com/{tenant}/oauth2/v2.0/token 请求的访问令牌,资源为“https://graph.microsoft.com”

请求访问令牌图像

已成功接收范围为 IMAP.AccessAsUser.All SMTP.Send 的访问令牌

{
    "token_type": "Bearer",
    "scope": "IMAP.AccessAsUser.All SMTP.Send",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "access_token",
    "refresh_token": "refresh_token",
    "id_token": "id_token"
} 
Run Code Online (Sandbox Code Playgroud)

这是Java代码(使用JavaMail jar 1.6.2)

Properties properties= new Properties();
properties.put("mail.imap.ssl.enable", "true");
properties.put("mail.imap.auth.mechanisms", "XOAUTH2");
//properties.put("mail.imap.sasl.enable", "true"); un-commented still results are same
properties.put("mail.imap.auth.login.disable", "true");
properties.put("mail.imap.auth.plain.disable", "true");
properties.put("mail.debug", "true");
properties.put("mail.debug.auth", "true");

Session …
Run Code Online (Sandbox Code Playgroud)

imap jakarta-mail azure oauth-2.0 office365

8
推荐指数
1
解决办法
8564
查看次数

标签 统计

azure ×1

imap ×1

jakarta-mail ×1

oauth-2.0 ×1

office365 ×1