尝试通过 Microsoft Graph 创建组时“权限不足,无法完成操作”

用户1063287

期望的行为

group使用single tenant application具有delegatedAPI 权限的 JavaScript SDK 和 MSAL创建一个via Microsoft Graph

实际行为

{
  "statusCode": 403,
  "code": "Authorization_RequestDenied",
  "message": "Insufficient privileges to complete the operation.",
  "requestId": "6e865d96-ef8b-408e-a905-5393b4adcfdc",
  "date": "2020-05-16T20:20:15.000Z",
  "body": "{\"code\":\"Authorization_RequestDenied\",\"message\":\"Insufficient privileges to complete the operation.\",\"innerError\":{\"request-id\":\"6e865d96-ef8b-408e-a905-5393b4adcfdc\",\"date\":\"2020-05-17T06:20:15\"}}"
}

我试过的

为了创建代码,我使用了以下 API 参考说明:

登录/注销和所有其他 API 请求都在工作。

订阅

Microsoft 365 Business Standard Trial

API权限

在此处输入图片说明

Directory.AccessAsUser.All +++
Directory.ReadWrite.All ***
Group.ReadWrite.All  
GroupMember.ReadWrite.All ***
openid
profile
Sites.Read.All
Tasks.ReadWrite
User.Read

*** 我在阅读此答案后添加了这些,但仍然出现相同的错误。
+++ 我在下面的答案中添加了这个建议。

我已单击 Azure 应用程序注册区域中的“授予管理员同意”按钮。

索引.html

<!-- msal -->
<!-- from:  https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-core -->
<script type="text/javascript" src="https://alcdn.msauth.net/lib/1.3.0/js/msal.js" integrity="****" crossorigin="anonymous"></script>

<!-- javascript sdk -->
<!-- from:  https://github.com/microsoftgraph/msgraph-sdk-javascript -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@microsoft/microsoft-graph-client/lib/graph-js-sdk.js"></script>

配置文件

// msal options
const msalConfig = {
    auth: {
        clientId: "client-id-here",
        redirectUri: "http://localhost:8080",
        authority: "https://login.microsoftonline.com/tenant-id-here"
    },
  cache: {
    cacheLocation: "sessionStorage",
    storeAuthStateInCookie: false,
    forceRefresh: false
  }
};

// define application permissions   
const scopes = ['directory.accessasuser.all', 'directory.readwrite.all', 'group.readwrite.all', 'groupmember.readwrite.all', 'openid', 'profile', 'sites.read.all', 'user.read', 'tasks.readwrite' ]; 

认证.js

const msalApplication = new Msal.UserAgentApplication(msalConfig);

const loginRequest = {
    scopes: scopes
}

async function sign_in() {
    try {
        await msalApplication.loginPopup(loginRequest);
        if (msalApplication.getAccount()) {
            console.log("sign in success");
        }
    } catch (error) {
        console.log("sign in error");
        console.log(error);
    }
}

function sign_out() {
    msalApplication.logout();
}

图.js

var path = "/groups"; 
var group = {
  description: "Here is a description.",
  displayName: "test_test_test",
  groupTypes: [
    "Unified",
    "DynamicMembership"
  ],
  mailEnabled: true,
  mailNickname: "test_test_test",
  securityEnabled: false, // initially i had this as true, doesn't seem to make a difference either way  
  visibility: "Hiddenmembership",
  "[email protected]": [
    "https://graph.microsoft.com/v1.0/users/my-user-id-here"
  ],
    "[email protected]": [
        "https://graph.microsoft.com/v1.0/users/my-user-id-here"
  ]
};

var response = await client.api(path)
                            .post(group);

相关阅读:

比较组

了解 Microsoft 365 组

面向管理员的 Microsoft 365 组概述

在 Microsoft Graph 中使用组

在 Microsoft 365 管理中心创建、编辑或删除安全组

使用 Microsoft Graph 创建团队和管理成员

Microsoft Graph 中的 Office 365 组概述

关于什么可能导致错误的其他想法......

可见性仅支持统一组;安全组不支持它。

来源

也许的组合securityEnabled: truevisibility:Hiddenmembership不兼容?

我尝试将其更改为securityEnabled: false并收到相同的消息。

令牌有问题吗?

Authorisation: Bearer从 Chrome 开发工具控制台复制了值并粘贴到https://jwt.io并且令牌中提供了两个额外的范围 - 但所有其他范围都存在:

在此处输入图片说明

在此处输入图片说明

用户1063287

我能够Group通过更改以下内容来创建一个graph.js

groupTypes: ["Unified","DynamicMembership"]  

groupTypes: ["Unified"]`   

我不知道为什么DynamicMembership会导致错误。

它是下面链接中列出Group>的有效属性值,groupTypes没有任何警告:

https://docs.microsoft.com/en-us/graph/api/resources/group?view=graph-rest-1.0#properties

作为参考,上面的代码创建:

  • 团体
  • SharePoint“团队网站”
  • Outlook 电子邮件组

它不会自动创建相应的:

  • 团队
  • 计划

您可以在以下位置看到列出的新组:

https://admin.microsoft.com/AdminPortal/Home#/groups

https://outlook.office365.com/people

https://portal.azure.com/#blade/Microsoft_AAD_IAM/GroupsManagementMenuBlade/AllGroups

您可以在以下位置看到“团队站点”组:

https://your_account-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/siteManagement

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

尝试连接到Microsoft Graph时“权限不足,无法完成操作”

Microsoft Graph API-权限不足,无法完成操作

Microsoft Graph API:权限不足,无法完成操作

“更新用户”操作给予“权限不足,无法完成操作”。Microsoft Graph API中的错误

Microsoft Graph API-更新密码-权限不足,无法完成操作

通过Microsoft Graph查询组邮箱的范围

通过 Microsoft Graph API 创建用户

无法通过 Microsoft Graph 获取收到的消息

使用Python的Microsoft Graph API请求:进行简单调用时出现“权限不足,无法完成操作”错误

Graph APIassignLicense:权限不足,无法完成操作

通过Graph API重置密码时,为什么会遇到“ Authorization_RequestDenied:权限不足以完成操作”

尝试下载用户图像时出现Microsoft.Graph.ServiceException

尝试访问 Microsoft Graph 中的 Bookings Api 时授权被拒绝

通过Microsoft Graph API检索SharePoint Online对象权限

通过Microsoft Graph从Azure AD获取组中的用户

通过 Microsoft GRAPH 的 OneDrive 通知

无法识别通过 powershell 的 Microsoft Graph API 查询参数

无法通过 Microsoft Graph 获取已删除的 Outlook 邮件

通过Microsoft Graph请求时,列表项为空

尝试使用$ expand(microsoft.graph.itemattachment / item)读取ItemAttachment属性时,Microsoft Graph API“拒绝访问”

Microsoft graph API:尝试读取用户组时获取403

Azure AAD和Graph API:权限不足,无法完成操作

Graph API-权限不足,无法完成操作

无法通过具有授权权限的Microsoft Graph API发送电子邮件

通过Microsoft Graph API访问Microsoft Teams频道消息时出现错误:Proxy_InternalServerError

尝试访问Microsoft Graph时出现“无法获取本地发行者证书”

尝试激活控制器时无法解析类型为“ Microsoft.Graph.GraphServiceClient”的服务

Microsoft Graph API委托权限

Microsoft Graph API 创建组失败