-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Passing Cookies to API endpoint #343
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
Comments
+1 |
You cannot add cookies to AJAX requests this way. Cookie and Set-Cookie are special headers which are handled by the web browser's XMLHttpRequest. Cookies can be sent, received, stored and deleted by XMLHttpRequest automatically; just like it happens with the "synchronous" requests - HTML pages, for example. You need a web browser with support for the XMLHttpRequest II and set |
This is very old, but this is how I made it work in my environment...... I had the same need so I just added this two lines in swagger.js before the if statement https://github.com/wordnik/swagger-ui/blob/master/dist/lib/swagger.js#L1208 I didn't know how to change de useJQuery boolean to true, so I just hard coded, yes it looks very awful. But It works obj.useJQuery = true;
obj.xhrFields = { withCredentials: true }; |
ok, we've recently merged swagger-api/swagger-js#102 which makes the useJQuery flag work fully. When constructing the Swagger UI, just pass the
|
+1 |
I don't understand how this helps with passing cookies to the endpoint? Can someone give me a code example of how to do this? Thanks. |
The referenced commit lets you use the $.ajax for whatever reasons. It does not turn on sending cookies in the XMLHttpRequest by default. And it should not be done - the server needs to confirm it and if it does not, which is the default behaviour, the entire AJAX call fails. It is a protection against XSRF attacks; only some REST APIs perform the authorization using cookies, usually only partially. See withCredentials & Access-Control-Allow-Credentials. You should still set
If the A solution without modifying Swagger would be registering an I think that the SwaggerUi should offer a flag for it, unless it allows you to access the |
Thanks for the detailed explanation. I appreciate it. :) |
No problem :-) Actually, if you want this fixed, you might consider reopening this issue. I don't think that the cookie authentication works in with the vanilla swagger-ui. (I don't need it anymore, because the REST API I've been working with stopped using the cookie authentication to prevent possible XSRF attacks.) |
Closing in favor of #461 |
Hi,
I want to add a Cookie header to each requests made to the API, I tried this without success:
Is there any other solution to add Cookie headers?
The text was updated successfully, but these errors were encountered: