Implement API to log in through MPIN authentication. #87

Merged
ashutosh.nehete merged 1 commits from Ashutosh_Task#484_Login_MPIN into Issue_Jun_1W_2 2025-06-07 08:01:04 +00:00
Collaborator

1. Validate MPIN Token

  • Uses _refreshTokenService.ValidateToken to validate the token (verifyMPIN.MPINToken).
  • Checks that the token is authenticated.
  • If the token is invalid or unauthenticated:
    • Logs a warning.
    • Returns 401 Unauthorized.

2. Extract Claims from Token

  • Retrieves these claims from the token:
    • token_type
    • TenantId
    • NameIdentifier (User ID)
  • If any of the claims are missing:
    • Logs a warning.
    • Returns 401 Unauthorized.

3. Fetch Employee Using Token Details

  • Converts TenantId to GUID.
  • Fetches the Employee using:
    • verifyMPIN.EmployeeId
    • TenantId from the token
    • ApplicationUserId from the token
  • Ensures employee is active.
  • If not found or invalid:
    • Logs a warning.
    • Returns 400 Bad Request.

4. Validate Token-Employee Match

  • Checks that the ApplicationUserId from token matches the one on employee.
  • Ensures token_type is "mpin".
  • If mismatch:
    • Logs a warning.
    • Returns 401 Unauthorized.

5. Check MPIN Input

  • Validates that verifyMPIN.MPIN is not null or empty.
  • If empty:
    • Logs a warning.
    • Returns 400 Bad Request.

6. Fetch MPIN Details from DB

  • Finds existing MPIN record for the user and tenant.
  • If not found:
    • Logs a warning.
    • Returns 400 Bad Request indicating MPIN isn't set.

7. Compare Hashed MPIN

  • Computes SHA256 hash of input MPIN.
  • Compares it with the stored MPIN hash.
  • If they don't match:
    • Logs a warning.
    • Returns 401 Unauthorized.

8. Generate Tokens

  • If MPIN is correct:
    • Generates a new JWT access token.
    • Generates a refresh token.
  • Logs success message for MPIN verification.

9. Return Successful Login Response

  • Returns 200 OK with:
    • token
    • refreshToken
    • Success message: "User logged in successfully."

10. Exception Handling

  • Logs unexpected errors and returns:
    • 500 Internal Server Error
    • Message: "Unexpected error"
**1. Validate MPIN Token** * Uses _refreshTokenService.ValidateToken to validate the token (verifyMPIN.MPINToken). * Checks that the token is authenticated. * If the token is invalid or unauthenticated: * Logs a warning. * Returns 401 Unauthorized. **2. Extract Claims from Token** * Retrieves these claims from the token: * token_type * TenantId * NameIdentifier (User ID) * If any of the claims are missing: * Logs a warning. * Returns 401 Unauthorized. **3. Fetch Employee Using Token Details** * Converts TenantId to GUID. * Fetches the Employee using: * verifyMPIN.EmployeeId * TenantId from the token * ApplicationUserId from the token * Ensures employee is active. * If not found or invalid: * Logs a warning. * Returns 400 Bad Request. **4. Validate Token-Employee Match** * Checks that the ApplicationUserId from token matches the one on employee. * Ensures token_type is "mpin". * If mismatch: * Logs a warning. * Returns 401 Unauthorized. **5. Check MPIN Input** * Validates that verifyMPIN.MPIN is not null or empty. * If empty: * Logs a warning. * Returns 400 Bad Request. **6. Fetch MPIN Details from DB** * Finds existing MPIN record for the user and tenant. * If not found: * Logs a warning. * Returns 400 Bad Request indicating MPIN isn't set. **7. Compare Hashed MPIN** * Computes SHA256 hash of input MPIN. * Compares it with the stored MPIN hash. * If they don't match: * Logs a warning. * Returns 401 Unauthorized. **8. Generate Tokens** * If MPIN is correct: * Generates a new JWT access token. * Generates a refresh token. * Logs success message for MPIN verification. **9. Return Successful Login Response** * Returns 200 OK with: * token * refreshToken * Success message: "User logged in successfully." **10. Exception Handling** * Logs unexpected errors and returns: * 500 Internal Server Error * Message: "Unexpected error"
ashutosh.nehete added 1 commit 2025-06-07 07:59:31 +00:00
ashutosh.nehete merged commit 9f37c37e18 into Issue_Jun_1W_2 2025-06-07 08:01:04 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/marco.pms.api#87
No description provided.