简体   繁体   English

.NET MVC身份验证 - 表单+ Windows身份验证

[英].NET MVC Authentication - Forms + Windows Authentication

I am currently working on a project that has a requirement that is causing me some issues and I want to know the best way of handling it. 我目前正在开发一个项目,该项目的要求导致了一些问题,我想知道处理它的最佳方法。

Essentially we would like internal users to be able to access the MVC application and be authenticated through AD, this we want to be pretty much like SSO, they sign on to their computer navigate to the site and they are in. 基本上我们希望内部用户能够访问MVC应用程序并通过AD进行身份验证,我们希望它们非常像SSO,他们登录到他们的计算机导航到站点并且他们在。

The second type of users are outside partners that do not exist in our AD and we want to manage through our SQL Server. 第二类用户是我们AD中不存在的外部合作伙伴,我们希望通过SQL Server进行管理。 For these users we want to display a login page and do forms authentication. 对于这些用户,我们希望显示登录页面并进行表单身份验证。

My thoughts at first were simple, let IIS try and authenticate with windows authentication and if it fails (401) redirect to a login page. 我的想法一开始很简单,让IIS尝试使用Windows身份验证进行身份验证,如果失败(401)重定向到登录页面。 I don't currently have an environment to test this in but from my understanding in IIS7 it is not that simple and requires a little bit of a "hack" to accomplish. 我目前没有一个可以测试它的环境,但是根据我在IIS7中的理解,它不是那么简单,需要一点“黑客”来完成。 I need to avoid anything like that I need a solution that works as the system was designed to work and not by tricking it. 我需要避免这样的事情,我需要一个解决方案,因为系统设计工作,而不是欺骗它。

I have looked into ADFS and WIF but ADFS only supports AD not SQL and from what I've seen there is no STS that supports SQL Server. 我已经研究过ADFS和WIF,但是ADFS只支持AD而不支持SQL,而且从我看到的是没有支持SQL Server的STS。 I have contemplated hosting both an internal application that used windows authentication and external application that used forms authentication but I want to avoid this if possible. 我已经考虑过托管使用Windows身份验证的内部应用程序和使用表单身份验证的外部应用程序,但我想尽可能避免这种情况。

Ideally the flow that we want is user navigates to the MVC application IIS tries to do windows authentication, if it fails (401) redirect them to the login page. 理想情况下,我们想要的流程是用户导航到MVC应用程序IIS尝试执行Windows身份验证,如果失败(401)将它们重定向到登录页面。 From there the login page will authenticate the user credentials against the SQL Database. 从那里登录页面将根据SQL数据库验证用户凭据。 What is the best way of accomplishing this all within 1 MVC application? 在1 MVC应用程序中实现这一切的最佳方法是什么?

Thank you! 谢谢!

I would just implement my own authentication on top of FormsAuthentication or OWIN if you are using ASP.NET MVC 5. It is really simple and you will have full control over where you go to authenticate users. 如果您使用的是ASP.NET MVC,我会在FormsAuthentication或OWIN之上实现自己的身份验证。它非常简单,您可以完全控制对用户进行身份验证的位置。 Trust me it isn't as scary as it sounds. 相信我并不像听起来那么可怕。 I've written a few posts about it that you might find interesting. 我写了一些你可能感兴趣的帖子。

MVC 5 MVC 5

http://www.khalidabuhakmeh.com/asp-net-mvc-5-authentication-breakdown-part-deux http://www.khalidabuhakmeh.com/asp-net-mvc-5-authentication-breakdown-part-deux

MVC 4 MVC 4

http://tech.pro/tutorial/1216/implementing-custom-authentication-for-aspnet http://tech.pro/tutorial/1216/implementing-custom-authentication-for-aspnet

I currently use the MVC 4 method to authenticate against an Active Directory domain with great success. 我目前使用MVC 4方法对Active Directory域进行身份验证,并取得了巨大成功。 The only thing I would recommend is you Cache your calls to Active Directory as it can be unreliable at times. 我建议的唯一一件事就是将您的呼叫缓存到Active Directory,因为它有时可能不可靠。

There is the STS that supports sql server, it is the IdentityServer. 有支持sql server的STS,它是IdentityServer。

https://github.com/thinktecture/Thinktecture.IdentityServer.v2 https://github.com/thinktecture/Thinktecture.IdentityServer.v2

It even supports custom membership providers which give you quite a lot of different possibilities. 它甚至支持自定义成员资格提供程序,为您提供了很多不同的可能性。 I am not sure however if it supports automatic fallback to forms when integrated authentication fails. 我不确定它是否支持在集成身份验证失败时自动回退到表单。 If not, there are two options: a custom sts or two explicit stses and an explicit choice for users. 如果没有,则有两个选项:自定义sts或两个显式stses以及用户的显式选择。 We have implemented the latter scenario once with ADFS - there were two adfses, one with Forms, the other one with integrated auth, first one federated with the other. 我们用ADFS实现了后一个场景 - 有两个adfses,一个是Forms,另一个是集成auth,第一个是另一个。 This gives an explicit choice on the home realm discovery page - ".would you like to log in with username/password or try the integrated authentication" 这在home realm发现页面上给出了明确的选择 - “。你想用用户名/密码登录还是尝试集成身份验证”

You could create a project that uses "On-Premises Authentication" which uses ADFS to authenticate users. 您可以创建一个使用“内部部署身份验证”的项目,该项目使用ADFS对用户进行身份验证。 The on-premises authority URI will be: 内部部署权限URI将是:

https://yourADFSservername/federationmetadata/2007-06/federationmetadata.xml

After your project is loaded, you can to goto your ADFS settings and create a new "Relying Party Trust" and pass on HTTPS URL that your MVC app will be using. 加载项目后,您可以转到ADFS设置并创建新的“信赖方信任”并传递您的MVC应用将使用的HTTPS URL。 Setup to used LDAP attributes as claims and that will sort out AD authentication easily as it will navigate users to organisational sign-in page just like Office 365. Then if authentication fails for certain users, take the user to send the user to normal sign-in/signup page that exists independently of AD and connected to SQL server. 设置为使用LDAP属性作为声明,并且将轻松地对AD身份验证进行排序,因为它将用户导航到组织登录页面,就像Office 365一样。然后,如果某些用户的身份验证失败,请让用户将用户发送到正常的签名 - in / signup页面,独立于AD并连接到SQL Server。 You could skip windows authentication altogether by using on-premises authentication. 您可以使用内部部署身份验证完全跳过Windows身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM