Hello @HR Admin , OAuth integration requires your application to use SASL XOAUTH2 format to encode and transmit the access token. SASL XOAUTH2 encodes the username, access token together in the following format:
base64("user=" + userName + "^Aauth=Bearer " + accessToken + "^A^A")
^A
represents a Control + A (%x01
).
For example, the SASL XOAUTH2 format to access test@contoso.onmicrosoft.com
with access token EwBAAl3BAAUFFpUAo7J3Ve0bjLBWZWCclRC3EoAA
is:
base64("user=test@contoso.onmicrosoft.com^Aauth=Bearer EwBAAl3BAAUFFpUAo7J3Ve0bjLBWZWCclRC3EoAA^A^A")
In Python you would do something like this (auth_string is not base64 encoded in the samples I found which make me guess the authenticate method will encode it. If that's not the case then proceed to encode it with base64.b64encode(auth_string)
)
auth_string = 'user=%s\1auth=Bearer %s\1\1' % (username, access_token)
imap_conn.authenticate('XOAUTH2', lambda x: auth_string)
Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing similar issues can more easily find a solution.