Skip to main content
15-Moonstone
April 12, 2021
Solved

SAP OData authentication with token

  • April 12, 2021
  • 1 reply
  • 6184 views

Hi,

 

is it possible to use the integration runtime SAP oData connector to authenticate via a token?

 

The process will be as followed:

1. Request with username/password to endpoint "GetToken"

2. Response is body with json values where I get my access token

3. Use the access token to authenticate to SAP

 

There is something for CSRF token requests. But I am not sure if this is the same thing. Right now my settings are this:

Authentication type: Fixed

Auth. Server ID: -empty-

Rel. URL for CSRF Get Request: /v1/auth/.../token

CSRF Token Name: acc_token

HTTP Connector Connection Settings:

Username & Password for token endpoint

Base URL, rel. URL as needed for SAP...

 

It worked for my endpoint where no authentication is required. But for this one I've only get a 401 - Unauthorized.

Best answer by Chrischhan

Hello,

 

if I understand you correctly you want to fetch a current token and use it (as ApiKey?) to authenticate yourself to SAP.

If so you can override the service "GetCustomHeaderParameters" on your thing and handle the logic in it and return a matching infotable containing the apikey as result:

 

// TODO: fetch Key/Token
// e.g. const tokenResponse = Resources["ContentLoaderFunctions"].GetJSON(params);
var result = { dataShape: { fieldDefinitions: {} }, rows: [] };

result.dataShape.fieldDefinitions["header"] = {
 name: "apikey",
 baseType: "STRING"
};
result.rows = [{ "apikey": tokenResponse.token }];

 

 

1 reply

13-Aquamarine
April 14, 2021

Hello,

 

if I understand you correctly you want to fetch a current token and use it (as ApiKey?) to authenticate yourself to SAP.

If so you can override the service "GetCustomHeaderParameters" on your thing and handle the logic in it and return a matching infotable containing the apikey as result:

 

// TODO: fetch Key/Token
// e.g. const tokenResponse = Resources["ContentLoaderFunctions"].GetJSON(params);
var result = { dataShape: { fieldDefinitions: {} }, rows: [] };

result.dataShape.fieldDefinitions["header"] = {
 name: "apikey",
 baseType: "STRING"
};
result.rows = [{ "apikey": tokenResponse.token }];