SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
161 stars 55 forks source link

Error: Could not fetch client credentials token for service of type connectivity: XsuaaService requires uaadomain inside credentials #4841

Closed gauravkr75 closed 1 month ago

gauravkr75 commented 1 month ago

Describe the bug We are using SAP Cloud SDK with CAP. When we are trying to call an on-premise service using cloud-sdk, we are getting the error: Error: Could not fetch client credentials token for service of type connectivity: XsuaaService requires uaadomain inside credentials. This issue started coming since we upgraded the cloud sdk from version 3.15.0 to 3.16.0

It seems the issue is caused because the connectivity service credentials does not contain uaadomain property and these credentials are being passed to the XsuaaService class of @sap/xssec npm package which looks for this property and then throws an error. Please check the Screenshots section to see this flow.

To Reproduce Steps to reproduce the behavior:

  1. Set up ...
  2. Execute ...
  3. Confirm ...
  4. See error

Expected behavior Receive the response without any errors

Screenshots This screenshot explains the process flow and where it fails.

image

Used Versions:

Code Examples

import { executeHttpRequest } from "@sap-cloud-sdk/http-client";
const response = await executeHttpRequest(
            { destinationName: "destination-name" },
            {
                method, url, data, headers
            }
        );

Log file If applicable, add your log file or related error message. Again, please remove your sensitive information.

Full Log:

[cds] - ErrorWithCause: Failed to load destination.
    at /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-accessor.ts:67:13
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolveDestination (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-accessor.ts:65:31)
    at async /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/http-client/src/http-client.ts:83:33
Caused by:
ErrorWithCause: Failed to add proxy authorization header - client credentials grant failed!
    at proxyAuthorizationHeader (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:123:11)
    ... 21 lines matching cause stack trace ...
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: ErrorWithCause: Failed to add proxy authorization header - client credentials grant failed!
      at proxyAuthorizationHeader (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:123:11)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async proxyHeaders (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:102:27)
      ... 5 lines matching cause stack trace ...
  Caused by:
  ErrorWithCause: Could not fetch client credentials token for service of type "connectivity".
      at serviceToken (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/token-accessor.ts:70:11)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async proxyAuthorizationHeader (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:120:19)
      at async proxyHeaders (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:102:27)
      at async addProxyConfigurationOnPrem (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:41:11)
      at async Function.getDestinationFromDestinationService (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-from-service.ts:158:30)
      at async getDestination (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-accessor.ts:98:6)
      at async resolveDestination (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-accessor.ts:65:31)
      at async /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/http-client/src/http-client.ts:83:33
  Caused by:
  Error: Could not fetch client credentials token for service of type connectivity: XsuaaService requires uaadomain inside credentials.
      at /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/xsuaa-service.ts:60:11
      at processTicksAndRejections (node:internal/process/task_queues:95:5) {
    cause: ErrorWithCause: Could not fetch client credentials token for service of type "connectivity".
        at serviceToken (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/token-accessor.ts:70:11)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async proxyAuthorizationHeader (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:120:19)
        at async proxyHeaders (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:102:27)
        at async addProxyConfigurationOnPrem (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/connectivity-service.ts:41:11)
        at async Function.getDestinationFromDestinationService (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-from-service.ts:158:30)
        at async getDestination (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-accessor.ts:98:6)
        at async resolveDestination (/Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/destination/destination-accessor.ts:65:31)
        at async /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/http-client/src/http-client.ts:83:33
    Caused by:
    Error: Could not fetch client credentials token for service of type connectivity: XsuaaService requires uaadomain inside credentials.
        at /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/xsuaa-service.ts:60:11
        at processTicksAndRejections (node:internal/process/task_queues:95:5) {
      cause: Error: Could not fetch client credentials token for service of type connectivity: XsuaaService requires uaadomain inside credentials.
          at /Users/<USER>/Documents/project/node_modules/@sap-cloud-sdk/connectivity/src/scp-cf/xsuaa-service.ts:60:11
          at processTicksAndRejections (node:internal/process/task_queues:95:5)
    }
  }

Impact / Priority For now we have downgraded the version to 3.15.0 so its working but it would be great if it can be fixed soon.

Affected development phase: e.g. Getting Started, Development, Release, Production

Impact: e.g. No Impact, Inconvenience, Impaired, Blocked

Timeline: e.g. Go-Live is in 12 weeks.

Additional context Add any other context about the problem here.

deekshas8 commented 1 month ago

Hi @gauravkr75 ,

Thanks you for raising this. We are aware of this issue in the xssec library and it is currently being worked on by the team. Please use 3.15.0 for now. @finkmanAtSap @jjtang1985

deekshas8 commented 1 month ago

Hi @gauravkr75 ,

We released a canary version with the fix. You can try it out by setting this in your package.json: "@sap-cloud-sdk/connectivity": "canary".

We will likely release a new minor version sometime next week.

gauravkr75 commented 1 month ago

Hi @deekshas8,

Thanks for looking into this issue. I tested with the canary version and it is working fine now.

deekshas8 commented 1 month ago

Hi @gauravkr75

We have now released a new minor version 3.17.0.