我们已使用 PnP PowerShell 将应用程序分配到选定的 SharePoint 站点,现在 pnp 删除了该支持。我们是否可以通过其他方式向特定用户分配访问所选 SharePoint 网站的权限?我们已参考下面的链接来使用 Powercell 分配权限。 https://medium.com/@sanghuynh_73086/how-to-access-sharepoint-site-using-microsoft-graph-08d20311c61c#:~:text=2.2.-,1.,Sharepoint%20Site%20(选定% 20个站点)
我们正在使用 Graph API 获取客户的 SharePoint 文档或文件。为此,我们按照以下步骤从 SharePoint 检索文档:
步骤1:
在本地打开PowerShell(建议使用版本>=7.x运行代码)。
第2步: 如果我们本地没有 PnP PowerShell,我们使用以下命令来安装它:
### Install PnP PowerShell in local PowerShell:
Install-Module PnP.PowerShell -Scope CurrentUser
Install-Module SharePointPnPPowerShellOnline -Scope CurrentUser
第3步: 在线连接 Sharepoint 网站:
### Connect Sharepoint Online:
$devAsiaP = "https://mydomain.sharepoint.com/sites/appname"
Connect-PnPOnline -Url $devAsiaP
第四步: 验证连接:
### Verify connection:
Get-PnPSite
第5步: 授予所选站点的权限(写入权限)。
### Grant permission for selected site:
Grant-PnPAzureADAppSitePermission -AppId "{client_id}" -DisplayName "{app_name}" -Permissions Write -Site https://mydomain.sharepoint.com/sites/appname
第6步: 授权成功:
执行此步骤后,应用程序将有权控制所选的 Sharepoint 站点。
现在的问题是PnP不提供分配权限(下面提到的步骤)。我们正在寻找替代解决方案。
要向 SharePoint 分配权限,您还可以使用 Microsoft Graph API,如下所示:
创建两个 Microsoft Entra ID 应用程序,一个用于向应用程序分配站点权限,另一个是您要分配权限的应用程序。
在第一个应用程序中,授予
Sites.FullControl.All
应用程序类型API权限:
将
Sites.Selected
授予其他应用程序:
现在使用第一个应用程序(通过 Sites.FullControl.All
授予)Api 权限生成访问令牌:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
grant_type : client_credentials
client_id : ClientIDofFirstApp
client_secret : SecretofFirstApp
scope : https://graph.microsoft.com/.default
现在创建权限:
POST https://graph.microsoft.com/v1.0/sites/{sitesId}/permissions
Content-Type: application/json
{
"roles": ["write"],
"grantedToIdentities": [{
"application": {
"id": "AppIDwhichyouwanttograntpermission",
"displayName": "SharePointApp"
}
}]
}
参考: