在我们的代码中,我们创建了一个具有Microsoft Graph Beta调用(https://graph.microsoft.com/beta)的Microsoft团队。其他调用通过Microsoft Graph(https://graph.microsoft.com/)完成。我们正在使用Microsoft Graph v1.14.0 NuGet软件包。
直到2019年5月30日,这一切都很好。之后,它停止工作并返回以下错误:
console log(_data);
没人可能在5月30日至31日工作,所以我们这边什么都没有改变。
我们的电话:
Type: Microsoft.Graph.ServiceException
Bericht: Code: BadRequest
Message: Write requests (excluding DELETE) must contain the Content-Type header declaration.
变量“ team”包含一个对象,该对象生成以下JSON:
var createdTeam = await graphApiServiceClient
.Teams
.Request()
.AddAsync(team);
我们已经登录到Graph Explorer,从cookie中获取访问令牌,并在我们自己的代码中使用了它。这导致通话成功,并创建了团队。
这有点奇怪,因为如果我们原始的访问令牌是错误的,那么我们将无法进行正在执行的其他成功调用(例如,创建了安全组)。
我们已经比较了Graph Explorer用户和我们在代码中使用的用户的权限。我们发现没有区别。两者都具有{
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
"owners@odata.bind": ["https://graph.microsoft.com/beta/users('a guid')"],
"displayName": "Test displayname",
"description": "Test Description",
"visibility": "Private"
}
权限。
有时我们在相同数据的同一呼叫上收到另一个错误:
更新:升级到Microsoft Graph v1.50.0和Microsoft Graph Core v1.16.0后,我们收到以下错误
Group.ReadWrite.All
其他信息:
我们正在使用App上下文。
获取访问令牌的代码:
Type: Microsoft.Graph.ServiceException
Bericht: Code: UnauthorizedAccess
Message: Failed to execute Templates backend request CreateTeamFromTemplateRequest.
Request Url: https://teams.microsoft.com/fabric/templates/api/team,
Request Method: POST, Response Status Code: Unauthorized, Response Headers: Strict-Transport-Security: max-age=2592000
X-MSEdge-Ref: Ref A: 266D45253C1B41809D27E6B7815E094E Ref B: DB3EDGE1119 Ref C: 2019-06-05T09:25:18Z
Date: Wed, 05 Jun 2019 09:25:18 GMT,
ErrorMessage : {
"errors":[{
"message":"AccessToken token is not valid."
}],
"operationId":"2d511c3df28add419e9aa37926ccb962"
}
请求失败(令牌已过期)
var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($"https://login.microsoftonline.com/{this.domain}");
var credential = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(ClientID, ClientSecret);
var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", credential);
accessToken = authResult.AccessToken;
身体:
Method: POST,
RequestUri: 'https://graph.microsoft.com/beta/teams',
Version: 1.1,
Content: System.Net.Http.StringContent,
Headers:
{
SdkVersion: Graph-dotnet-1.14.0
FeatureFlag: None
FeatureFlag: RedirectHandler, RetryHandler, AuthHandler, DefaultHttpProvider
Cache-Control: no-store, no-cache
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEQ29NcGpKWHJ4VHE5Vkc5dGUtN0ZYblRaYWluNkdtNWhnRnRrWEh0RlRydFhtRUM2bUZJZFI0X00wMkRoMFg5QzVIaFU0ZHhyRFE2cU1rMGVFOEFVbWtqZnZaMjFlZFZKR1NXYUY5bGdsRFNBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoiQ3RmUUM4TGUtOE5zQzdvQzJ6UWtacGNyZk9jIiwia2lkIjoiQ3RmUUM4TGUtOE5zQzdvQzJ6UWtacGNyZk9jIn0.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvM2QxY2M5YWQtZjBkNC00MTZkLTkyZGMtOTRjZGFjYzdkNTUwLyIsImlhdCI6MTU2MTYyMTMwNiwibmJmIjoxNTYxNjIxMzA2LCJleHAiOjE1NjE2MjUyMDYsImFpbyI6IjQyWmdZRmgzTmJmT3JweE56V2wzdmtMc2IxMWJBQT09IiwiYXBwX2Rpc3BsYXluYW1lIjoiREVWX01PTy1wcm92aXNpb25pbmciLCJhcHBpZCI6IjkwNmUwNjJkLTIwNWItNGM3Yi05NmM3LWQ4ZTI4YjZlMTAyNyIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzNkMWNjOWFkLWYwZDQtNDE2ZC05MmRjLTk0Y2RhY2M3ZDU1MC8iLCJvaWQiOiIzMjQyODFjYi01ODVmLTQ5ODItODE4NC00ZTdlOGNmYTllMTQiLCJyb2xlcyI6WyJVc2VyLlJlYWRXcml0ZS5BbGwiLCJHcm91cC5SZWFkV3JpdGUuQWxsIiwiVXNlci5SZWFkLkFsbCIsIk1haWxib3hTZXR0aW5ncy5SZWFkV3JpdGUiXSwic3ViIjoiMzI0MjgxY2ItNTg1Zi00OTgyLTgxODQtNGU3ZThjZmE5ZTE0IiwidGlkIjoiM2QxY2M5YWQtZjBkNC00MTZkLTkyZGMtOTRjZGFjYzdkNTUwIiwidXRpIjoiREVyR082OTE0a1doazh0YjI4OUNBQSIsInZlciI6IjEuMCIsInhtc190Y2R0IjoxMzQzODA0NzExfQ.DXO3VpCj5GyULTxiCvdyV5Fv33D5QER4CQDkhfxi-0t8MGXJ7reositSt2-oNqxRwQ3iI0_R-kXsldaPtf7mR0aP2HgJeWQoy_MiTKtLU8RwW9hkgJEohjeeWku9edOn_fsLj8V1Yw4eLeXroqPLEmIWQ4ks8mG9Q1T3Q-9mixhjI7b4by7wIJgFe6DvmI7Yo9KYg4HygCPJ-FQJH8yeDGQWbyuy0pskNmj88b77k3fL_3-c-OAL74dOZ-FCcTkIq63bvg8NxKSgRWb5OMu7JK6cjfKUhPFWLTk2l8Aqq8UYXqoSQynX2ZvaJsBmARb6vLIeflwLPC4yr73afj6NtA
Content-Type: application/json
Content-Length: 305
}
响应是一个Microsoft.Graph.ServiceException:
{
"template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
"owners@odata.bind": ["https://graph.microsoft.com/beta/users('a guid')"],
"displayName": "Test displayname",
"description": "Test Description",
"visibility": "Private"
}
响应头:
{
Code: BadRequest
Message: Write requests (excluding DELETE) must contain the Content-Type header declaration.
Inner error
}
Stacktrace:
{
Transfer-Encoding: chunked
request-id: 1daa5989-7fbe-44c1-89f8-908c3adb740b
client-request-id: 1daa5989-7fbe-44c1-89f8-908c3adb740b
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceC","Ring":"5","ScaleUnit":"003","RoleInstance":"AGSFE_IN_44","ADSiteName":"WEU"}}
Duration: 5.254
Strict-Transport-Security: max-age=31536000
Cache-Control: private
Date: Thu, 27 Jun 2019 07:56:27 GMT
}
更多其他信息:
如果我们在Postman中使用我们的clientId和clientSecret进行以下调用,我们将获得一个有效的令牌(我们在代码中使用了返回的令牌)。
at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendAsync>d__30`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MOO.Apps.Office365.Backend.Repository.Office365.TeamO365Repository.<CreateAsync>d__2.MoveNext()
答案 0 :(得分:0)
能否请您尝试在 authContext.AcquireTokenAsync()中传递“ https://graph.microsoft.com”而不是“ https://graph.microsoft.com/”?
var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com", credential);
我们正在寻找修复程序,但与此同时,请尝试此变通办法,让我们知道您是否仍然遇到相同的问题。