I am trying to connect app(react.js) with SAP CPI I am facing a CORS (Cross-Origin Resource Sharing) issue while making a request from my frontend application to the server at https://oauthasservices-xxxxxxx.ap1.hana.ondemand.com/oauth2/api/v1/token?grant_type=client_credentials. The error message states that the request header field Authorization is not allowed by Access-Control-Allow-Headers in the preflight response.

To Bypass this issue i used Moseif CORS google extension as well as deployed app on netlify, still not working. This api works when i call it from Postman,
can i make some changes in my frontend code to bypass this issue, or this issue could only be solved from SAP CPI API Management. Because SAP Backend team saying they can't configure this api to allow cross origin headers: "*"

Here is my api call code snippet

const axios = require('axios');

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://oauthasservices-xxxxxxxxxx.ap1.hana.ondemand.com/oauth2/api/v1/token?grant_type=client_credentials',
  headers: { 
    'Authorization': 'Basic ZThlNDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
    
  }
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Also tried using proxy urls and proxy express server, still not working.

0

There are 0 best solutions below