我目前正在使用Graph API测试MS Teams中的团队创建。为此,我已经在Azure AD中注册了一个应用程序并授予了所有必要的权限。根据Microsoft指南,必须首先创建O365组。然后,可以根据组ID创建团队。如果通过Deamon(即没有用户)完成此操作,则会发生错误400 Bad Request。
如果我将admin作为示例插入到组中,然后使用Graph Explorer创建与JSON主体具有相同内容的组,则它将正常工作。没有用户的Deamon是否有可能无法创建团队?
结果是:允许Deamon(无需用户)创建团队,但似乎sdk中存在错误或图形api服务器界面中存在错误。
我先在它的侧面进行测试,以使用sdk创建该组,但效果很好。以下是我的代码供您参考(如果您对创建组没有问题,请跳过此步骤):
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create("<client id>")
.WithTenantId("<tenant id>")
.WithClientSecret("<secret>")
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication, "https://graph.microsoft.com/.default");
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var group = new Group
{
Description = "Group with designated owner and members",
DisplayName = "huryNewGroup16",
GroupTypes = new List<String>()
{
"Unified"
},
MailEnabled = true,
MailNickname = "operations201916",
SecurityEnabled = false
};
await graphClient.Groups.Request().AddAsync(group);
创建小组后,我将测试创建一个具有小组ID的团队。古西亚在回答中提到的结论是正确的,但这不是重点。我们不能在没有添加至少一个成员/所有者的情况下创建团队,但是即使我添加了一个用户作为所有者,我仍然无法通过sdk创建团队。但是我可以在资源管理器中创建团队(使用auth代码流),也可以在“ API测试器”或邮递员中创建团队(使用Deamon / client_credential流)。
因此,我继续测试sdk并使用提琴手捕获来自sdk的请求,该请求如下所示:
PUT https://graph.microsoft.com/v1.0/groups/xxxx/team HTTP/1.1
Host: graph.microsoft.com
SdkVersion: Graph-dotnet-1.20.1
FeatureFlag: 0000004F
Cache-Control: no-store, no-cache
Authorization: Bearer xxxxxx
Accept-Encoding: gzip
Content-Type: application/json
Content-Length: 389
{
"memberSettings": {
"allowCreateUpdateChannels": true,
"@odata.type": "microsoft.graph.teamMemberSettings"
},
"messagingSettings": {
"allowUserEditMessages": true,
"allowUserDeleteMessages": true,
"@odata.type": "microsoft.graph.teamMessagingSettings"
},
"funSettings": {
"allowGiphy": true,
"giphyContentRating": "strict",
"@odata.type": "microsoft.graph.teamFunSettings"
},
"@odata.type": "microsoft.graph.team"
}
我还通过“ API测试器”中的请求创建了团队,并通过提琴手捕获了该请求,该请求如下所示:
PUT https://graph.microsoft.com/v1.0/groups/xxxx/team HTTP/1.1
Host: graph.microsoft.com
Connection: keep-alive
Content-Length: 327
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61
Authorization: Bearer xxxxxx
Content-Type: application/json
Accept: */*
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
Sec-Fetch-Site: none
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: xxxxx
{
"memberSettings": {
"allowCreateUpdateChannels": true
},
"messagingSettings": {
"allowUserEditMessages": true,
"allowUserDeleteMessages": true
},
"funSettings": {
"allowGiphy": true,
"giphyContentRating": "strict"
}
}
我们可以发现,不同之处在于第一个请求正文有多余的内容@odata.type
,如果我删除这些@odata.type
字段并再次在“ API Tester”中进行请求,则可以创建团队成功。
所以我认为问题是@odata.type
由sdk请求时in请求主体引起的。sdk中可能存在错误,或者图api服务器的界面中存在错误。但是对于您的问题“没有用户的Deamon是否有可能创建团队”?答案是“是”。但是我们不能使用sdk进行操作,我们可以在“ API Tester”或邮递员中请求它。或者,如果您想通过代码进行操作,则可以使用“ HttpClient”来请求访问令牌(使用Deamon / client_credential流),然后在您的代码中请求图形api。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句