rpaframework icon indicating copy to clipboard operation
rpaframework copied to clipboard

Add MFA support to RPA.Exchange.Email

Open AllanMedeiros opened this issue 2 years ago • 1 comments

Library RPA.Exchange.Email can't connect to Outlook Exchange server that has MFA enforced and gives just connection errors. The idea is to implement oauth support to retrieve the OTP number from another library like https://github.com/pyauth/pyotp.

AllanMedeiros avatar Aug 10 '22 13:08 AllanMedeiros

More context here on this Slack thread. https://robotframework.slack.com/archives/C0115TMTADC/p1649872794578149

AllanMedeiros avatar Aug 10 '22 13:08 AllanMedeiros

This got solved, here's an official Portal robot example on how to do it.

cmin764 avatar Sep 19 '22 12:09 cmin764

Hi @cmin764 , how can I use the OTP code on Authorize kw to login on Exchange email server?

AllanMedeiros avatar Sep 26 '22 12:09 AllanMedeiros

I believe to have set everything right and when calling Authorize kw I get this error: KeyError: 'access_token'

AllanMedeiros avatar Sep 27 '22 13:09 AllanMedeiros

Also, when I add "Library OAuth2" to my settings, I get this error: Importing library 'OAuth2' failed: ModuleNotFoundError: No module named 'OAuth2'

AllanMedeiros avatar Sep 27 '22 13:09 AllanMedeiros

Hi there @AllanMedeiros ,

RPA.Email.Exchange.Authorize is designed to work with one of these two:

  • App Password, passed with password=. (recommended and easy, MFA is required to be enabled on the account first)
  • OAuth2, which is most secure, enabled with is_oauth=${True} client_id=... client_secret=... token=.... (this is a complex flow, you have to self-educate on this to understand what you're doing)

Here's a full Portal example you have to copy-paste into your robot (including the OAuth2.py library inside the root dir) before being able to use it. Please read all the instructions with maximum attention to the details, as you need to follow all the steps described in the README.


On the MFA side, we have another example which simply browser-automates the login flow with Selenium.

For more inquiries regarding the library, please use our forum instead.

cmin764 avatar Sep 30 '22 08:09 cmin764