问题
I am attempting to query user information via Microsoft Graph. I can authenticate fine but when I attempt to query user information graphServiceClient.Users
my application hangs indefinitely: no timeout, no error, just hangs. I found this post however the suggestions there did not help me.
Here is my code:
public bool GetUserByUniqueID(string uid, out GraphUser user)
{
bool ret = false;
user = new GraphUser();
if (Authenticate(out AuthToken token))
{
GraphServiceClient graphServiceClient = GetGraphServiceClient(token);
// The below code hangs indefinitely
User graphUser = graphServiceClient.Users[uid].Request()
.Select("id,displayName,userPrincipalName,userType,accountEnabled").GetAsync().GetAwaiter()
.GetResult();
if (graphUser != null)
{
user.ID = graphUser.Id;
user.DisplayName = graphUser.DisplayName;
user.PrincipalName = graphUser.UserPrincipalName;
user.UserType = graphUser.UserType;
user.AccountEnabled = graphUser.AccountEnabled ?? false;
user.MemberOf = GetMemberOf(token, graphUser.Id);
ret = true;
}
}
return ret;
}
private bool Authenticate(out AuthToken token)
{
bool ret = false;
token = new AuthToken();
string url = $"https://login.microsoftonline.com/{_tenant}/oauth2/v2.0/token";
RestClient client = new RestClient(url);
RestRequest request = new RestRequest(Method.POST);
request.Parameters.Add(new Parameter("grant_type", _grantType, ParameterType.GetOrPost));
request.Parameters.Add(new Parameter("scope", _scope, ParameterType.GetOrPost));
request.Parameters.Add(new Parameter("client_secret", _clientSecret, ParameterType.GetOrPost));
request.Parameters.Add(new Parameter("client_id", _clientId, ParameterType.GetOrPost));
IRestResponse response = client.Execute<AuthToken>(request);
if (response.StatusCode == HttpStatusCode.OK)
{
token = JsonConvert.DeserializeObject<AuthToken>(response.Content);
ret = true;
}
return ret;
}
回答1:
I have fixed the issue by reverting to a previous version of Microsoft.Graph
and Microsoft.Graph.Core
. I was using version 1.14.0 and now I am using 1.12.0. .GetAwaiter().GetResult()
is broken in 1.14.0 the current release (1.15.0).
回答2:
I'm having the same issue with NPM package of the Graph API. Reverted to plain old request-promise. Now it's not stuck but does not always find the members of a group. Using beta version of the API works fine
来源:https://stackoverflow.com/questions/55944518/microsoft-graph-api-call-hangs-indefinitely