0

I am getting below error while trying to use sapjco3 in my Springboot application. I am deploying my application to SAP Cloud foundry environment packaging as war file with tomee7 TARGET_RUNTIME.

com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestFailedException: Failed to resolve access token.","\tat com.sap.cloud.sdk.cloudplatform.connectivity.OAuth2ServiceImpl.lambda$executeClientCredentialsFlow$1(OAuth2ServiceImpl.java:119)"

Error requesting technical user token vvith grant_type 'client_credentials': Error retrieving JWT token. Server URI https: xxxxxxxxxxxxxx
dev.authentication.eu20.hana.ondemand.com/oauth/token. Http status code 401. Response body '{"error":"unauthorized","error_description":"Bad credentials"}"',"\tat com.sap.cloud.security.xsuaa.tokenflows.ClientCredentialsTokenFIow.requestTechnicalUserToken(ClientCredentialsTokenFlow.java:188)","\tat com.sap.cloud.security.xsuaa.tokenflows.ClientCredentialsTokenFlow.execute(ClientCredentialsTokenFlow.java:141)","\tat ...

enter image description here

I am trying to call a BAPI using SAP Cloud SDK as specified in the below documents.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Athul Ram
  • 31
  • 2
  • I see that you could go forward, as you just [asked a new question](https://stackoverflow.com/questions/76260683/jco-error-communication-initialization-of-repository-destination-failed) further, so please maybe you could add a little feedback here for future visitors having the same issue? – Sandra Rossi May 16 '23 at 11:58

1 Answers1

0

Judging from the displayed error message, it seems like your application is not able to access the bound authentication service (most commonly an instance of the XSUAA service). This is not directly related to either JCo or BAPI but instead seems to indicate a configuration issue of your application.

You can validate whether the credentials in your Service Binding (found in VCAP_SERVICES environment variable of your deployed application) are actually valid by performing the authentication manually with a REST client of your choice. For that, use the URL you masked in your screenshot, select the authentication type OAuth2 - Client Credentials and provide the clientid and clientsecret from said Service Binding.

You should be able to reproduce the issue you are seeing (e.g. the 401) with that setup. In this case, I'd recommend re-binding the service in question so that a new clientid and clientsecret pair is getting generated.

  • I am getting below error while executing call.{ "error": "unauthorized", "error_description": "An Authentication object was not found in the SecurityContext" } – Athul Ram May 15 '23 at 19:10
  • 1
    I think you have to be a bit more precise: Where is this error coming from? Some local class or is it part of the XSUAA service response? Also: Did you check whether you are using all of your JCo and SAP Java Buildpack related dependencies with `provided` (as outlined in [our documentation](https://sap.github.io/cloud-sdk/docs/java/guides/manage-dependencies#avoiding-scope-conflicts)). – Johannes Schneider May 16 '23 at 06:22