你好,我有个邮件服务的功能需要升级认证方式为OAuth2.0,这需要我先注册一个应用程序,然后使用应用程序的参数获取token,我现在能够成功拿到token,但是在代码里面连接outlook的IMAP服务器的时候,依然告诉我连接失败,我不知道是不是我应用程序哪里的配置存在问题,能帮我看一下吗?以下是我的应用程序截图

应用程序的概念页面地址

我创建应用之后,首先设置了web回调地址为 http://localhost:9081/email/auth,然后新增证书和密码中的客户端密码,然后添加了API权限,我发现网上有很多帖子说会添加 office 3654 exchange online 下面的两个权限,但是我没有找到这个权限在哪里

以下是我的java代码:

1.获取token

2.获取邮件

我使用获取的token,使用IMAP连接服务器,依然无法成功认证:

jakarta.mail.AuthenticationFailedException: AUTHENTICATE failed.

以下是我的debug信息:

DEBUG: Jakarta Mail version 
DEBUG: URL jar:file:/E:/Soft%
DEBUG: successfully loaded resource: jar:file:/E:/Soft%
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers 
DEBUG: Tables of loaded providers 
DEBUG: Providers Listed By Class Name: {
DEBUG: Providers Listed By Protocol: {
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map 
DEBUG: URL jar:file:/E:/Soft%
DEBUG: successfully loaded resource: jar:file:/E:/Soft%
DEBUG: getProvider() returning jakarta.mail.Provider[
DEBUG IMAP: mail.imap.partialfetch: 
DEBUG IMAP: mail.imap.ignorebodystructuresize: 
DEBUG IMAP: mail.imap.statuscachetimeout: 
DEBUG IMAP: mail.imap.appendbuffersize: 
DEBUG IMAP: mail.imap.minidletime: 
DEBUG IMAP: enable STARTTLS 
DEBUG IMAP: peek 
DEBUG IMAP: closeFoldersOnStoreFailure 
DEBUG IMAP: protocolConnect returning 
DEBUG IMAP: trying to connect to host 
											

谢谢你的建议,我尝试将scope变更为:https://outlook.office.com/.default之后,成功拿到了一个access_token,但是使用此token依旧会提示jakarta.mail.AuthenticationFailedException: AUTHENTICATE failed.,以下是我的报错信息:

DEBUG: Jakarta Mail version 
DEBUG: URL jar:file:/E:/Soft%
DEBUG: successfully loaded resource: jar:file:/E:/Soft%
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {
DEBUG: Providers Listed By Protocol: {
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: URL jar:file:/E:/Soft%
DEBUG: successfully loaded resource: jar:file:/E:/Soft%
DEBUG: getProvider() returning jakarta.mail.Provider[
DEBUG IMAP: mail.imap.partialfetch: 
DEBUG IMAP: mail.imap.ignorebodystructuresize: 
DEBUG IMAP: mail.imap.statuscachetimeout: 
DEBUG IMAP: mail.imap.appendbuffersize: 
DEBUG IMAP: mail.imap.minidletime: 
DEBUG IMAP: enable STARTTLS
DEBUG IMAP: peek
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: protocolConnect returning 
DEBUG IMAP: trying to connect to host 
* OK The Microsoft Exchange IMAP
* CAPABILITY IMAP
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: XOAUTH
DEBUG IMAP: protocolConnect login, host=outlook.office
DEBUG IMAP: IMAPStore cleanup, not connected
Exception in thread 
    at jodd.mail.MailSession.open(MailSession.java:
    at jodd.mail.ReceiveMailSession.open(ReceiveMailSession.java:
    at com.guyi.demo.ImapReceiveTest.main(ImapReceiveTest.java:
Caused by: jakarta.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:
    at jakarta.mail.Service.connect(Service.java:
    at jakarta.mail.Service.connect(Service.java:
    at jakarta.mail.Service.connect(Service.java:
    at jodd.mail.MailSession.open(MailSession.java:
jakarta.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:
    at jakarta.mail.Service.connect(Service.java:
    at jakarta.mail.Service.connect(Service.java:
    at jakarta.mail.Service.connect(Service.java:
    at jodd.mail.MailSession.open(MailSession.java:
    at jodd.mail.ReceiveMailSession.open(ReceiveMailSession.java:
    at com.guyi.demo.ImapReceiveTest.main(ImapReceiveTest.java:

我在官方文档
https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth

注意到在给应用程序赋予API权限时会分配office 365 exchange online 下的两个API权限,但是我在我的应用程序中并没有找到office 365 exchange online,不知道问题是不是出在了这里