加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何使用Windows Active Directory身份验证和基于身份的声明?

发布时间:2020-12-13 21:16:46 所属栏目:Windows 来源:网络整理
导读:问题 我们希望使用Windows Active Directory将用户验证到应用程序中。但是,我们不想使用Active Directory组来管理控制器/视图的授权。 据我所知,没有一种简单的方式来结合AD和基于身份的声明。 目标 使用本地Active Directory验证用户 使用身份框架来管理
问题

我们希望使用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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读