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

Add option to set withCredentials = false for ajax requests #2513

Closed
nolanlawson opened this issue Jul 22, 2014 · 6 comments
Closed

Add option to set withCredentials = false for ajax requests #2513

nolanlawson opened this issue Jul 22, 2014 · 6 comments
Labels
enhancement Feature request

Comments

@nolanlawson
Copy link
Member

In ajax-browser.js we're setting withCredentials to be true every time. We need some way to programmatically set this, although TBH I have no idea how.

Without this feature, we won't be able to set up the npm-browser to replicate from skimdb.npmjs.com, since credentials will be set to false on that server.

@nolanlawson nolanlawson changed the title Cannot use CouchDB with cors/credentials == false Cannot use CouchDB with cors credentials == false Jul 22, 2014
@nolanlawson
Copy link
Member Author

So I guess this would take the form of an ajax option, something like {credentials: true} or {credentials: false}. My feeling is that the default should be true, because otherwise we are going to break a lot of running code out there, since we have been recommending since day 1 that people set credentials=true on the remote CouchDB.

@calvinmetcalf
Copy link
Member

the object returned by getHost will have auth set to either a string or false, we can check that

@daleharvey daleharvey added the enhancement Feature request label Aug 4, 2015
@xMartin
Copy link

xMartin commented Oct 13, 2015

This is not limited to CouchDB configuration. For instance I have a setup with some auth proxy. How about renaming the issue to something like 'make withCredentials configurable' or something like that.

@anaran
Copy link
Contributor

anaran commented Oct 13, 2015

I arrived at this solution to make auth work for all my use cases (Firefox OS app, Desktop packaged app, served as hosted app via python -m SimpleHTTPServer

Using a customized xhr field I was able to debug this.

I leave the if statement in for historical background:

    var myXHR = function () {
      var request;
      if (false && /* false && */window.location.protocol == "app:") {
        request = new XMLHttpRequest({ mozSystem: true, mozAnon: true });
      }
      else {
        request = new XMLHttpRequest({ mozSystem: false, mozAnon: false });
      }
      return request;
    }
    var opts = {
      ajax: {
        xhr: myXHR,
        timeout: 30000
      }
    };
    var remoteOptionsDB = new PouchDB(destination + optionsDB._db_name, opts);
    var remoteDB = new PouchDB(destination + db._db_name, opts);

@daleharvey daleharvey changed the title Cannot use CouchDB with cors credentials == false Add option to set withCredentials = false for ajax requests Oct 13, 2015
@nolanlawson
Copy link
Member Author

woot, efe5dd8

@xMartin
Copy link

xMartin commented Oct 18, 2015

Nice, thanks!

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

No branches or pull requests

5 participants