通过 Id 获取用户不会 return
Fetching User by Id does not return
我已经成功连接到Azure AD(至少我希望如此,无法说出细节),现在我正在尝试获取一些用户的详细信息。但是逐步调试器不会继续执行以下行:
IUser result = azureDirectoryClient.Users.GetByObjectId(someId).ExecuteAsync().Result;
我到这里为止,没有抛出任何错误,函数也没有 return - 这告诉我什么?如何进一步调试问题?
不要忘记在某处使用await关键字等待结果,同时指定方法是async所以它运行异步
public async Task<ActionResult> SomeAction()
{
IUser result = await azureDirectoryClient.Users.GetByObjectId(someId).ExecuteAsync();
return View(result);
}
调试时你发现了什么:
try
{
IUser result = azureDirectoryClient.Users.GetByObjectId(objectId).ExecuteAsync().Result;
}
catch(exception e)
{
console.white(e.message)
}
如何连接到 Azure AD?确保您获得准确的访问令牌:
public static string GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(Constants.AuthString, false);
// Config for OAuth client credentials
ClientCredential clientCred = new ClientCredential(Constants.ClientId, Constants.ClientSecret);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(Constants.ResourceUrl, clientCred);
string token = authenticationResult.AccessToken;
return token;
}
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri(https://graph.windows.net, TenantId),
async () => await GetTokenForApplication());
我已经成功连接到Azure AD(至少我希望如此,无法说出细节),现在我正在尝试获取一些用户的详细信息。但是逐步调试器不会继续执行以下行:
IUser result = azureDirectoryClient.Users.GetByObjectId(someId).ExecuteAsync().Result;
我到这里为止,没有抛出任何错误,函数也没有 return - 这告诉我什么?如何进一步调试问题?
不要忘记在某处使用await关键字等待结果,同时指定方法是async所以它运行异步
public async Task<ActionResult> SomeAction()
{
IUser result = await azureDirectoryClient.Users.GetByObjectId(someId).ExecuteAsync();
return View(result);
}
调试时你发现了什么:
try
{
IUser result = azureDirectoryClient.Users.GetByObjectId(objectId).ExecuteAsync().Result;
}
catch(exception e)
{
console.white(e.message)
}
如何连接到 Azure AD?确保您获得准确的访问令牌:
public static string GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(Constants.AuthString, false);
// Config for OAuth client credentials
ClientCredential clientCred = new ClientCredential(Constants.ClientId, Constants.ClientSecret);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(Constants.ResourceUrl, clientCred);
string token = authenticationResult.AccessToken;
return token;
}
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri(https://graph.windows.net, TenantId),
async () => await GetTokenForApplication());