cloud-sdk-java icon indicating copy to clipboard operation
cloud-sdk-java copied to clipboard

TokenRequestFailedException when trying to access destinations with OAuth2ClientCredentials type Authentication

Open anupriyaSap opened this issue 1 year ago • 5 comments

Issue Description

We are trying to connect to say a microserviceB from microserviceA. The destination is configured with OAuth2ClientCredentials authentication. We have a certificate which we have added in the destination and a clientId. We have url to call B and a token service url.

Expectation is that the microserviceA sdk library will make a connection to the destination with DestinationAccessor.getDestination(name) and internally generate the token with the tokenUrl and call the url to microserviceB.

But when the code - DestinationAccessor.getDestination(name); is called, I get the following exception.

com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.resilience.ResilienceRuntimeException: com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestFailedException: Failed to resolve access token.

I can generate a token via client and call the microserviceB via a client.

Impact / Priority

Its a P1 - top priority for us as our code freeze for go live is on 22 August.

Affected development phase: Development closure soon

Impact: Blocked

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

Error Message

com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.resilience.ResilienceRuntimeException: com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestFailedException: Failed to resolve access token.
  • SDK Version: 5.0.0
com.sap.cloud.sdk.cloudplatform
  • Link to GitHub repo:
  • Project type, for example:
    • [ ] CAP Project
  • Platform: both below
    • [ ] Cloud Foundry
    • [ ] Deploy with Confidence (Cloud Foundry)

Checklist

  • [ ] Checked out the documentation and Stack Overflow
  • [ ] Description provided with all relevant information
  • [ ] Exception and stack trace provided
  • [ ] Attached debug logs
  • [ ] Attached dependency tree
  • [ ] Provided Cloud SDK version & link to relevant source code

anupriyaSap avatar Aug 16 '24 17:08 anupriyaSap

Please provide the information as described in the issue template: full stack trace, logs etc.

Also, please upgrade to the latest version 5.11.0

MatKuhr avatar Aug 18 '24 15:08 MatKuhr

Added the logs StackTrace.txt

anupriyaSap avatar Aug 19 '24 06:08 anupriyaSap

Updated version to - 5.11.0

However, I get the following error on making a call to DestinationAccessor.getDestination(name);

com.sap.scl.tcl.client.GCLClient : Entering GlobalContentLibrary- getPublishedTemplateDto method 2024-08-19T09:00:25.642+0000 [APP/PROC/WEB/0] STDOUT 2024-08-19T09:00:25.642Z INFO 8 --- [nio-8080-exec-1] com.sap.scl.tcl.client.GCLClient : Entering performGetRequestForGCLWithCerts 2024-08-19T09:00:25.642+0000 [APP/PROC/WEB/0] STDOUT 2024-08-19T09:00:25.642Z INFO 8 --- [nio-8080-exec-1] com.sap.scl.tcl.client.GCLClient : Entering getDestination to get Destinations-gcl 2024-08-19T09:00:25.760+0000 [APP/PROC/WEB/0] STDOUT 2024-08-19T09:00:25.760Z INFO 8 --- [nio-8080-exec-1] com.sap.scl.tcl.client.GCLClient : Exception while getPublishedTemplateDto --Failed to determine com.sap.cloud.sdk.cloudplatform.resilience.ResilienceDecorationStrategy. 2024-08-19T09:00:25.760+0000 [APP/PROC/WEB/0] STDOUT 2024-08-19T09:00:25.760Z INFO 8 --- [nio-8080-exec-1] com.sap.scl.tcl.client.GCLClient : Exiting performGetRequestForGCL for method getPublishedTemplateDto

anupriyaSap avatar Aug 19 '24 09:08 anupriyaSap

updating my destination configuration.

removed the image.

anupriyaSap avatar Aug 19 '24 10:08 anupriyaSap

Hi @anupriyaSap,

Could you please attach full stack trace and DEBUG logs from your application? We need DEBUG logs enabled for packages com.sap.cloud.sdk and org.apache.http.wire. Refer here for more details.

Please remove any sensitive information from the wire logs before sharing them.

Regards, Kavitha

KavithaSiva avatar Aug 19 '24 13:08 KavithaSiva

Hi @anupriyaSap,

From the stack trace shared over email, I see the following root cause:

STDERR Caused by: java.lang.NoClassDefFoundError: javax/cache/configuration/Configuration

Please check your project's dependency tree and see if an older version of javax.cache:cache-api gets included. Inside the SDK, we use javax.cache:cache-api:1.1.1. You could also use our BOM in your dependency management section to minimise dependency conflicts.

Also, since you mentioned you updated to version 5 recently and use DwC, please also check if you did all the steps listed here during migration.

Regards, Kavitha

KavithaSiva avatar Aug 20 '24 12:08 KavithaSiva

Closing, assuming the issue is resolved

MatKuhr avatar Sep 03 '24 09:09 MatKuhr