-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
99 lines (86 loc) · 3.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var Browser = require("zombie");
var express = require('express');
var bodyParser = require("body-parser");
var querystring = require("querystring");
var request = require('request');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
var router = express.Router();
app.get('/', function(req, res) {
res.json({ "urm...": "you're in the wrong part of the right place." });
});
app.post('/api/v1/halo4', function(req, res) {
if (req.body == undefined) {
res.json({ result: null, error: { error_description: "no_account_information" } });
return;
}
var microsoftAccount = null;
var microsoftAccountPassword = null;
if (req.body["MicrosoftAccount"] != undefined)
microsoftAccount = req.body["MicrosoftAccount"];
if (req.body["MicrosoftAccountPassword"] != undefined)
microsoftAccountPassword = req.body["MicrosoftAccountPassword"];
if (microsoftAccount == null || microsoftAccountPassword == null) {
res.json({ Result: null, Error: { Description: "no_account_information" } });
return;
}
var browser = new Browser();
Browser.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36";
browser.visit("https://app.halowaypoint.com/oauth/spartanToken", function() {
browser.
fill("input[type=email]", microsoftAccount).
fill("input[type=password]", microsoftAccountPassword).
pressButton("Sign in", function() {
if (browser.text('body').indexOf('SpartanToken') != -1) {
var data = browser.text('body');
res.json({ Result: JSON.parse(data), Error: null });
browser.close();
} else {
res.json({ Result: null, Error: { Description: "unable_to_authentication_with_halo_waypoint", details: browser.text('body') } });
browser.close();
return;
}
});
});
});
app.post('/api/v1/xboxlive', function(req, res) {
if (req.body == undefined) {
res.json({ result: null, error: { error_description: "no_account_information" } });
return;
}
var microsoftAccount = null;
var microsoftAccountPassword = null;
if (req.body["MicrosoftAccount"] != undefined)
microsoftAccount = req.body["MicrosoftAccount"];
if (req.body["MicrosoftAccountPassword"] != undefined)
microsoftAccountPassword = req.body["MicrosoftAccountPassword"];
if (microsoftAccount == null || microsoftAccountPassword == null) {
res.json({ Result: null, Error: { Description: "no_account_information" } });
return;
}
var browser = new Browser();
Browser.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36";
browser.visit("https://login.live.com/oauth20_authorize.srf?client_id=0000000048093EE3&redirect_uri=https://login.live.com/oauth20_desktop.srf&response_type=token&display=touch&scope=service::user.auth.xboxlive.com::MBI_SSL", function() {
browser
.fill("input[type=email]", microsoftAccount)
.pressButton('Next', function() {
browser
.fill("input[type=password]", microsoftAccountPassword)
.pressButton("Sign in", function() {
var index = browser.url.indexOf('access_token');
if (index != -1) {
var data = browser.url.substring(index);
res.json({ Result: querystring.parse(data), Error: null });
browser.close();
} else {
res.json({ Result: null, Error: { Description: "unable_to_authentication_with_xbox_live" } });
return;
}
});
});
});
});
app.listen(process.env.PORT || 3001);