SamDecrock / node-http-ntlm

Node.js module to authenticate using HTTP NTLM
MIT License
192 stars 89 forks source link

Maintain session with a series of related requests? #12

Closed rdooh closed 9 years ago

rdooh commented 10 years ago

Hi Sam,

This is not really a bug - but I need to perform a series of authenticated requests within a session. Currently, been able to perform a series of independent requests, no problem. But each is treated as a completely new session.

How would I perform a single-session series of requests? Would I follow the Advanced example, injecting additional steps in the waterfall? If so, how am I dealing with the Type2 and Type3 messages - do these need to be redone each time? I'm hoping that this is all possible, and that you could provide a simple illustration.

Thanks, Rob

SamDecrock commented 9 years ago

With the recent pull request, you can now add custom headers. That means you can pass along cookies from request to the other.

Like this:

// 1st request:
httpntlm.get({
    url: "https://someurl.com",
    username: 'm$',
    password: 'stinks',
    workstation: 'choose.something',
    domain: ''
}, function (err1, res1){
    if(err1) return err1;

    console.log(res1.body);
    console.log(res1.cookies);

    // 2nd request, passing cookies
    httpntlm.get({
        url: "https://someurl.com",
        username: 'm$',
        password: 'stinks',
        workstation: 'choose.something',
        domain: '',
        headers: {
           Cookie: res1.cookies.join("; ")
        }
    }, function (err2, res2){
        if(err2) return err2;

        console.log(res2.body);
        console.log(res2.cookies);
    });
});