Here we migrate the provided ASP.NET web application that uses the SAML protocol to authenticate users and integrated with AD FS, to your Azure Active Directory tenant.
In the previous chapter 1-1 we integrated an ASP.NET web application with an AD FS instance.
After the migration, this sample will use the App Federation Metadata Url from the Azure Active Directory tenant, for authentication.
- Visual Studio
- .NET Framework 4.7.2
- An AD FS environment
- An Azure Active Directory (Azure AD) tenant. For more information on how to get an Azure Active Directory tenant, see How to get an Azure Active Directory tenant
- Sign in to the Azure portal using a tenant admin account.
- Navigate to the Microsoft identity platform for developers Enterprise applications page.
- Select New registration.
- Select Non gallery app.
- Choose a name for the application, for instance
WebApp_SAMLand select Add on the bottom. - Under the Manage section, select Single sign-on.
- Select SAML and the Set up Single Sign-On with SAML page will appear.
- To edit the basic SAML configuration options, select the Edit icon (a pencil) in the upper-right corner of the Basic SAML Configuration section.
- Set Identifier (Entity ID) with an unique URL that follows the pattern,
http://{your-appName}.{your-domain}.com. For instance:http://webappsaml.contoso.com. Copy the Entity ID value to be used in later steps. - Set Reply URL with the URL that Azure AD will reply after the authentication. In this sample we are using
https://localhost:44347/. - [Optional] Set the optional parameters if they are required in your scenario. The guide Moving application authentication from Active Directory Federation Services to Azure Active Directory is an excellent resource to learn about the various available options.
Learn more about configuring SAML-based single sign-on in Azure Active Directory.
By default, the claims givenname, surname, emailaddress and name will be already configured for the application.
The web application registered on chapter 1 also uses Employee-ID claim, so we need to configure that as well. If you added extra claims on the AD FS registration of the web application, follow the steps below to register all the additional claims that should be returned by the Azure AD SAML application:
- In the User Attributes and Claims section, select the Edit icon (a pencil) in the upper-right corner.
- Add additional claims that you would like to use in the web app project.
- To add a claim, select Add new claim at the top of the page.
- Enter the Name, for instance
employeeID. - Enter the Namespace if desired, for instance
http://schemas.xmlsoap.org/ws/2005/05/identity/claims. - Select the appropriate Source that contains the claim value. For Employee-ID, the source is Attribute.
- Select the appropriate Source Attribute or Transformation, depending on what you selected on the previous step. For Employee-ID, select
user.employeeid. - Select Save. The new claim appears in the table.
- In the SAML Signing Certificate section, if you don't have a certificate yet, select the Edit icon (a pencil) in the upper-right corner.
- Select New Certificate and then Save.
- Close the blade, refresh the page and copy the value for
App Federation Metadata Urlfield. We will use it on the .NET MVC project.
In Azure AD, it is possible to customize claims emitted in tokens for specific applications. Check the permitted values that can be emitted and SAML exceptions and restrictions.
In order to customize the claims emitted in tokens, you have to create a claim mapping policy and assign it to the desired application. Learn how to create and assign a claim mapping policy.
Open the project WebApp_SAML in your IDE (like Visual Studio) to configure the code.
- Open the Web.config file.
- Replace the value for
ida:ADFSMetadatawith the link that you copied from App Federation Metadata Url field. - Replace the value for
ida:Wtrealmwith the value that you set for Identifier (Entity ID). For instance,http://webappsaml.contoso.com. - Save, clean and build the solution.
Clean and build the solution, then run the WebApp_SAML application and sign-in using an on-premise user (who already got synced) or a user from your Azure AD tenant only.
All the claims configured on the User Attributes and Claims steps will be listed in the page, in case the signed-in user has a value set for it.
If you find a bug in the sample, raise the issue on GitHub Issues.
Were we successful in addressing your learning objective? Do consider taking a moment to share your experience with us.
We're always listening, and if you want to get in touch with you directly, send an email to aadappfeedback@microsoft.com.