在Python中,必须出现这种类型的Oauth soap标头

发布于 2025-02-13 13:46:44 字数 1224 浏览 1 评论 0 原文

最近,Microsoft撤回了用于访问Exchange服务的基本身份验证服务。因此,我正在努力将身份验证从基本的基于OAUTH转换为基于OAUTH。但是,在测试过程中,我遇到以下例外。

  File "/usr/local/lib/python3.6/site-packages/exchangelib/services/common.py", line 423, in _raise_soap_errors
    raise vars(errors)[code](msg)
exchangelib.errors.ErrorInvalidExchangeImpersonationHeaderData: ExchangeImpersonation SOAP header must be present for this type of OAuth token.

我浏览了此处提到的建议 https://github.com/eceders.com/ecedersstrand/ecederstrand/exchangelib/exchangelib/sissues/735555 解决问题,但没有运气解决问题。

#实现有关

redentials = OAuth2Credentials(
            client_id=self.client_id, client_secret=self.client_secret, tenant_id=self.tenant_id,
            identity=Identity(smtp_address=self.email_address)
        )
        log.info(f"Credentials ==>{credentials}")
        config = Configuration(server=self.email_server, credentials=credentials,  auth_type=OAUTH2,  version=Version(build=EXCHANGE_O365))
        self.account = Account(self.email_address, access_type=DELEGATE, config=config)

解决上述例外的任何建议都是很大的帮助。提前致谢

Recently Microsoft has withdrawn the basic authentication service for accessing the Exchange Service. Therefore I am working on switching the authentication from basic to OAuth based. However, during the testing, I come across the below exception.

  File "/usr/local/lib/python3.6/site-packages/exchangelib/services/common.py", line 423, in _raise_soap_errors
    raise vars(errors)[code](msg)
exchangelib.errors.ErrorInvalidExchangeImpersonationHeaderData: ExchangeImpersonation SOAP header must be present for this type of OAuth token.

I went through the suggestions mentioned here https://github.com/ecederstrand/exchangelib/issues/735 for solving but had no luck solving the issues.

#Implementation

redentials = OAuth2Credentials(
            client_id=self.client_id, client_secret=self.client_secret, tenant_id=self.tenant_id,
            identity=Identity(smtp_address=self.email_address)
        )
        log.info(f"Credentials ==>{credentials}")
        config = Configuration(server=self.email_server, credentials=credentials,  auth_type=OAUTH2,  version=Version(build=EXCHANGE_O365))
        self.account = Account(self.email_address, access_type=DELEGATE, config=config)

Any suggestion on solving the above exception would be a great help. Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2025-02-20 13:46:44

当您使用client_credentials流时,您需要在ews中使用模仿,例如,

access_type=DELEGATE

access_type=IMPERSONATION

还需要确保您的申请注册具有FULL_ACCESS_AS_APP许可,并且已同意以查看 https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-to-to-authenticate-an-ews-an-ews-application-by-usish-using-oauth

When your using the client_credentials flow you need to use impersonation in EWS eg change

access_type=DELEGATE

to

access_type=IMPERSONATION

You also need to make sure you Application registration has the full_access_as_app permission and its consented to see https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文