【问题标题】:How to Authenticate User Against ADFS from my Custom SSO applicaiton如何从我的自定义 SSO 应用程序针对 ADFS 对用户进行身份验证
【发布时间】:2018-04-05 05:51:38
【问题描述】:

我有点困惑。我正在为我的应用程序创建一个单点登录应用程序。所以流程是当用户尝试访问 example.com 的登录控制器时我将用户重定向到我的 SSO 应用程序

 FederatedAuthentication.WSFederationAuthenticationModule.RedirectToIdentityProvider("example.com", "example.com", true);

在这个应用程序中,我显示了一个登录页面,用户可以在其中输入用户名和密码。所以现在我想根据我的 ADFS 中的这些凭据对用户进行身份验证。但我很困惑如何做到这一点

这是我的登录页面

@using SingleSignOn.Models

@model LoginModel

@{
    ViewBag.Title = "Login";
}

<h2>Login</h2>

@using (Html.BeginForm(new { returnUrl = ViewBag.ReturnUrl }))
{
    @Html.ValidationSummary()

    <div class="left">
        @Html.LabelFor(m => m.Username)
    </div>
    <div>
        @Html.EditorFor(m => m.Username)
    </div>

    <div class="left">
        @Html.LabelFor(m => m.Password)
    </div>
    <div>
        @Html.EditorFor(m => m.Password)
    </div>

    <div class="left"></div>
    <div>
        <input type="submit" value="Login" />
    </div>
}

这是我使用表单身份验证的发布方法,但我必须在这里使用 ADFS 身份验证。

 [HttpPost]
    public ActionResult Index(LoginModel loginModel, string returnUrl)
    {
        if (ModelState.IsValid)
        {
            if (loginModel.Username == "user" && loginModel.Password == "password")
            {
                FormsAuthentication.SetAuthCookie(loginModel.Username, true);
                return Redirect(returnUrl);
            }
            else
            {
                ModelState.AddModelError("", "The username or password provided is incorrect.");
            }
        }

        ViewBag.ReturnUrl = returnUrl;

        return View(loginModel);
    }

这是我的索引方法,希望在用户中接收声明,然后重定向到 example.com

 public ActionResult Index()
    {
        if (User.Identity.IsAuthenticated)
        {
            var action = Request.QueryString[Action];

            if (action == SignIn)
            {
                var formData = ProcessSignIn(Request.Url, (ClaimsPrincipal)User);
                return new ContentResult() { Content = formData, ContentType = "text/html" };
            }
            else if (action == SignOut)
            {
                ProcessSignOut(Request.Url, (ClaimsPrincipal)User, (HttpResponse)HttpContext.Items["HttpResponse"]);
            }
        }

        return View();
    }

【问题讨论】:

    标签: model-view-controller single-sign-on adfs2.0


    【解决方案1】:

    ADFS 不允许自定义登录页面。 ADFS 本​​身会在您重定向到它时提供登录页面,并在使用 SAML 令牌成功验证后返回。

    example 用于 Azure AD,但说明了原则。

    只需使用 ADFS 元数据地址。

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多