Skip to content

Commit

Permalink
Added X-Apple-Widget-Key header and removed Cheerio
Browse files Browse the repository at this point in the history
  • Loading branch information
stoprocent committed Nov 16, 2015
1 parent fe4a9de commit e1ba946
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
40 changes: 5 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

var async = require('async'),
request = require('request'),
cheerio = require('cheerio'),
moment = require('moment'),
fs = require('fs'),
path = require('path'),
Expand Down Expand Up @@ -114,6 +113,7 @@ function Connect(username, password, options) {
baseURL : "https://itunesconnect.apple.com",
apiURL : "https://reportingitc2.apple.com/api/",
loginURL : "https://idmsa.apple.com/appleauth/auth/signin",
appleWidgetKey : "22d448248055bab0dc197c6271d738c3",
concurrentRequests : 2,
errorCallback : function(e) {},
loginCallback : function(c) {}
Expand Down Expand Up @@ -275,20 +275,21 @@ Connect.prototype.login = function(username, password) {
//Request apple login page from which we need a "my account info" cookie
request.post({
url : this.options.loginURL,
headers : { 'Content-Type': 'application/json' },
headers : { 'Content-Type': 'application/json', 'X-Apple-Widget-Key': this.options.appleWidgetKey },
json : {
"accountName" : username,
"password" : password,
"rememberMe" : false
}
}, function(error, response, body) {
var cookies = response ? response.headers['set-cookie'] : null;

if (error || !(cookies && cookies.length)) {
error = error || new Error('There was a problem with loading the login page cookies. Check login credentials.');
} else {
//extract the account info cookie
var myAccount = /myacinfo=.+?;/.exec(cookies);

if (myAccount == null || myAccount.length == 0) {
error = error || new Error('No account cookie :( Apple probably changed the login process');
} else {
Expand All @@ -303,6 +304,7 @@ Connect.prototype.login = function(username, password) {
},
}, function(error, response, body) {
cookies = response ? response.headers['set-cookie'] : null;

if (error || !(cookies && cookies.length)) {
error = error || new Error('There was a problem with loading the login page cookies.');
} else {
Expand All @@ -323,38 +325,6 @@ Connect.prototype.login = function(username, password) {
}
}
})
// Request ITC to get fresh post action
request.get(this.options.baseURL, function(error, response, body) {
// Handle Errors

// Search for action attribute
var html = cheerio.load(body);
var action = html('form').attr('action');

// Login to ITC
request.post({
url : self.options.baseURL + action,
form: {
'theAccountName' : username,
'theAccountPW' : password,
'theAuxValue' : ""
}
}, function(error, response, body) {
var cookies = response ? response.headers['set-cookie'] : null;
// Handle Errors
if(error || !(cookies && cookies.length)) {
error = error || new Error('There was a problem with recieving cookies. Please check your username and password.');
self.options.errorCallback( error );
}
else {
// Set _cookies and run callback
self._cookies = cookies;
self.options.loginCallback(cookies);
// Start requests queue
self._queue.resume();
}
});
});
}

/**
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"underscore": "~1.6.0",
"moment": "~2.8.1",
"request": "~2.39.0",
"cheerio": "~0.17.0",
"async": "~0.9.0"
},
"devDependencies": {
Expand Down

0 comments on commit e1ba946

Please sign in to comment.