ericblade/synergv-lib

code not working in node.js

Closed this issue · 4 comments

It seems that the ServiceLogin request requires cookies to work, and the current implementation of node-xmlhttprequest doesn't support cookies. That seems pretty easy to get in, in fact, there's a xmlhttprequest-cookie module that seems to add support .. however, the request still doesn't work, and just hangs for a long time, then times out.

I can't seem to find a particularly good existing online test for cookie functionality that doesn't also require executing javascript code arbitrarily from their site, so may need to setup a PHP page to test xmlhttprequest-cookie to see if it's even working properly, at the server side.

It may be possible that we need the cookies from the previous requests .. not just the ones that come from ServiceLogin ..

The login process currently looks like:

GET https://accounts.google.com/ServiceLoginAuth
POST https://accounts.google.com/signin/challenge/sl/password

This works in browser, but in node, we seem to be getting a response that cookies are required, and a timeout from the node code that is looking at it. (that's also a weird part -- we get a response, but we don't get it back from node until after timeout)

Might be possible that we may need to retool the entire postRequest using node request library instead of a XMLHttpRequest library, and then get a compatible 'request' library for browser .. or just write a completely separate postRequest for node use... sigh.

... or maybe if lucky, fix xmlhttprequest-cookie to use the specific repo for node-xmlhttprequest with document support, instead of the master repo, and see what happens if we use that same library for both calls.

Alternatively, if that is a thing that could work, we could fork xmlhttprequest library, pull the changes for document, and add the changes for cookies ourselves..

OK, so, I've tracked much of this down:

xmlhttprequest-cookie needs to respond only with the cookie values, not with the parameters as well

(approximately line 70ish in send_cookie in xmlhttprequest-cookie:

    // The original code just dropped the entire cookie string! That isn't right!!!
    // https://www.nczonline.net/blog/2009/05/05/http-cookies-explained/
    var s = cookies[i].value;
    s = s.substring(0, s.indexOf(';'));
    cookie += cookies[i].name + "=" + s;

)

node-xmlhttprequest needs to send the data when redirecting, as right now it just hangs without any data.

( approximately line 433 in node-xmlhttprequest XMLHttpRequest.js

      console.warn("**** redirecting!!", url);
      request = doRequest(newOptions, responseHandler).on("error", errorHandler);
      if (data) {
        console.warn("**** writing data to redirect", data);
        request.write(data);
      }

      request.end();

)

.... this still doesn't actually solve the problem, though, as the server is still redirecting my test code into the wrong location (going to the account chooser, despite having provided credentials)

BUT it's at least responding with a document, and it's a document that doesn't say "TURN ON COOKIES".

First part not valid, it shouldn't send the data with the redirect. there's something else that needs to be done, though (and sending an empty data doesn't work) because otherwise the request just hangs.

mostly fixed. need to re-test everything in browser still, though.