Introduction
Microsoft Entra ID (formerly Azure Active Directory) provides authentication and authorization capabilities for modern applications. Integrating Entra ID with a .NET application using OWIN (Open Web Interface for .NET) middleware allows seamless authentication using industry-standard protocols such as OpenID Connect and OAuth 2.0.
Use case
Most of the legacy applications use the .NET Framework, and the Enterprise will look to integrate the Entra ID as an Identity provider into these applications for the SSO, as part of cloud adoption. In this use case, sometimes you may not get time to modernize the legacy application, or you may prefer a phase-by-phase approach to modernize the application. In this case, you can use OWIN libraries in your .NET Framework application to integrate with Microsoft Entra ID for Single sign-on.
In this article, I will explain how to integrate Microsoft Entra ID with a .NET application using OWIN libraries.
Step 1. Register the Application in Microsoft Entra ID.
To enable authentication, you need to register your application using the Microsoft Entra ID portal.
- Go to the Microsoft Entra ID portal.
- Navigate to App registrations > New registration.
- Enter a name for your application.
- Set the Supported account types (Single Tenant or Multi-Tenant).
- Specify the Redirect URI (e.g., https://localhost:44300/signin-oidc).
- Click Register.
- Copy the Application (client) ID and Directory (tenant) ID.
Step 2. Install Required OWIN Packages.
In your .NET Framework application, install the necessary OWIN NuGet packages by running the following commands in the Package Manager Console.
Step 3. Configure OWIN Middleware.
In the Startup.cs file, configure OWIN to use Microsoft Entra ID authentication.
Create a Startup.Auth.cs file under the app start folder if it does not exist and put the code below.
Note. Don’t forget to add this attribute [assembly: OwinStartup(typeof(EntraId_Owin_Net_Framework.Startup))]
Step 4. Enable Authentication in Web.config
Ensure your Web.config has authentication mode set to None, as OWIN handles authentication.
Add below app settings, ensure replace the ClientID, RedirectUri, TenantID, and Domain.
Step 5. Create AccountController and View.
Create AccountController and add the below code to implement SignIn and SignOut Action.
_LoginPartial.cshtml
Step 6. Run and Test the Application.
- Run the application.
- Navigate to a protected route (e.g., https://localhost:44300/home).
- The app should redirect to the Microsoft Entra ID login page.
- Enter your credentials and complete authentication.
- The application should successfully authenticate and redirect back to your app.
![Login]()
Conclusion
Integrating Microsoft Entra ID Single Sign On with a .NET application using OWIN libraries provides secure authentication leveraging OpenID Connect. By following these steps, you can easily configure authentication and enhance security in your .NET applications.