Skip to main content
Version: MNSR

Authentication Service

Author(s)

  • Arpita Dey

Last Updated Date

[2024-11-14]


SRS References

  • 2.1.2

Version History

VersionDateChangesAuthor
1.02024-11-14Initial draftArpita Dey
............

Feature Overview

Objective:
The authentication service provides a secure and efficient mechanism for user authentication and session management. This service enables users to log in and log out of the portal with different authentication methods tailored for mobile and web platforms. Mobile devices leverage stateless authentication using JWT (JSON Web Tokens), ensuring quick, token-based access without maintaining server-side sessions. Web users benefit from a refresh token mechanism that facilitates secure and seamless session persistence. Additionally, the service extends functionality to enable administrative capabilities, such as viewing the list of all users, creating or updating user profiles, and managing role scopes through add and edit functions.

Scope:

  • User authentication for web and mobile platforms
  • Role-based access control management
  • User session management
  • User profile management
  • Scope and permission management

Dependencies:

  • JWT Token Library
  • Password Hashing Library
  • Database Access Layer
  • Caching Service
  • Email Service (for password reset)

Requirements

(List all the functional and non-functional requirements that the feature must meet.)

  1. Web devices must use refresh token-based authentication
  2. Mobile devices must use JWT token-based authentication
  3. Scope Management:
    • Support multiple scope types (Payroll, Attendance, Authentication)
    • Each type can have multiple scopes (e.g., Payroll.view, Payroll.get, Payroll.set)
  4. Role Management:
    • Support multiple role types (Admin, Manager, Worker)
    • One role can have multiple scopes (many-to-one relationship)
    • Predefined role configurations:
      • Admin: Access to Payroll, Attendance, Authentication
      • Manager: Access to Payroll, Attendance
  5. User Management:
    • One-to-one relationship between user and role
    • Example: user@example.com has Admin role
  6. Core Authentication Features:
    • User login/logout functionality
    • View/create/update user profiles
  7. Role Management Features:
    • GetRoles, GetMinimalRoles, GetScopes
    • AddRole, UpdateRole, DeleteRole

Design Specifications

(Provide detailed design specifications, including UI/UX designs, API interfaces, and any other relevant architectural details.)

  • UI/UX Design:
    The UI should provide intuitive login and registration screens with clear options for both web and mobile platforms. Additionally, user role management should be easily accessible for admin users, with simple forms for adding and editing user roles and scopes.

  • Data Models:
    (Detail the data structures, including database schemas or objects.)

public record ScopeMaster
{
public required string Name { get; set; }
public required bool Value { get; set; }
}
public record ScopeDetails : ScopeMaster
{
public required ScopeType Type { get; set; }
public required string Description { get; set; }
}
public class MinimalRoleDetails
{
public Guid? RoleId { get; set; }
public required string Role { get; set; }
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
public required RoleType Type { get; set; }
}
public class RoleMaster : MinimalRoleDetails
{
[JsonIgnore]
public int TotalNumber { get; set; }
public DateTime? Created { get; set; }
public DateTime? Updated { get; set; }
}
public class RoleDetails : MinimalRoleDetails
{
public required List<ScopeMaster> Scopes { get; set; }
}
public record LogInUser
{
[Required(ErrorMessage = "Username is required")]
public required string Username { get; init; }

[Required(ErrorMessage = "Password is required")]
[DataType(DataType.Password)]
public required string Password { get; init; }
}
public class User
{
public string? FirstName { get; set; }

public string? LastName { get; set; }

[Required(ErrorMessage = "Password is required")]
[DataType(DataType.Password)]
public required string Password { get; set; }

[Required(ErrorMessage = "Email is required")]
[EmailAddress]
public required string Email { get; set; }

[Phone]
public string? Phone { get; set; }

[Required(ErrorMessage = "User role is required")]
public required string Role { get; set; }
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
public RoleType Type { get; set; } = RoleType.User;

public UserStatus Status { get; set; } = UserStatus.Uninitialized;

[DataType(DataType.DateTime)]
public DateTime? Created { get; set; }

[DataType(DataType.DateTime)]
public DateTime? Updated { get; set; }
}
public enum OperationType
{
Insert,
Update
}
public record UserRecord(string Email, string Role, string? FirstName, string? LastName, string? Phone, UserStatus Status = UserStatus.Uninitialized)
{
[DataType(DataType.Password)]
public string? Password { get; set; }

[DataType(DataType.DateTime)]
[JsonIgnore]
public DateTime? Created { get; set; } = DateTime.UtcNow;

[DataType(DataType.DateTime)]
[JsonIgnore]
public DateTime? Updated { get; set; } = DateTime.UtcNow;
}
  • API Interfaces:
EndpointMethodParametersResponseResponse Status Codes
/api/auth/loginPOSTLogInUser200 OK, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error
/api/auth/token/refreshGETNone200 OK, 401 Unauthorized, 404 Not Found, 500 Internal Server Error
/api/auth/logoutGETNone200 OK, 401 Unauthorized, 500 Internal Server Error
/api/auth/usersGETNoneList Of User200 OK, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error
/api/auth/user/createorupdatePOST[Required] OperationType, UserRecord204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict, 500 Internal Server Error
/api/auth/get/rolesGETint pageNumber, int rowsPerPageList Of RoleMaster200 OK, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error
/api/auth/get/scopesGETGuid? roleId, string? roleList Of RoleMaster200 OK, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error
/api/auth/add/rolePOSTRoleDetails200 OK, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error
/api/auth/update/rolePUTRoleDetails204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error
/api/auth/delete/roleDELETEGuid roleId204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 500 Internal Server Error
  • Third-Party Integrations:
    None

  • Workflow:
    alt text


Development Tasks & Estimates

(Break down the development process into smaller tasks and provide time estimates for each.)

NoTask NameEstimate (Hours)DependenciesNotes
1Introduce Scope Management System3.5 hoursNoneImplementing scope types and values.
2Introduce Role Management System2 hoursTask 1Defining roles and their permissions.
3Introduce User Management System3 hoursTask 2Adding user profile management functionality.
4Introduce Login & Logout4.5 hoursTask 1, 2, 3Implementing JWT and refresh token authentication.
5Total13 hours

Testing & Quality Assurance

(List all the relevant test cases for this feature.)

Test Case IDDescriptionExpected ResultStatus
TC01Test login with valid credentialsReturns 200 OK and a valid JWT or refresh tokenPending
TC02Test login with invalid credentialsReturns 401 UnauthorizedPending
TC03Test role assignment functionalityReturns the correct role with associated scopesPending
TC04Test user profile creationUser is successfully created with assigned rolePending
TC05Test logout functionalityReturns 200 OK, session terminatedPending

Deployment Considerations

  • None

Risks & Mitigations

(Identify potential risks and the strategies to mitigate them.)

RiskImpactLikelihoodMitigation Strategy
Risk 1HighMediumStrategy for mitigating Risk 1
Risk 2MediumHighStrategy for mitigating Risk 2
............

Review & Approval

(Include a section for review and approval by stakeholders.)

  • Reviewer:
    (Name and role of the person reviewing the document.)

  • Approval Date:
    (Date when the feature is approved for development.)


Notes
(Add any additional notes or considerations related to the feature development here.)