This document provides a brief overview of the different API endpoints, their usage and purpose.
This section lists the authentication related requests such as login.
Allows the user to login into the portal and receive the auth token from the API. Requires the user email and password values.
Here is a step-by-step breakdown of the user login flow:
-
Client-Side Request
The client sends a login request to the server.
-
AuthenticationController Handling
The
AuthenticationControllercaptures the login request through thePOST /loginendpoint. -
Service Delegation
The
AuthenticationControllerdelegates the login process to theAuthenticationService. -
AuthenticationService Processing
The
AuthenticationServiceis responsible for processing the login request. It interacts with theUserRepositoryto verify user credentials. -
UserRepository Database Interaction
The
UserRepositoryinteracts with the database to:- Utilize
PasswordSignInAsyncfunction for password validation provided bySignInManagercomponent of Asp.Net Identity. - Retrieve user details using
UserManagerfunction's provided by Asp.Net Identity.
- Utilize
-
JWT Token Generation
Upon successful login, the
AuthenticationServicegenerates a JWT token using user information. -
Response to Client
The
AuthenticationControllerresponds to the client with the generated JWT token.
The user login flow involves the client sending a login request, which is handled by the AuthenticationController. The controller delegates the login process to the AuthenticationService, and the user credentials are verified by interacting with the UserRepository. If successful, a JWT token is generated and sent back to the client. This flow ensures a secure and structured user login process, utilizing key components provided by ASP.NET Identity and Entity Framework.
User Table
Endpoint: http://localhost:5000/api/auth/register
Method: POST
Body:
{
"email": "example@gmail.com",
"password": "Change@123"
}cURL
curl -X 'POST' \
'http://localhost:5000/api/auth/login' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"email": "example@gmail.com",
"password": "Change@123"
}'Sample response
{
"token": "<AUTH_TOKEN>"
}Allows the new user to register into the portal and receive the auth token from the API. Requires the user details (firstname,lastname,email) and password values.
Here is a step-by-step breakdown of the user registration flow:
-
Client-Side Request
The client sends a registration request to the server.
-
AuthenticationController Handling
The
AuthenticationControllercaptures the registration request through thePOST /registerendpoint. -
Service Delegation
The
AuthenticationControllerdelegates the registration process to theAuthenticationService. -
AuthenticationService Processing
The
AuthenticationServiceis responsible for processing the registration request.It interacts with theUserRepositoryto handle user-related database operations. -
UserRepository Database Interaction
The
UserRepositoryinteracts with the database to:- Create a new
IdentityApplicationUser(an identity entity). - Use
CreateAsyncmethod ofUserManagerComponent to create a new identity user - Add user details to the
ApplicationUserentity. - Associate user roles.
- Commit the changes to the database within a transaction.
- Create a new
-
JWT Token Generation
Upon successful registration, the
AuthenticationServicegenerates a JWT token using user information. -
Response to Client
The
AuthenticationControllerresponds to the client with the generated JWT token.
The overall flow ensures a secure and structured user registration process using key components provided by ASP.NET, including Identity for user management and Entity Framework for database interactions. The separation of concerns among the controller, service, and repository ensures maintainability and scalability of the authentication process.
User Table
User Role
Endpoint: http://localhost:5000/api/auth/register
Method: POST
Body:
{
"firstName": "firstname",
"lastName": "lastname",
"email": "example@gmail.com",
"password": "Change@123"
}cURL
curl -X 'POST' \
'http://localhost:5000/api/auth/register' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"firstName": "firstname",
"lastName": "lastname",
"email": "example@gmail.com",
"password": "Change@123"
}'Sample response
{
"token": "<AUTH_TOKEN>"
}Allows the user to send forget password request to the portal and receive the reset token that is used to change the password from the API. Requires the user email.
Here is a step-by-step breakdown of the forgot password flow:
-
Client-Side Request
The client sends a forgot password request to the server.
-
AuthenticationController Handling
The
AuthenticationControllercaptures the forgot password request through thePOST /forgot-passwordendpoint. -
Service Delegation
The
AuthenticationControllerdelegates the forgot password process to theAuthenticationService. -
AuthenticationService Processing
The
AuthenticationServiceis responsible for initiating the forgot password process.It interacts with theUserRepositoryto find the user by email. -
UserRepository Database Interaction
The
UserRepositoryinteracts with the database to:- Use
UserManager.FindByEmailAsyncto find a user by email. - Generate a password reset token using
GeneratePasswordResetTokenAsyncprovided byUserManagerComponent of Asp.Net Identity.
- Use
-
Email Notification
The password reset token is sent to the user's email.The
SendForgetPasswordEmailAsyncfunciton ofIEmailRepositoryis used for sending the email viaosmo-x. -
Response to Client
The
AuthenticationControllerresponds to the client with a message indicating that the password reset process has been initiated.
The forgot password flow involves the client initiating a request, which is handled by the AuthenticationController. The controller delegates the process to the AuthenticationService, and the necessary steps are taken in the UserRepository. A password reset token is generated, sent to the user's email for verification, and a response is provided to the client. This ensures a secure and structured forgot password process using ASP.NET Identity and Entity Framework components.
Endpoint: http://localhost:5000/api/auth/forgot-password
Method: POST
QueryParam:
email = example@gmail.com
cURL
curl -X 'POST' \
'http://localhost:5000/api/auth/forgot-password?email=example%40gmail.com' \
-H 'accept: */*' \
-d ''Sample response
200: SuccessSample Mail
Allows the user to change the password for portal login. Requires reset token, user email and new password value.
Here is a step-by-step breakdown of the reset password flow:
-
Client-Side Request
The client sends a reset password request to the server.
-
AuthenticationController Handling
The
AuthenticationControllercaptures the reset password request through thePOST /reset-passwordendpoint. -
Service Delegation:
The
AuthenticationControllerdelegates the reset password process to theAuthenticationService. -
AuthenticationService Processing
The
AuthenticationServiceis responsible for processing the reset password request.It interacts with theUserRepositoryto reset the user's password. -
UserRepository Database Interaction
The
UserRepositoryinteracts with the database to:- Use
UserManager<IdentityApplicationUser>to find the user by email. - Reset the user's password using
ResetPasswordAsyncfunction provided by UserManger of Asp.Net Identity.
- Use
-
JWT Token Generation
Upon successful password reset, the
AuthenticationServicegenerates a new JWT token using user information. -
Response to Client
The
AuthenticationControllerresponds to the client with the generated JWT token.
The reset password flow involves the client initiating a request, which is handled by the AuthenticationController. The controller delegates the process to the AuthenticationService, and the necessary steps are taken in the UserRepository. Upon successful password reset, a new JWT token is generated and sent to the client. This ensures a secure and structured reset password process using ASP.NET Identity and Entity Framework components.
Endpoint: http://localhost:5000/api/auth/reset-password
Method: POST
Body:
{
"email": "example@gmail.com",
"token": "<RESET_TOKEN>",
"password": "Change@123"
}cURL
curl -X 'POST' \
'http://localhost:5000/api/auth/reset-password' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"email": "example@gmail.com",
"token":"<RESET_TOKEN>",
"password": "Change@123"
}'Sample response
{
"token": "<AUTH_TOKEN>"
}


