简体   繁体   中英

Spring Integration: Microsoft Outlook oauth2

i've a spring integration java application with a flow configured like this:

        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();
    }

This just work for basi auth, how to fix to let this codw work with OAUTH2?

I'm searching online but i didn't find anything about this problem

I somehow think that this is your Gitter question as well: https://gitter.im/spring-projects/spring-integration?at=63ce9304624f3f4330280089 .

So, to have a full context over here, please, look into this GH issue: https://github.com/spring-projects/spring-integration-samples/issues/341 .

To be precise: you need to implement an Authenticator to obtain OAuth token against the user. Feel free to raise a GH issue, so we will document this approach. Although this has nothing to do with Spring Integration - plain Java Mail feature, - too many people are asking it in Spring Integration context.

Such an Authenticator has to be injected into an ImapMailReceiver via its property:

/**
 * 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) {

Don't forget to set Java Mail mail.imap.auth.mechanisms=XOAUTH2 property!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM