This project implements a secure login system using Microsoft Azure App Registration in an ASP.NET Core MVC application, allowing users to authenticate using their Microsoft accounts.
- Register a new application in the Azure Portal to obtain
ClientId
andClientSecret
. - Configure these values in the ASP.NET Core application to set up the authentication service.
- Integrate Microsoft authentication by adding necessary services and settings in
Program.cs
. - Use
AddAuthentication()
to specifyClientId
andClientSecret
from Azure App Registration. - Configure
DbContext
to use SQL Server for storing user and role data. - Implement Identity for user and role management, including authentication and login policies.
The UsersController
manages login and logout functionalities, integrating external Microsoft account logins.
Login()
: Displays the login form. Users can initiate the login process with their Microsoft account.ExternalLogin()
: Redirects the user for Microsoft account authentication and specifies the callback action.RegisterExternalUser()
: Handles the callback from Microsoft authentication, registers the user if new, and signs them in.Logout()
: Signs the user out of the application.
- The user clicks to log in using their Microsoft account.
- They are redirected to Microsoft for authentication.
- Upon successful authentication, the callback (
RegisterExternalUser
) either logs the user in directly (if already registered) or creates a new user account and then logs the user in.
Integrating Azure App Registration in an ASP.NET Core MVC application enables a secure and convenient way for users to log in using their Microsoft accounts, leveraging modern technologies to enhance software development quality.