IdentityAuthService is a .NET 8 Web API Application that utilizes MSSQL Server as its underlying database.
To configure IdentityAuthService for use with IdentityUser
, follow these steps:
-
Install the required NuGet packages:
- IdentityAuthService.DbContext
- IdentityAuthService.Services
- Microsoft.AspNetCore.Identity
- Microsoft.EntityFrameworkCore
-
Uncomment the following code snippet in
Startup.cs
to add theIdentityUser
service to the project:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetValue<string>("ConnectionStrings:DefaultConnection")));
services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
- Then utilize
Microsoft.AspNetCore.Identity.UserManager
to retrieve data from the identity database. - DbContext is also provided for managing
IdentityUser
.
- Consists of the following properties. These fields will be usable for other operations. The password will not be stored in the database.
string UserFirstName
string UserLastName
string UserEmailAddress
string UserPhoneNumber
string UserAddress
bool IsMigrated
The isMigrated
field tracks whether the user has been migrated from the database or not.
The AuthController
includes login and signup actions, both annotated with AllowAnonymous
and HttpPost
.
- Login: Expects
string SignInName
andstring Password
parameters to validate the user login process. - SignUp: Expects
string SignInName
,string FirstName
,string LastName
, andstring PhoneNumber
parameters. The password is stored in Azure AD B2C only. Essential user data is added to the custom database for other operations.
The AuthService
manages essential user data for other operations. Since users are migrated, updates to the Identity User table are unnecessary.
- UserLoginValidation: Checks user availability in the database. If the user is available but not marked as migrated, it updates the user as migrated and returns
userDetails
,roles
, andneedToMigrate
(set to 'local') fields with a 200 OK status. If the user is available but already marked as migrated, it returnsroles
andneedToMigrate
(set to null) fields with a 200 OK status. - UserSignUpValidation: Checks user availability in the database. If the user is available, it returns
true
. Otherwise, it adds essential user details to the User database and returnsfalse
.