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

auto CSRF function get confused by body #213

Closed
p-mathias opened this issue Sep 11, 2023 · 5 comments
Closed

auto CSRF function get confused by body #213

p-mathias opened this issue Sep 11, 2023 · 5 comments

Comments

@p-mathias
Copy link

p-mathias commented Sep 11, 2023

Last week we got to the state the auto csrf function is kicking in,
when csrf is needed by post request.

i notice that the post request doesn't get send since then,
while checking today what could be the issue,
i notice an error in the console:

 Retrieving JSON body from OData response failed: Unexpected token '<', "<?xml vers"... is not valid JSON

This error meesage sense and not sense in the same time,
the return of the get call (where csrf token is collected) a response from the server,
which is in xml.
But two things make this thing, i guess to an issue/bug:

  • it's doesn't define that the format should be in json in request header -> why expect that the response body is in json?
  • we don't care about the the response body since in the response header is the x-csrf-token maintained and this all we needed

Please had in mind this i an oDataV2 interface

place where the error hapen:
https://github.com/odata2ts/http-client/blob/ed6b01821c2dc161f05144e3b4d8f8d899f954ae/packages/fetch/src/FetchClient.ts#L98

@texttechne
Copy link
Contributor

Hi @p-mathias,
damn that's particular to the fetch client.... For now, as workaround: Append ?$format=json to the csrfTokenFetchUrl.

@p-mathias
Copy link
Author

fixed the issue,
should i close the issue?

@texttechne
Copy link
Contributor

No, please leave it open. I still need to fix the underlying issue.

@texttechne
Copy link
Contributor

Hi @p-mathias,

with the newest version of the fetch client you can remove the format parameter.
Tested and works.

@p-mathias
Copy link
Author

with the fixed version ?$format=json is not needed any more

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

2 participants