我在Java8中有一个后台任务,它应该使用OAuth 2.0读取和处理MS 365邮件文件。
A)任务正在使用“客户端凭据”。安装程序严格遵循
https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth
B)访问令牌是使用
终点:https://login.microsoftonline.com/11111111-2222-3333-4444-55555555555555/oauth2/v2.0/token
范围:https://outlook.office365.com/.default
应用程序ID和密码看起来是正确的,因为身份验证服务器返回了一个有效的访问令牌,该令牌可以被base-64解码为有效的JSON JWT。
C)下面的Javamail connect()使用步骤B)中的访问令牌而不是标准密码连接到“outlook.office365.com:993”时返回“A1 NO AUTHENTICATE failed”
Mail property mail.imaps.auth.login.disabe: true
Mail property mail.imaps.auth.plain.disable: true
Mail property mail.debug.auth.password: false
Mail property mail.mime.ignoreunknownencoding: true
Mail property mail.imaps.port: 993
Mail property mail.imaps.sasl.mechanisms: XOAUTH2
Mail property mail.store.protocol: imaps
Mail property mail.imaps.ssl.enable: true
Mail property mail.imaps.partialfetch: false
Mail property mail.mime.decodetext.strict: false
Mail property mail.debug.auth: true
Mail property mail.imaps.peek: true
Mail property mail.imaps.sasl.enable: true
DEBUG: setDebug: Jakarta Mail version 1.6.7
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.partialfetch: false
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable SASL
DEBUG IMAPS: SASL mechanisms allowed: XOAUTH2
DEBUG IMAPS: peek
DEBUG IMAPS: closeFoldersOnStoreFailure
DEBUG IMAPS: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [WgBSADAAUAAyADcAOABDAEEAMAAwADkAMAAuAEMASABFAFAAMgA3ADgALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, user=xxx@xxx.com, password=<non-null>
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS: XOAUTH2
DEBUG IMAPS:
DEBUG IMAPS: SASL client XOAUTH2
DEBUG IMAPS: SASL callback length: 2
DEBUG IMAPS: SASL callback 0: javax.security.auth.callback.NameCallback@e2e750a
DEBUG IMAPS: SASL callback 1: javax.security.auth.callback.PasswordCallback@8765a5d1
A1 AUTHENTICATE XOAUTH2
dXNlcj1h ... (Valid Token) ... AQ==
A1 NO AUTHENTICATE failed.
调试日志中的身份验证字符串(由JavaMail生成)正确解码为“user=xxx@xxx.com auth=Bearer“格式,后跟访问标记。
如果访问令牌看起来有效,什么原因会导致“NO AUTHENTICATE”错误?
谢谢你的帮助安迪·布伦纳
1条答案
按热度按时间bybem2ql1#
问题已解决:
PowerShell命令与“应用程序注册”屏幕的对象ID一起使用。
但对象ID必须从企业应用程序中获取。