@H_
404_0@
问题
我们希望使用Windows Active Directory将用户验证到应用程序中。但是,我们不想使用Active Directory组来管理控制器/视图的授权。
据我所知,没有一种简单的方式来结合AD和基于身份的声明。
目标
>使用本地Active Directory验证用户
>使用身份框架来管理声明
尝试(失败)
> Windows.Owin.Security.ActiveDirectory – Doh。这是对于Azure AD。没有LDAP支持。他们可以把它称为AzureActiveDirectory吗?
> Windows身份验证 – 这可以通过NTLM或Keberos身份验证。问题始于:i)令牌和索赔全部由AD管理,我无法弄清楚如何使用身份声明。
> LDAP – 但是这些似乎迫使我手动执行表单验证以使用身份声明?当然必须有一个更简单的方法?
任何帮助将不胜感激。我已经很久很久就被困在这个问题上,并且会很感激外界的关注。
鞋子你的
解决方案推动我朝着在MVC6-Beta3 Identityframework7-Beta3 EntityFramework7-Beta3上为我工作的方向:
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(Loginviewmodel model,string returnUrl = null)
{
if (!ModelState.IsValid)
{
return View(model);
}
//
// Check for user existance in Identity Framework
//
ApplicationUser applicationUser = await _userManager.FindByNameAsync(model.eID);
if (applicationUser == null)
{
ModelState.AddModelError("","Invalid username");
return View(model);
}
//
// Authenticate user credentials against Active Directory
//
bool isAuthenticated = await Authentication.ValidateCredentialsAsync(
_applicationSettings.Options.DomainController,_applicationSettings.Options.DomainControlleRSSlPort,model.eID,model.Password);
if (isAuthenticated == false)
{
ModelState.AddModelError("","Invalid username or password.");
return View(model);
}
//
// Signing the user step 1.
//
IdentityResult identityResult
= await _userManager.CreateAsync(
applicationUser,cancellationToken: Context.RequestAborted);
if(identityResult != IdentityResult.Success)
{
foreach (IdentityError error in identityResult.Errors)
{
ModelState.AddModelError("",error.Description);
}
return View(model);
}
//
// Signing the user step 2.
//
await _signInManager.SignInAsync(applicationUser,isPersistent: false,authenticationMethod:null,cancellationToken: Context.RequestAborted);
return RedirectToLocal(returnUrl);
}