Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small adjustment to support $batch requests #168

Open
mikezaschka opened this issue Mar 20, 2022 · 0 comments
Open

Small adjustment to support $batch requests #168

mikezaschka opened this issue Mar 20, 2022 · 0 comments

Comments

@mikezaschka
Copy link

mikezaschka commented Mar 20, 2022

Hi @gregorwolf,

thank you for this example project. Helped me a lot to get things up and running with a CAP project and AzureAD integration (also using the PostgreSQL adapter and no deployment to BTP).
I did not want to miss all the OData V4 magic in CAP, so I found a way to get around the issue, that the SAPUI5 ODataModel (V2 and V4) append the Authorization header to all requests, including the ones collected within a $batch request.

So instead of deactivating batch like you did here

it is possible to hook into all jQuery ajax calls and remove the Authorization header from the $batch request body.
Just place this somewhere in the app initialization code (e.g. Component->init):

jQuery.ajaxSetup({
  beforeSend: function (xhr, settings) {
    if (settings.url && settings.url.indexOf("$batch") > -1) {
      settings.data = settings.data.replace(/Authorization:Bearer .*.+([\r\n]+|\.|[\r\n])/g, "");
    }
  }
});

This way all backend requests (I am only using V4) work perfectly fine and the bearer token is only available in the request header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant