You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR: I cannot get exchangelib to work with CBA, although oauth2 works.
I am already using exchangelib with oauth2, but would like to use certificates instead of tokens, because tokens have a limited lifetime.
I have researched related issues: #1183#1093#751 and Google.
Working unit test with oauth2:
fromexchangelibimportIMPERSONATION, OAUTH2, Account, Configuration, OAuth2Credentialsfromexchangelib.versionimportEXCHANGE_O365, VersionCLIENT_ID="xxx"CLIENT_SECRET="xxx"TENANT_ID="xxx"imap_host="outlook.office365.com"mailbox_user="[email protected]"# authenticate using OAUTH2credentials=OAuth2Credentials(
client_id=CLIENT_ID, tenant_id=TENANT_ID, client_secret=CLIENT_SECRET
)
# do not rely on autodiscover but specify explicit server nameconfig=Configuration(
server=imap_host, credentials=credentials,
version=Version(build=EXCHANGE_O365), auth_type=OAUTH2
)
deftest_exchange_connection(logger):
logger.info("Logging in to mailbox")
# see: https://github.com/ecederstrand/exchangelib/issues/735# use IMPERSONATION instead of DELEGATE: "ExchangeImpersonation SOAP header must be present for this type of OAuth token"my_account=Account(
primary_smtp_address=mailbox_user,
config=config, autodiscover=False, access_type=IMPERSONATION
)
logger.info(f"my_account.root.tree(): {my_account.root.tree()}")
assertmy_account.root.child_folder_count>0
I haven't tried CBA myself, and I have no easy way to test it myself, unfortunately. I have very little knowledge about how CBA workes, but is it possible that the certificate is valid but has not been granted access to EWS?
I don't think it's an exchangelib problem per se, but it could be that I am using it incorrectly.
The error code 401 makes me think that there is indeed something wrong with the cert.
With tokens, the lib works just fine:
I uploaded the certificate in the same app registration area:
And the app has all permissions:
I believe there is nothing more needed. I already use a Python MSAL lib and I was able to switch from tokens to certificates the same way, without any problem. But I will keep looking and post updates if I find anything interesting.
Hello,
TL;DR: I cannot get exchangelib to work with CBA, although oauth2 works.
I am already using exchangelib with oauth2, but would like to use certificates instead of tokens, because tokens have a limited lifetime.
I have researched related issues: #1183 #1093 #751 and Google.
Working unit test with oauth2:
Attempted unit test for CBA:
This results in a 401 error.
Relevant notes:
Is this the correct way or is there anything I should try?
Log below and thanks for looking.
The text was updated successfully, but these errors were encountered: