Skip to content

DMS API calls with Logged in User Token #99

@abdulbasitg

Description

@abdulbasitg

Hello Team,

I'm using the plugin in my CAP application and it works perfect. However, I have a complex scenario where I'm having issues with the plugin.

Scenario

I have a CAP application with HANA DB + DMS services. I want to deploy this CAP application to two different subaccounts in different regions (EU10 and AP11) but use the HANA DB and DMS instances centrally to make sure that both applications point to the same DB and DMS repository.

On the main subaccount, application is deployed with standard configurations. On the second subaccount, I'm creating user-provided service instances for HDI Container and DMS by providing credentials from the service instances in the main subaccount.

My application is able to access HDI Container as expected but I'm having errors in sdm plugin during the DMS access.

I've debugged the application and found that it is failing in generating tokens to access DMS API's.

Problem 1:

getClientCredentialsToken method in lib/util/index.js

let subdomain = cds.context.user?.tokenInfo?.getPayload()?.ext_attr?.zdn;

In this part of the code, the subdomain is retrieved from the user token and forwarded to the:

requests.requestClientCredentialsToken(
  subdomain,
  credentials.uaa,
  null
...
...

Since the subdomain of token endpoint (credentials.uaa.url) and user token is different, this method is trying to replace the tokenurl with the provided subdomain which generates an incorrect endpoint and token generation fails.

Problem 2:

generateSDMBearerToken method in lib/util/index.js

In this part of the code, the access token is being created with password grant_type which uses JWT token retrieved from user context.

Since the user specific JWT is used here, and this token is generated in different subaccount than the original service instance, API call returns unauthorized as expected.

I've tried to fix these errors locally and deployed the modified version. I'm now able to access to the DMS and all operations works fine.

Question/Recommendation:

DMS API has two different access options as described in the following documentation:

https://help.sap.com/docs/document-management-service/sap-document-management-service/develop-using-client-credential-flow?locale=en-US

As desribed in Step 2 & 3, it is possible to access DMS API with technical user ID (client id/secret from service instance/key) and user JWT token. However, based on my understanding, this plugin relies on the user's JWT token.

Since the plugin is attached to the CAP application, and all authorizations can be handled in CAP, I would expect technical user token is used in the plugin instead of user token. It might also be possible make this setting configurable with sdm settings in package.json.

I'm planning to use this plugin in many different applications in our landscape but this issue is a main blocker for us. Should I expect a fix in this part in future releases or do you think this is a limitation of the plugin and want to keep it as is?

I’d be happy to submit a pull request with my fix as well.

Thanks
Abdulbasit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions