Skip to Content
0
Aug 03 at 02:36 PM

SAP Cloud SDK Javascript, Client Credential Flow

497 Views

Dear community,

I would like to programmatically access the api of the xsuaa and do some automatic configuration bejond the xs-security.json.

Therefore I thought using the Cloud SDK Javascript seems like a good idea.

Currently I am stuck, because the framework is not requesting an auth token.

This is what i am doing:

import { RoleCollectionsApi } from "./clients/AuthorizationAPI";
const xsenv = require('@sap/xsenv');

// load credentials
xsenv.loadEnv();
var service = xsenv.filterServices({ name: 'test-xsuaa-apiaccess' });

(async () => {
    const credentials = service[0].credentials;
    const destination: any = {};
    destination.authentication = "OAuth2ClientCredentials";
    destination.tokenServiceUrl = credentials.url + "/oauth/token";
    destination.clientId = credentials.clientid;
    destination.clientSecret = credentials.clientsecret;
    destination.url = credentials.apiurl
    const responseData = await RoleCollectionsApi.getRoleCollections().execute(destination);
})();
And it will result in:
Error: `AuthenticationType` is "OAuth2ClientCredentials", but no auth tokens could be fetched from the destination service.
I would like to emphasize that I want a technical access to the xsuaa api, i do not need the router.What am i missing?BR,Tobi