通过恶魔创建 Microsoft Teams 组
Create Microsoft Teams group by deamon
我目前正在使用 Graph API 在 MS Teams 中测试团队创建。
为此,我在 Azure AD 中注册了一个应用程序并授予了所有必要的权限。
根据 Microsoft 指南,必须首先创建一个 O365 组。然后可以根据组 ID 创建团队。如果这是通过守护进程(即没有用户)完成的,则会发生错误 400 Bad Request。
如果我将管理员作为示例插入组中,然后使用 Graph Explorer 创建内容与 JSON Body 相同的组,它可以正常工作。
难不成没有用户的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创建一个团队。 古西亚在他的回答中提到的结论是正确的,但不是重点。我们不能在不添加至少一个 member/owner 的情况下创建团队,但即使我添加一个用户作为所有者, 我仍然无法通过 sdk 创建团队。但是我可以在资源管理器中创建团队(使用授权代码流),我也可以在“API Tester”或邮递员(使用 Deamon/client_credential 流)中创建团队。
于是继续测试sdk,使用fiddler抓取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 Tester”中通过请求创建团队并通过fiddler捕获请求,请求如下:
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"
}
}
我们可以发现区别是第一个请求body多了@odata.type
,如果我去掉@odata.type
字段再在“API Tester”中请求,就可以创建团队成功。
所以我认为问题是由于sdk请求时请求体中的@odata.type
引起的。 可能sdk有bug或者graphapiserver的界面有bug。 但是对于“没有用户的Deamon是否可以创建团队”的问题?答案是“是”。但是我们不能用sdk来做,我们可以在“API Tester”或者postman中请求。或者,如果您想通过代码来完成,您可以使用“HttpClient”请求访问令牌(使用 Deamon/client_credential 流程),然后在您的代码中请求图形 api。
我目前正在使用 Graph API 在 MS Teams 中测试团队创建。 为此,我在 Azure AD 中注册了一个应用程序并授予了所有必要的权限。 根据 Microsoft 指南,必须首先创建一个 O365 组。然后可以根据组 ID 创建团队。如果这是通过守护进程(即没有用户)完成的,则会发生错误 400 Bad Request。
如果我将管理员作为示例插入组中,然后使用 Graph Explorer 创建内容与 JSON Body 相同的组,它可以正常工作。 难不成没有用户的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创建一个团队。 古西亚在他的回答中提到的结论是正确的,但不是重点。我们不能在不添加至少一个 member/owner 的情况下创建团队,但即使我添加一个用户作为所有者, 我仍然无法通过 sdk 创建团队。但是我可以在资源管理器中创建团队(使用授权代码流),我也可以在“API Tester”或邮递员(使用 Deamon/client_credential 流)中创建团队。
于是继续测试sdk,使用fiddler抓取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 Tester”中通过请求创建团队并通过fiddler捕获请求,请求如下:
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"
}
}
我们可以发现区别是第一个请求body多了@odata.type
,如果我去掉@odata.type
字段再在“API Tester”中请求,就可以创建团队成功。
所以我认为问题是由于sdk请求时请求体中的@odata.type
引起的。 可能sdk有bug或者graphapiserver的界面有bug。 但是对于“没有用户的Deamon是否可以创建团队”的问题?答案是“是”。但是我们不能用sdk来做,我们可以在“API Tester”或者postman中请求。或者,如果您想通过代码来完成,您可以使用“HttpClient”请求访问令牌(使用 Deamon/client_credential 流程),然后在您的代码中请求图形 api。