簡體   English   中英

Spring 集成:Microsoft Outlook oauth2

[英]Spring Integration: Microsoft Outlook oauth2

我有一個 spring 集成 java 應用程序,其流程配置如下:

        String emailStoreUri = emailProtocol + "://" + emailUsername + ":" + emailPassword + "@" + emailHost + ":" + emailPort + "/" + emailFolderInbox;

        return IntegrationFlows.from(Mail.imapInboundAdapter(emailStoreUri)
                .shouldMarkMessagesAsRead(emailShouldMarkMessagesAsRead)
                .simpleContent(true).maxFetchSize(msgPerPoll)
                .searchTermStrategy(new AcceptAllEmailStrategy())
                .javaMailProperties(p -> {
                    p.put("mail.store.protocol", emailProtocol);
                    p.put("mail.debug", emailDebug);
                    p.put("mail.imaps.timeout", "5000"); 
                    p.put("mail.imaps.connectionpoolsize", "1");
                    p.put("mail.imaps.connectiontimeout", "5000");
                    p.put("mail.imaps.connectionpool.debug","true");
                     p.put("mail.debug", "true");
                }).simpleContent(true),
                e -> e.autoStartup(emailAutoStart).poller(pollerMetadata))
                .channel(MessageChannels.rendezvous("inboundEmailChannel")).log("DEBUG").get();
    }

這只適用於 basi auth,如何修復讓這個 codw 與 OAUTH2 一起工作?

我正在網上搜索,但我沒有找到任何關於這個問題的信息

我以某種方式認為這也是您的 Gitter 問題: https://gitter.im/spring-projects/spring-integration?at=63ce9304624f3f4330280089

因此,要了解完整的上下文,請查看此 GH 問題: https://github.com/spring-projects/spring-integration-samples/issues/341

准確地說:您需要實現一個Authenticator來獲取針對用戶的 OAuth 令牌。 請隨意提出 GH 問題,因此我們將記錄這種方法。 雖然這與 Spring 集成無關 - 普通 Java 郵件功能 - 太多人在 Spring 集成上下文中詢問它。

這樣的Authenticator必須通過其屬性注入到ImapMailReceiver中:

/**
 * Optional, sets the Authenticator to be used to obtain a session. This will not be used if
 * {@link AbstractMailReceiver#setSession} has been used to configure the {@link Session} directly.
 * @param javaMailAuthenticator The javamail authenticator.
 * @see #setSession(Session)
 */
public void setJavaMailAuthenticator(Authenticator javaMailAuthenticator) {

不要忘記設置 Java 郵件mail.imap.auth.mechanisms=XOAUTH2屬性!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM