惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
U
Unit 42
WordPress大学
WordPress大学
B
Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
D
DataBreaches.Net
G
Google Developers Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家

博客园 - 阿福

TypeScript forms authentication failed the ticket supplied was invalid错误 (Windows Server 2008 + IIS 7.5) jQuery Mobile 1.1.1 RC1发布 HashSet<T> vs List<T> 不要用把无序GUID既作为主键又作为聚集索引 WCF Data Services 5.0 RTM发布 EF Power Tools Beta 2发布 Entity Framework 5性能方面的注意事项 jQuery Mobile 1.1.0 RC2发布 源码+幻灯片:学习HTML5/jQuery/ASP.NET MVC/EF Code First的绝佳资源Account at a Glance项目 使用Autofac在ASP.NET Web API上实现依赖注入 在Windows Azure上开发ASP.NET程序与在Windows Sever上有何不同 充分利用缓存来提高网站性能 ASP.NET MVC 4, ASP.NET Web API, ASP.NET Web Pages v2 (Razor)全部开源,并接受来自社区的贡献(contributions) EF5 beta2通过NuGet发布 Getting Started with HTML5 开发HTML5应用你需要了解的 WCF入门资源 jquery history plugin, url hash Run Tasks in an ASP.NET Application Domain ASP.NET 2.0: 生成Excel报表 VS 2008 hot-fix终于出来了 Images; How to create an HTTP handler to dynamically resize images and change quality. ASP.NET 2.0: Add build-in paging feature to repeater/为repeater添加内置分页功能 Tip/Trick ASP.NET 2.0: DropDownList DataBind Ajax类库、框架、工具包完全列表 怀旧啊 Search Box ASP.NET 2.0: Site Maps Checking All CheckBoxes in a GridView
ASP.NET 2.0: Forms Authenticat...
阿福 · 2010-01-01 · via 博客园 - 阿福

Keywords: single sign-on, across applications, across domains.

目标:实现对www.domain.com, sub1.domain.com, sub2.domain.com......的统一权限认证,既single sign-on 单点登录。说明一点,这里的每个地址对应的是一个独立的应用,也就是说在IIS里它们都是一个实际的站点。这和运用URL Rewiting技术实现的二级域名访问是不同的。URL重写实现的二级域名访问,对应的服务器端其实只是一个应用。实际上,IIS在处理这种二级域名的请求时,首先会检查有没有实际的站点配置在IIS上,如果有就会转向这个这个站点(这里讨论的就是这种情况下的跨域认证问题),如果没有就会转向主机头为空的那个站点,例如访问sub1.domain.com,如果IIS上没有配置这个域名,则iis就会把它转向domain.com上,而URL Writing是在domain.com这个应用上进行的。扯远了,还是回到single sign-on上。

实现:跨域的身份认证换句话说就是实现对认证信息的共享,ASP.NET的Forms认证,认证信息默认是加密存储在cookie里的,所以只要对cookie的加密方式,密钥,存储位置进行统一,认证信息就可以共享了。ASP.NET 2.0中的实现其实非常简单,只要修改一些配置信息就可以了。以sub1.domain.com, sub2.domain.com两个应用为例,为了实现两者的统一认证,必须保证下列配置的一致(标注红色的部分):

     <authentication mode="Forms">
      <forms name=".ASPXAUTH" loginUrl="signin.aspx" defaultUrl="~/default.aspx" protection="All" timeout="30" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" domain="domain.com" enableCrossAppRedirects="true"/>
    </authentication>
    <machineKey validationKey='64E5DACAC6FB2B3E34FE06887639909EF2A180D6CDCB2463EAF098BA3E24A4FAC6C2A6E48C2F80FEE32A751C4B33D3EC70D73C59D64340E4CF7D9E44B0BA0077'   decryptionKey='BCCC63AF8E95BEA7393377CF2CF0CA35F1B5C09343404F44'   validation='SHA1'/>

另外,如果打算对角色信息也可以共享,例如在sub1.domain.com里认证为具有administrators角色的用户在进入sub2.domain.com后仍然是administrators,则要保证以下配置信息的一致:

    <roleManager cacheRolesInCookie="true" cookieName=".ASPXROLES" cookiePath="/" cookieProtection="All" cookieRequireSSL="false" domain="domain.com" cookieSlidingExpiration="true" cookieTimeout="30" createPersistentCookie="false" defaultProvider="SQLRoleProvider" enabled="true">
      <providers>
        <add name="SQLRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="MyConnectionString" applicationName="MyApp"/>
      </providers>
    </roleManager>

进而,如果想对认证信息统一进行管理,(如membersihp,roles),则应该对membersihp, rolemanager配置节的物理存储配置进行统一,主要是数据库的链接配置到统一的位置,applicationName配置成相同的。这时我们就会感觉到,ASP.NET 2.0 build-in的membersip, rolemanagement service,为我们实现集中的权限认证提供了便利。由于物理存储的结构相同,整合就变得十分方便。

附:下面这个链接可以用来生成machine key配置:
http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx
References:

MSDN Configuring Forms Authentication Across Applications
Creating a Single Sign-on for ASP.NET Application and Legacy ASP Application (Part II)
Single sign-on across multiple applications in ASP.NET
Single Sign-On for everyone - ASP.NET Forums