Azure Active Directory图形客户端2.0
有人在使用Azure AD Graph客户端的新2.0版本吗 我昨天开始胡闹,但没法让它工作。Azure Active Directory图形客户端2.0,azure,graph,active-directory,Azure,Graph,Active Directory,有人在使用Azure AD Graph客户端的新2.0版本吗 我昨天开始胡闹,但没法让它工作。GraphConnection类被标记为已弃用,并替换为ActiveDirectoryClient。另外,一下子就变成了Office 365,而我只想将我的试用限制在没有O365的Azure Active Directory上。文档很难找到,至少当您不想使用O365和O365 API工具时是如此。GitHub上的广告示例似乎也已更新,但代码仍在使用GraphConnection类。算了吧 关于使用Act
GraphConnection
类被标记为已弃用,并替换为ActiveDirectoryClient
。另外,一下子就变成了Office 365,而我只想将我的试用限制在没有O365的Azure Active Directory上。文档很难找到,至少当您不想使用O365和O365 API工具时是如此。GitHub上的广告示例似乎也已更新,但代码仍在使用GraphConnection
类。算了吧
关于使用ActiveDirectory客户端的示例/指南还不多,所以下面的代码暂时还没有使用
public async Task<ActionResult> Index()
{
List<Exception> exceptions = new List<Exception>();
ProfileViewModel model = new ProfileViewModel();
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(SecurityConfiguration.Authority, new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(SecurityConfiguration.ClientId, SecurityConfiguration.AppKey);
try
{
var ServiceUri = new Uri(SecurityConfiguration.GraphUrl);
ActiveDirectoryClient client = new ActiveDirectoryClient(ServiceUri, async () =>
{
var result = await authContext.AcquireTokenSilentAsync(SecurityConfiguration.GraphUrl, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
return result.AccessToken;
});
try
{
var users = await client.Users.ExecuteAsync();
var user = await client.Users[userObjectID].ExecuteAsync();
}
catch (Exception exc)
{
exceptions.Add(exc);
}
}
catch (AdalSilentTokenAcquisitionException exc)
{
exceptions.Add(exc);
}
ViewBag.Exceptions = exceptions;
return View(model);
}
如果您使用razor来显示用户的内容,则在尝试通过收集(如assignedplan
类型“System.Object”是在未引用的程序集中定义的。必须添加对程序集“System.Runtime,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”的引用
解决方案是更改web.config中的编译设置,如中所述
用于按Id检索用户实体,而不是:
var userFetcher = client.Users.Where(u => u.ObjectId == userObjectID);
var user = await userFetcher.ExecuteAsync();
您可以直接使用getByObjectId:
var user = await client.Users.GetByObjectId(userObjectID).ExecuteAsync();
最近我们发现与AAD合作非常非常令人沮丧。我们目前遇到了各种各样的问题,特别是关于ZUMO的问题,并且在少量的博客上找到了解决方案等等。。。官方文件中未提及任何内容。如果你没有完全遵循MS的教程,那你就是在白费力气。
var userFetcher = client.Users.Where(u => u.ObjectId == userObjectID);
var user = await userFetcher.ExecuteAsync();
var user = await client.Users.GetByObjectId(userObjectID).ExecuteAsync();