【问题标题】:Azure functions connecting flow to sharepoint with mfa使用 mfa 将流连接到共享点的 Azure 函数
【发布时间】:2018-01-09 03:41:55
【问题描述】:

我正在尝试使用本教程:https://medium.com/plumsail/how-to-call-sharepoint-from-microsoft-flow-with-a-help-of-an-azure-function-a5740794341 使用 Azure Functions 设置自定义 MS Flow 触发器来处理共享点文档。所以,我完全遵循了 tut,到目前为止只更改了我的凭据。

我收到以下错误,告诉我该帐户未经授权,我必须先浏览到该站点并启用自动登录

2018-01-03T21:11:01.889 Exception while executing function: Functions.CreateFolder. Microsoft.Azure.WebJobs.Script: One or more errors occurred. Microsoft.SharePoint.Client.Runtime: Cannot contact web site 'https://mysite.sharepoint.com/' or the web site does not support SharePoint Online credentials. The response status code is 'Unauthorized'. The response headers are 'X-SharePointHealthScore=0, X-MSDAVEXT_Error=917656; Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically., SPRequestGuid=9c003d9e-9090-5000-1519-82d69fd4d838, request-id=9c003d9e-9090-5000-1519-82d69fd4d838, MS-CV=nj0AnJCQAFAVGYLWn9TYOA.0, Strict-Transport-Security=max-age=31536000, X-FRAME-OPTIONS=SAMEORIGIN, SPRequestDuration=29, SPIisLatency=0, MicrosoftSharePointTeamServices=16.0.0.7206, X-Content-Type-Options=nosniff, X-MS-InvokeApp=1; RequireReadOnly, Content-Length=0, Content-Type=text/plain; charset=utf-8, Date=Wed, 03 Jan 2018 21:11:01 GMT, P3P=CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI", Server=Microsoft-IIS/8.5, X-Powered-By=ASP.NET'.

不太确定它们在那里的确切含义,但不管我的登录是否需要 mfa。以前有没有人尝试过这样做,使用 mfa 时我需要做些什么特别的事情吗?以下是建立客户端连接的几行。

string userName = System.Environment.GetEnvironmentVariable("SharePointUser", EnvironmentVariableTarget.Process);
string password = System.Environment.GetEnvironmentVariable("SharePointPassword", EnvironmentVariableTarget.Process);

var authenticationManager = new PnPAuthenticationManager();
var clientContext = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant(sharePointSiteUrl, userName, password);
var pnpClientContext = PnPClientContext.ConvertFrom(clientContext);

非常感谢任何帮助。

编辑:

【问题讨论】:

  • 我认为问题出在 MFA 上。 sharepoint 中是否有等效的 Service Principal user 可以在具有适当权限的自动化工具中使用?
  • 我们使用 AD 来管理帐户,所以我尝试创建一个 SP 用户,然后通过几个身份验证管理器方法使用该应用程序 ID 和密码。我通过 AD -> 应用注册 -> 所需权限授予应用 Sharepoint 权限。我还尝试仅使用应用程序注册来授予包含我的功能和所有权限的资源组,使用该应用程序 ID/秘密,使用应用程序密码。我现在被禁止而不是未经授权,所以我想这是一个权限问题,但不确定我还能做什么。你有没有做过类似的事情?
  • 使用 ServicePrincipalUser 是自动化工具的最佳方式。我建议先尝试在 Azure Functions 之外使用 SP 凭据,以确保您获得正确的权限。这是SP setup credentials 在资源组中具有正确权限的示例。希望这会有所帮助。
  • 让它与 sp 用户一起工作,感谢您的信息!
  • 太棒了。将移步回答。

标签: c# azure sharepoint azure-functions


【解决方案1】:

使用 ServicePrincipalUser 是自动化工具的最佳方式。 H

设置服务主体凭据的说明

  1. 获取 Azure CLI npm i -g azure-cli

  2. 登录到 Azure azure login

    这将为您提供一个代码并提示您访问aka.ms/devicelogin。提供代码,然后使用您的 Azure 身份登录(如果您已经登录,这可能会自动发生)。然后您就可以通过 CLI 访问您的帐户。

  3. 获取您的订阅和租户 ID azure account show

    保存订阅和租户 ID 以备后用

  4. 为给定的&lt;name&gt;&lt;password&gt; 创建服务主体并添加贡献者角色。 azure ad sp create -n <name> -p <password>

    这应该返回一个具有servicePrincipalNames 属性和一个ObjectId 的对象。保存对象 ID 和数组中的其中一个名称以及稍后提供的密码。如果以后需要查找服务主体,可以使用azure ad sp -c &lt;name&gt;,其中&lt;name&gt; 是最初提供的名称。请注意,您提供的 &lt;name&gt; 不是您稍后将提供的名称,它是 servicePrincipalNames 数组中的名称。

    然后使用 ObjectId 授予 SP 贡献者访问权限 azure role assignment create --objectId <objectIDFromCreateStep> -o Contributor

为确保 SP 用户对您需要的资源拥有正确的权限,请先尝试在 Azure 函数之外使用它。

【讨论】:

    猜你喜欢
    • 2015-05-01
    • 2018-12-20
    • 2020-10-30
    • 2021-05-28
    • 2018-06-22
    • 1970-01-01
    • 2021-12-01
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多