Last updated
Last updated
The authentication domain within the FoodService application encompasses the functionalities related to user authentication, authorization, and user management. This domain ensures secure access to the application's resources by verifying the identity of users and managing their roles and permissions.
The AuthController
is responsible for handling incoming requests related to user authentication and authorization. It includes endpoints for user registration (SignUp
), user login (SignIn
), adding users to administrative roles (AddUserToAdminRole
), retrieving the current user (GetCurrentUser
), listing users (ListUsers
), and retrieving user details (GetUserDto
). This controller enforces authorization rules using ASP.NET Core's authorization attributes, restricting access to certain endpoints based on user roles.
The AuthCommand
class implements the business logic for authentication operations defined in the IAuthCommand
interface. It delegates the execution of these operations to the IAuthService
. The class handles user sign-up, sign-in, adding users to admin roles, retrieving the current user, listing users, and retrieving user DTOs. It encapsulates the responses using ResponseCommon
objects to indicate the success or failure of operations.
The AuthService
class provides implementations for authentication-related operations defined in the IAuthService
interface. It interacts with repositories, ASP.NET Identity's user manager, configuration settings, and HTTP context accessor to perform operations such as listing users, retrieving user details, updating and deleting users, user sign-up, adding users to admin roles, user sign-in, and retrieving the current user. This class utilizes ASP.NET Identity for user management and JWT authentication for generating authentication tokens.
/api/Auth/sign-up
HTTP Method: POST
Description: Registers a new user.
Request Body: Accepts a JSON object of type SignUpDto
.
Response: Returns a BooleanResponseCommon
indicating the success or failure of the operation.
Flowchart:
/api/Auth/sign-in
HTTP Method: POST
Description: Signs in a user.
Request Body: Accepts a JSON object of type SignInDto
.
Response: Returns an SsoDtoResponseCommon
containing the authentication token and user information.
Flowchart:
/api/Auth/add-user-to-admin-role
HTTP Method: POST
Description: Adds a user to the administrator role.
Request Body: Accepts an integer representing the user ID.
Response: Returns a BooleanResponseCommon
indicating the success or failure of the operation.
Flowchart:
/api/Auth/get-current-user
HTTP Method: GET
Description: Retrieves the currently authenticated user.
Response: Returns a UserBaseResponseCommon
containing information about the current user.
Flowchart:
/api/Auth/list-users
HTTP Method: GET
Description: Lists all users.
Response: Returns a ClientUserListResponseCommon
containing a list of users.
Flowchart:
/api/Auth/get-userdto
HTTP Method: GET
Description: Retrieves a user DTO by ID.
Parameters: Accepts an integer id
as a query parameter.
Response: Returns a UserDtoResponseCommon
containing the user DTO.
Flowchart: