您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用Python的Azure Sharepoint多因素身份验证

使用Python的Azure Sharepoint多因素身份验证

错误消息非常直观,启用了多重身份验证(MFA)时不支持 用户凭据 身份验证。

为了避免此错误,可以改用SharePoint仅应用程序流(由Office365-REST-Python- Clientlibrary支持)。

设置具有租户权限的仅应用程序主体,本节介绍如何配置它,并概括起来包括两个步骤:

一旦创建并同意了应用程序主体,就可以利用它来访问SharePoint资源,如下所示:

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.client_credential import ClientCredential

site_url = 'https://contoso.sharepoint.com/'
app_principal = {
    'client_id': '--client-id-goes-here--',
    'client_secret': '--client-secret-goes-here--',
}

credentials = ClientCredential(app_principal['client_id'], app_principal['client_secret'])
ctx = ClientContext(url).with_credentials(credentials)

web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Web site title: {0}".format(web.properties['Title']))

这是有关如何配置SharePoint仅应用程序流的说明:

注意:应用程序主登记操作(步骤1通过5)需要进行 每个租户一次 。尽管可以针对6-9每个租户或网站集应用授予权限的操作(步骤):

https://{tenant}-admin.sharepoint.com/_layouts/15/appinv.aspx。该操作需要租户管理员权限

脚步:

注意:有时,如果您指定实际域,例如sharepoint.com“ 和“ 字段中的域,而不是localhost,则An unexpected error has occurred可能会遇到错误消息。检查appregnew.aspx页面并确保两个字段都包含正确的localhostURI。

点击 。

转到appinv.aspx网站集上的页面。例如,https://example.sharepoint.com/_layouts/15/appinv.aspx授予 站点范围的 权限。

在“ *

http://sharepoint/content/sitecollection" Right="FullControl" />

注意:对于 级别范围,权限请求XML如下所示:

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant"

Right=”FullControl” />

python 2022/1/1 18:49:33 有391人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶