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

Support for CORS with credentials #251

Closed
ghost opened this issue Feb 20, 2015 · 10 comments
Closed

Support for CORS with credentials #251

ghost opened this issue Feb 20, 2015 · 10 comments

Comments

@ghost
Copy link

ghost commented Feb 20, 2015

When Swagger API is authenticated through cookie, Swagger GUI running on different host cannot access it because it doesn't pass on cookie. Swagger JS should be setting flag withCredentials to true to enable browser to pass on cookie to the Swagger API.

Example of enabling this for jQuery:
$.ajax({ url: a_cross_domain_url, xhrFields: { withCredentials: true } });

References:

@fehguy fehguy modified the milestone: v2.1 Mar 7, 2015
@fehguy
Copy link
Contributor

fehguy commented May 7, 2015

While this is easily added, it will cause other issues under some circumstances. @q7a I do not think we can determine automatically whether or not to pass withCredentials without developer hints. How do you envision telling the js client that withCredentials should be set? An initialization option?

@fehguy fehguy self-assigned this May 8, 2015
@bytesandwich
Copy link

I've been getting around this with

var WithCredentials = function() { };
WithCredentials.prototype.apply = function(obj) {
  obj.xhrFields = {
      withCredentials: true
   };
  return true;
};
...
swagger.clientAuthorizations.add("withCredentials", new WithCredentials());

along with new SwaggerClient({ useJQuery: true ...

perhaps letting useJQuery take a function that takes the jquery object, to set ajaxtransport or ajaxprefiter would solve this and give some room for other similar use cases. E.g.

new SwaggerClient({ useJQuery: function($) {
  $.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
    options.crossDomain ={
      crossDomain: true
    };
    options.xhrFields = {
      withCredentials: true
    };
  });
}

@webron webron modified the milestones: v2.1, v2.1.1 Jun 8, 2015
@webron webron modified the milestones: v2.1.1, v2.1.2 Jun 24, 2015
@webron webron modified the milestones: v2.1.2, v2.1.3 Jul 31, 2015
@webron webron modified the milestones: v2.1.3, v2.1.4 Sep 2, 2015
@fehguy fehguy modified the milestone: v2.1.4 Nov 5, 2015
@fehguy
Copy link
Contributor

fehguy commented Dec 10, 2015

Since you can supply your own HTTP transports now (see https://github.com/swagger-api/swagger-js/blob/master/test/client.js#L308-L325), you can easily support this, and without hacking the swagger-js code.

@fehguy fehguy closed this as completed Dec 10, 2015
@blop
Copy link

blop commented Mar 3, 2016

Solution provided by jackphel does not seem to work for me.
What's the official way to do that?

@fehguy
Copy link
Contributor

fehguy commented Mar 3, 2016

@blop more details?

@jhilary
Copy link

jhilary commented May 11, 2017

Now you can enable withCredentials by passing enableCookies=true to SwaggerClient.
#891
new Swagger({ url: a_cross_domain_url, enableCookies: true });

@LiorArbel
Copy link

Is there a way currently (v3) to enable cookies/credentials? I really really need this

@DonMartin76
Copy link

I would also like to see this, at least as an option. This would take away the need for some really nasty workarounds I have in our API Management system.

@shockey
Copy link
Contributor

shockey commented Aug 11, 2018

@LiorArbel @DonMartin76, take a look at #1189 - it may cover your use case 😄

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

No branches or pull requests

9 participants