Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-22986

[fiware-stackoverflow] Trouble accessing custom header in AJAX response using jQuery in Fiware Keyrock

    Details

      Description

      Created question in FIWARE Q/A platform on 31-03-2024 at 09:03
      Please, ANSWER this question AT https://stackoverflow.com/questions/78250593/trouble-accessing-custom-header-in-ajax-response-using-jquery-in-fiware-keyrock

      Question:
      Trouble accessing custom header in AJAX response using jQuery in Fiware Keyrock

      Description:
      I'm having trouble accessing a custom header named X-Subject-Token in the response of an AJAX request using jQuery. Here's my code:
      async function submitHandler(e) {
      e.preventDefault();
      let BASE_URL = "http://

      {my-ip}

      :3005"
      if (usernameInput.value && passwordInput.value) {

      let json =

      { name: usernameInput.value, password: passwordInput.value }

      console.log(json)

      try {
      let response = await fetch($

      {BASE_URL}

      /v1/auth/tokens, {
      method: "POST",
      headers:

      { "Content-Type": "application/json" }

      ,
      body: JSON.stringify(json)
      });

      if (response.ok) {
      let token = String(response.headers.get("X-Subject-Token"))
      console.log(token)
      response.headers.forEach(h=>

      { console.log(h) }

      )
      }
      let data = await response.json();
      console.log(data);
      } catch (err)

      { console.log(err) }

      }
      }

      I've verified that the X-Subject-Token header is present in the response using browser developer tools. However, when I try to access it using jqXHR.getResponseHeader('X-Subject-Token'), it returns only content type
      ,Content length and Cache control.
      I've also checked for CORS issues, but the server appears to be configured correctly to allow the custom header.
      keyrock:
      image: quay.io/fiware/idm:$

      {KEYROCK_VERSION}

      container_name: fiware-keyrock
      hostname: keyrock
      networks:
      default:
      ipv4_address: 172.18.1.5
      depends_on:

      • mysql-db
      • authzforce
        ports:
      • "$ {KEYROCK_PORT}:${KEYROCK_PORT}

        " # localhost:3005
        environment:

      • DEBUG=idm:*
      • IDM_DB_HOST=mysql-db
      • IDM_DB_PASS_FILE=/run/secrets/my_secret_data
      • IDM_DB_USER=root
      • IDM_HOST=http://localhost:$ {KEYROCK_PORT}
        - IDM_PORT=${KEYROCK_PORT}
      • IDM_HTTPS_PORT=$ {KEYROCK_HTTPS_PORT}
      • IDM_ADMIN_USER=alice
      • IDM_ADMIN_EMAIL=alice-the-admin@test.com
      • IDM_ADMIN_PASS=test
      • IDM_PDP_LEVEL=advanced
      • IDM_AUTHZFORCE_ENABLED=true
      • IDM_AUTHZFORCE_HOST=authzforce
      • IDM_AUTHZFORCE_PORT=$ {AUTHZFORCE_PORT}
      • IDM_CSP_FORM_ACTION=*
      • IDM_CORS_ENABLED=true
      • IDM_CORS_ORIGIN=*
      • IDM_CORS_METHODS=GET,HEAD,PUT,PATCH,POST,DELETE
      • IDM_CORS_ALLOWED_HEADERS=content-type,X-Auth-Token,Tenant-ID,Authorization,Fiware-Service,Fiware-ServicePath,NGSILD-Tenant,NGSILD-Path,X-Subject-Token
      • IDM_CORS_CREDENTIALS=true
      • IDM_CORS_PREFLIGHT=true
      • IDM_CORS_EXPOSED_HEADERS=content-type,X-Auth-Token,Tenant-ID,Authorization,Fiware-Service,Fiware-ServicePath,NGSILD-Tenant,NGSILD-Path,X-Subject-Token

      Can anyone help me understand why I'm unable to access the X-Subject-Token header in the AJAX response using jQuery? Any insights or suggestions would be greatly appreciated.

        Activity

        Hide
        newbacklogmanager Backlog Manager added a comment -

        2025-02-04 17:51|CREATED monitor | # answers= 0, accepted answer= False

        Show
        newbacklogmanager Backlog Manager added a comment - 2025-02-04 17:51|CREATED monitor | # answers= 0, accepted answer= False

          People

          • Assignee:
            Unassigned
            Reporter:
            newbacklogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: