最近宣布支持 Exchange Online 中的 IMAP 和 SMTP 的 OAuth 2.0。按照指南,我设置了应用程序权限以及 IMAP 和 SMTP 连接。应用程序配置为Accounts in any organizational directory (Any Azure AD directory - Multitenant)并使用授权代码流。
以下 URL 用于授权:
并且添加了以下委派 Microsoft Graph 范围:
范围,来自代码的请求:
final List<String> scopes = Arrays.asList(
"offline_access",
"email",
"openid",
"profile",
"User.Read",
"Mail.ReadWrite",
"https%3A%2F%2Foutlook.office365.com%2FIMAP.AccessAsUser.All",
"https%3A%2F%2Foutlook.office365.com%2FSMTP.Send"
);
Run Code Online (Sandbox Code Playgroud)
我成功收到访问和刷新令牌:
{
"token_type": "Bearer",
"scope": "email IMAP.AccessAsUser.All Mail.ReadWrite openid profile SMTP.Send User.Read",
"expires_in": 3599,
"ext_expires_in": 3599,
"access_token": "edited",
"refresh_token": "edited",
"id_token": "edited"
}
Run Code Online (Sandbox Code Playgroud)
这是用于连接到 …