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

reenable cookies in request so login will work again #21

Merged
merged 2 commits into from
Aug 13, 2013

Conversation

kcivey
Copy link
Contributor

@kcivey kcivey commented Aug 13, 2013

Cookies are now off by default in the current version of the request module:
request/request#587

As a result, login no longer works. This reenables it.

Cookies are now off by default in the current version of the request module:
request/request#587

As a result, login no longer works. This reenables it.
@maxkueng
Copy link
Contributor

Yeah login seems to be broken ;( Just noticed.

@kcivey
Copy link
Contributor Author

kcivey commented Aug 13, 2013

There may be a better way to handle it, but this restores it to the way it was. I guess really each client should have its own cookie jar, but most of the time there is only one client anyway.

@kcivey
Copy link
Contributor Author

kcivey commented Aug 13, 2013

Actually this should be better, having a new cookie jar for each instance of the api.

macbre added a commit that referenced this pull request Aug 13, 2013
reenable cookies in request so login will work again
@macbre macbre merged commit 7c263ef into macbre:master Aug 13, 2013
@macbre
Copy link
Owner

macbre commented Aug 13, 2013

Thanks for the fix, @kcivey!

Was "broken" since request v2.23.0

@macbre
Copy link
Owner

macbre commented Aug 13, 2013

I've tagged v0.3.7 which includes this fix and pushed the latest version of nodemw to NPM

@kcivey kcivey deleted the request-cookies branch August 13, 2013 21:35
@maxkueng
Copy link
Contributor

Awesome!! Thanks :)

@shaikui
Copy link

shaikui commented Aug 29, 2017

'use strict';

const azureHelper = require('./azure.helper');
var request = require('request').defaults({jar: true});
var request = require('request');
const environment = azureHelper.setAzureEnvironment();

/**

  • @name Private functions
    */

/**

  • @method
  • @name getTransandCsrf
  • Get Trans and Csrf
    */
    function getTransandCsrf(){
    var resp = {};
    var roEnv = process.env.roEnv;
    var url = roEnv + "/Account/Login.aspx";
    var userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0";
    return new Promise( (resolve, reject) => {
    request({
    method: 'GET',
    url : url,
    headers: {
    'User-Agent': userAgent
    }
    },(error, response, body) =>{
    if(response.statusCode !== 200) reject(error);
    resp.cookies = (response.headers["set-cookie"]);
    resp = Object.assign(resp,azureHelper.csrfandTransId(body));
    console.log(Status code for 1: ${response.statusCode});
    resolve(resp);
    }) // request
    })
    };

/**

  • @method

  • @name requestSingInAndSingUp

  • Sign In and Sign Up functionality

  • @param { Object } obj - Passing Object

  • @param { Object } env - Passing Object

  • @param { String } email - Passing email

  • @param { String } password - Passing password
    */
    function requestSingInAndSingUp (obj,env,email,password){
    let transId = obj.transId;
    let csrfId = obj.csrfId;
    let app = env.getAppUrl();
    let tenant = env.getTenantId();
    let policy = env.getPolicy();
    let cookies = obj.cookies;
    let url2 = ("https://" + app + "/" + tenant + "/" + policy + "/SelfAsserted?tx=" + transId + "&p=" + policy);

    var jar = request.jar();
    var options = {
    'request_type': 'RESPONSE',
    'signInName': email ,
    'password': password,
    'g-recaptcha-response-toms': '03AEHxwuy8mq_8jbEWU--XHGea2dF-p7F-oUmZhAgpr1Xt7XyyrzBQpJZJilwhJZPG3D-K_HldpTEEl_2Xi51xm4ICCg6-w66XfR5nE1-Cj39ytH6QZiY2yJUTy-1CJZ6qNfJBsO7EG2Kba7cSGhQgetkhAxJOBtI-FJt5WlRdjP6UHgId11rSVhSCS2kphf1Z-BO62Fu2Jm6jWxnbTiVceEVXuQTOEibtQnQ-n2ckOLI-i0GI1tFBAVi6Lu6NZkQII7m_00ZyJtSoik-1LCNNQ8GXmOxFnnVTnvm-vr3mk_RmNaLS9CT6eGlo0CfpK3DiVTLEArQDTuxY'
    };

    var cheaders = {
    'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0',
    'Content-type' : 'application/x-www-form-urlencoded',
    'Accept' : 'application/json, text/javascript, **///; q=0.01',
    'X-Requested-With' : 'XMLHttpRequest',
    'X-CSRF-TOKEN' : csrfId,
    'Cookie' : cookies
    };

    return new Promise( (resolve, reject) => {
    request({
    url: url2,
    headers:cheaders,
    method: "POST",
    jar : jar,
    form : options
    }, function(error, response, body){
    if(response.statusCode !== 200) reject(error);
    console.log(Status code for 2: ${response.statusCode});
    resolve(body);
    });
    });
    };

/**

  • @method

  • @name confirmIdToken

  • Confirm Token id functionality

  • @param { Object } obj - Passing Object

  • @param { Object } env - Passing Object
    /
    function confirmIdToken (obj,env){
    let transId = obj.transId;
    let csrfId = obj.csrfId;
    let app = env.getAppUrl();
    let tenant = env.getTenantId();
    let policy = env.getPolicy();
    let cookies = obj.cookies;
    let url =("https://"+app+"/"+tenant+"/"+policy+"/api/CombinedSigninAndSignup/confirmed?csrf_token=" + csrfId + "&tx=" + transId + "&p=" + policy);
    var jar = request.jar();
    return new Promise( (resolve, reject) => {
    request({
    method: 'GET',
    url : url,
    jar : jar,
    headers: {
    'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
    'Accept' : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,
    /*;q=0.8",
    'Cookie' : cookies
    }
    },(error, response, body) =>{
    if(response.statusCode !== 200) reject(error);
    console.log(Status code for 3: ${response.statusCode});
    let token = azureHelper.cropIdToken(body)
    resolve(token);

     }) // request
    

    });
    }

/**

  • Creates a new Azure Public functions.
  • @Class
    */
    function azureModule (){}

/**

  • @function getAuthenticationToken
  • Get Authentication token
  • @param { Object } req - Passing request object
  • @param { function } callback - Callback method
    */
    azureModule.prototype.getAuthenticationToken = function(req,callback){
    var _cookieAndIds = {};
    getTransandCsrf()
    .then((data)=>{
    _cookieAndIds = data;
    return requestSingInAndSingUp(_cookieAndIds,environment,req.body.email,req.body.password);
    }).then((data)=>{
    return confirmIdToken(_cookieAndIds,environment);
    }).then((data)=>{
    callback(data)
    }).catch((err) =>{
    callback(err);
    });
    }

module.exports = new azureModule();

This global jar:true hitting very badly :(, Any help would be appreciated If I disable jar: true it is not carrying the cookies to other call so it is getting failed , If I enabled it is always considering as old client even for new instance hit

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

Successfully merging this pull request may close these issues.

None yet

4 participants