Well, it took me a long time to figure it out, but those were the things that I did to get it to work. Much more needs to be done.
Prerequisites:
- ADFS 2.0 is running somewhere in your domain.
- IIS 7 with a self-signed certificate or certificate that you can use in your domain.
- Visual Studio 2012 with the Identity and Access extension installed (version 1.0.2).
- The MVC4 web application is configured to work in IIS.
- Make sure that a self-signed certificate is added to the site so that you can access it through https.
- You may need to configure the firewall settings for your computers to allow access to your ADFS 2.0 service.
At a development workstation
In the MVC4 project
- Open the Authentication and Access dialog box by right-clicking your web project.
- Select Use a business identity provider (for example, ADFS2)
- Enter the path to the STS metadata document, for example. https: // {PATH TO ADFS SERVER} /FederationMetadata/2007-06/FederationMetadata.xml
- Enter an area for your application, for example. https: // {web application url} /
- The end slash matters.
- Exit the dialogue by accepting these changes.
Add the following code to your project
using System; using System.IdentityModel.Services; namespace NAMESPACE { public class FixedWsFederationAuthenticationModule : WSFederationAuthenticationModule { public override void RedirectToIdentityProvider(string uniqueId, string returnUrl, bool persist) {
On ADFS 2.0 Server
- If you used a self-signed certificate, go to your https: // {web application URL} / web application and change the zone to a trusted site.
- In the address bar of the browser, you can right-click on the certificate and install (you can install certificates only from trusted sites). The certificate must be installed in trusted root services → Registry,
- Open the ADFS console, add the relying relying parties, with the address Federated Metadata https: // {URL of the web application} /FederationMetadata/2007-06/FederationMetadata.xml
Add some custom rules
MVC4 needs these rules to make usable ClaimsPrincipal
Add a skip rule to the Name property.
And these 2 user rules
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Value = "true"); => issue(Type = "http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", Value = "true");
source share