Azure AD 仅适用于 SharePoint,无需授予广泛的租户权限

标签 azure sharepoint-online

我想设置 Azure AD 仅应用程序来访问 SharePointOnline 中的某个网站。但是,当您设置 Azure AD App-Only 应用程序时,您似乎只能授予它跨所有站点网站集的访问权限,并且不能在范围上进行选择。有没有更好的方法可以在不授予广泛访问权限的情况下做到这一点?

我应该使用 SharePoint 仅应用程序应用程序,而不是使用 xml 权限定义吗?我知道使用这种方法您可以将其限制为仅一个网站集。

最佳答案

Note that: You can limit access to a SharePoint site collection in the application context by using the Sites.Selected application permission but you cannot restrict access to specific folders/files or specific scope.

创建 Azure AD 应用程序并授予 API 权限:

enter image description here

为了仅授予对一个 SharePoint 网站的访问权限,我使用了以下 PowerShell 脚本:

$siteUrl = “https://xxx.sharepoint.com/sites/testruk”
$clientId = “ClientID” 
$certThumbprint = “Thumbprint” 
$tenant = “xxx.onmicrosoft.com”

Connect-PnPOnline -Url $siteUrl -Interactive
$writeperm = Grant-PnPAzureADAppSitePermission -Permissions “Write” -Site $siteUrl -AppId $clientId -DisplayName “PowerShell-SharepointOnline”
$PermissionId = Get-PnPAzureADAppSitePermission -AppIdentity $clientId
Set-PnPAzureADAppSitePermission -Site $siteurl -PermissionId $(($PermissionId).Id) -Permissions “FullControl”

enter image description here

当 SharePoint 网站使用应用程序时,我能够访问该网站:

Connect-PnPOnline -Url $siteUrl -ClientId $clientId -Thumbprint $certThumbprint -Tenant $tenant

enter image description here

当我尝试访问另一个 SharePoint 网站时,收到 403 禁止 错误:

Connect-PnPOnline -Url $siteUrl -ClientId $clientId -Thumbprint $certThumbprint -Tenant $tenant

enter image description here

  • Microsoft Graph API 权限是租户范围内的,不能限制在特定范围内。
  • 如果 Azure AD 应用已被授予应用程序权限,则会向该应用授予完全级别的访问权限。
  • 因此,您可以仅限制 SharePoint 集合网站,但不能限制范围。

要确认上述内容,请检查以下内容 引用资料:

How to allow my app without user to access ONLY specific drive or folder - Microsoft Q&A作者:瓦西尔·米切夫

Graph API - Restrict OneDrive/Sharepoint Access when using "Files.ReadWrite.All" and "Sites.ReadWrite.all" Permissions - Microsoft Q&A作者:CarlZhao-MSFT

关于Azure AD 仅适用于 SharePoint,无需授予广泛的租户权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77176645/

相关文章:

node.js - Azure 网站是否支持 https 和 Node.js?

Azure CLI 运行命令使用参数调用 RunPowerShellScript

powershell - Azure AD - 通过 Powershell 自定义应用程序角色

azure - 用于与现有 VNET 子网集成应用服务的 ARM 模板

具有 SharePoint 连接的 Azure 逻辑应用

azure - 实例关闭后 Azure 虚拟机存储是否会丢失?

authentication - AAD 注册了 Azure Functions + GraphAP Delegated + SharePoint Online?

c# - SharePoint Online CSOM 网站列默认值

powershell - Connect-PnPOnline:术语 'Connect-PnPOnline'不被识别为cmdlet,函数,脚本文件或可运行程序的名称