Do I need to use the Windows Identity Federation Utility to create a claims-aware asp.net web application?

拜拜、爱过 提交于 2020-01-05 05:57:11

问题


I built a claims-aware asp.net mvc application following the steps outlined in this page: https://docs.microsoft.com/en-us/dotnet/framework/security/how-to-build-claims-aware-aspnet-mvc-web-app-using-wif. The example in the page uses an STS on the local host, but in my application I am pointing to a fully-functioning AD FS on a different server.

I'm using Framework 4.7 and Windows Server 2016 to host the AD FS and to host the web application.

After I deployed the application I ran the Windows Identity Federation Utility against it (because I thought I needed it to add the application as a Relying Party Trust on the AD FS). This utility inserts a lot of tags into the web.config that refer to the Microsoft.IdentityModel namespace.

I then added the application as a Relying Party Trust to the AD FS, and navigated to the claims-aware app. The page failed because the sample code cast the claim returned by the STS as System.Security.Claims.Claim. When I changed it to cast as Microsoft.IdentityModel.Claims.Claim it worked fine.

The example I was following makes no mention of the Windows Identity Federation Utility. Do I need to use that? Or would this have worked without it?

When I try reversing the web.config changes that the utility inserted the site fails with a 401 error (access denied due to invalid credentials) so obviously the stuff inserted by the Utility is needed to get authentication from AD FS. Is this because I ran the Utility on the web site before adding it as a relying party trust to the ADFS?


回答1:


The answer here is: don't run the Windows Identity Federation Utility if you are using ADFS Server 2016, as it forces use of the Microsoft.Identity libraries, which are deprecated. I mistakenly thought this utility was needed to create the FederationMetadata.xml file.

I created the FederationMetadata.xml file manually and reverted my web.config back to what it was before I ran the utility. This reverted me back to using the System.Identity libraries, which were added to the 4.5 framework, instead of the now-deprecated Microsoft.Identity libraries.




回答2:


Just to note that the more "modern way" is to use the OWIN WS-Federation library.

This example is for Azure AD but you simply point to the metadata and the code figures all the rest out for itself.



来源:https://stackoverflow.com/questions/50380722/do-i-need-to-use-the-windows-identity-federation-utility-to-create-a-claims-awar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!