Repository navigation
Description
Describe the bug
The MS Graph SDK has a mismatch on the response schema it expects vs what the MS Graph REST API returns for the "RevokeSignInSessions" endpoint.
The IUserRevokeSignInSessionsRequest.PostAsync returns a Task but the API response payload wraps that bool in a complex object and the SDK fails to deserialize.
The API states just a boolean should be returned - https://docs.microsoft.com/en-us/graph/api/user-revokesigninsessions?view=graph-rest-1.0&tabs=http
To Reproduce
Steps to reproduce the behavior:
- Create an AAD application with the Directory.ReadWrite.All application permission
- Create a .NET Core console application using the MS Graph SDK version 1.21.0
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create("{enter client_id}")
.WithClientSecret("{enter client_secret}")
.Build();
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphServiceClient = new GraphServiceClient(authenticationProvider);
var result = await graphServiceClient
.Users["{enter user_id}"]
.RevokeSignInSessions()
.Request()
.PostAsync();Actual Results
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Edm.Null",
"@odata.null": true
}Expected behavior
The successful request should correctly deserialize the response and not error out.
Screenshots
Error message differes b/w .NET Framework 4.8 and .NET Core. In .NET Core the error is:
Newtonsoft.Json.JsonReaderException
HResult=0x80131500
Message=Unexpected character encountered while parsing value: {. Path '', line 1, position 1.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.JsonTextReader.ReadAsBoolean()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Microsoft.Graph.Serializer.DeserializeObject[T](String inputString)
at Microsoft.Graph.ResponseHandler.<HandleResponse>d__2`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Graph.BaseRequest.<SendAsync>d__31`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AzureAdGraphNetCoreSample.Program.<CallUsingCreateClientCredentialProvider>d__1.MoveNext() in C:\Users\lapellan\source\repos\AzureAdGraphSample\AzureAdGraphNetCoreSample\Program.cs:line 34
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AzureAdGraphNetCoreSample.Program.Main(String[] args) in C:\Users\lapellan\source\repos\AzureAdGraphSample\AzureAdGraphNetCoreSample\Program.cs:line 17
Desktop (please complete the following information):
Additional context
Activity
MIchaelMainer commentedon Feb 20, 2020
The documentation is incorrect in that it states it returns a 204 No Content. See https://github.com/microsoftgraph/microsoft-graph-docs/issues/5359.
Our generator needs to be updated to support an OData Action that returns a boolean wrapped in an object. We need to check if this is expected per OData and which other scenarios need to be considered here.
This is a generation issue for us.
gavinkerr commentedon Oct 13, 2020
This looks to be fixed. I was getting it in v3.9.0 but after learning a ton more about Microsoft.Graph code base, I realised it was fixed in v3.17.0.... I would say this can be closed
P.S. a quick way to debug this kind of thing is to set the ResponeHandler with you own implementation, (although I dont advise leaving this as production level code):
var graphClient = await GraphClient(); var userRevokeSignInSessionsRequest = (UserRevokeSignInSessionsRequest)graphClient.Users[objectId].RevokeSignInSessions().Request(); userRevokeSignInSessionsRequest.ResponseHandler = new ResponseHandler(new MySerializer()); await userRevokeSignInSessionsRequest.PostAsync();MIchaelMainer commentedon Oct 13, 2020
gavinkerr Thank you for pointing this out and sharing your useful debugging tip. This scenario is fixed in the sense that the client library no longer throws the JSONReaderException. The response still doesn't match the service metadata and so is still technically an issue. We are tracking this issue with microsoftgraph/msgraph-sdk-serviceissues#9.
Related:
microsoftgraph/msgraph-beta-sdk-dotnet#160
microsoftgraph/msgraph-sdk-dotnet-core#135