Enhance Authentication Middleware to Support JWT and Legacy Auth Tokens

XMLWordPrintable

    • Type: Task
    • Resolution: Done
    • Priority: Highest
    • 3.1.0
    • Affects Version/s: None
    • None
    • AMRIT Sprint 37
    • Platform
    • All

      Update the authentication middleware to handle both modern JWT-based tokens and legacy auth tokens. The implementation should follow the priority and fallback order as described below

       

      Implementation Steps:

      1.Check for JWT token in cookies:

      • Look for a cookie (e.g., JwtToken in cookie).
      • If valid, decode and authenticate.

      Ref: https://github.com/PSMRI/HWC-API/blob/884dacdb7ba52a8b0ef56126f5b632499aef297d/src/main/java/com/iemr/hwc/utils/JwtUserIdValidationFilter.java#L69

      2. Check JwtToken in header

      • Look for a cookie (e.g., JwtToken in header).
      • If valid, decode and authenticate.

      Ref: https://github.com/PSMRI/HWC-API/blob/884dacdb7ba52a8b0ef56126f5b632499aef297d/src/main/java/com/iemr/hwc/utils/JwtUserIdValidationFilter.java#L52

      3. Fallback to Authorization header with legacy auth token:

      • If JWT not found in cookie or header, check the Authorization header.
      • Extract the token part from the header (remove the {{Bearer }} prefix).
      • Treat the token as a legacy auth token.
      • Authenticate using the legacy token validation logic.

      Ref: https://github.com/PSMRI/HWC-API/blob/884dacdb7ba52a8b0ef56126f5b632499aef297d/src/main/java/com/iemr/hwc/utils/http/HTTPRequestInterceptor.java#L90

       

      4.Error handling:

      • If none of the above validations succeed, return appropriate 401 Unauthorized response.

       

      Acceptance Criteria

      1. Old requests from currently deployed FLW app must get appropriate response when legacy auth token is sent in Authorization Bearer.
      2. New requests from existing FLW app under development sending JWT token in header must work.
      3. New requests from existing web interfaces must work (JWT in cookie).

            Assignee:
            Ravi Shanigarapu
            Reporter:
            Dr Mithun James
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: