How to use OAuth 2 authentication with camel-mail

Viewed 358

I'am using camel-mail plugin to read emails using IMAP and it working perfectly.

But more and more email providers are deprecation / disabling basic authentication to replace it by OAuth 2.0 token-based authorization.

Examples :

From Microsoft Exchange: Deprecation of Basic authentication in Exchange Online

We're removing the ability to use Basic authentication in Exchange Online for Exchange ActiveSync (EAS), POP, IMAP, ect.

Is there a way to use OAuth 2 with camel-mail? is there another solution?

Thank's for your help

3 Answers

Apache camel has authenticator feature to customize authentication. There is a default Authenticator class, you need to extend it and override getPassword method. GetPassword should return the access token instead of plain password. You can bind your custom authenticator to your context and you just need to call from your endpoint like

<from uri="imaps://outlook.office365.com?username=XYZ@DOMAIN.COM&authenticator=#yourCustomAuthenticator>

You need to do the following steps as well:

  • Disable plain auth with the following property on your "from" endpoint: mail.imap.auth.plain.disable=true

  • Enable oauth with the following property:

    mail.imap.auth.xoauth2.disable=false

Camel will automatically call imap login with access token (base64(auth=Bearer adfdfdf)).

You can use Camel-Box to read emails using OAuth 2.

I think you have to use the authenticator parameter of the camel mail component and implement your own OAuth2 MailAuthenticator. Looks a bit clumpy that an implementation is needed for this.

Related