-
Notifications
You must be signed in to change notification settings - Fork 4
/
auth.js
125 lines (106 loc) · 4.45 KB
/
auth.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict';
var login_url = 'https://sso.pokemon.com/sso/login?service=https%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize';
var login_oauth = 'https://sso.pokemon.com/sso/oauth2.0/accessToken';
// Google Parts
var android_id = '9774d56d682e549c';
var oauth_service = 'audience:server:client_id:848232511240-7so421jotr2609rmqakceuu1luuq0ptb.apps.googleusercontent.com';
var app = 'com.nianticlabs.pokemongo';
var client_sig = '321187995bc7cdc2b5fc91b11a96e2baa8602c62';
module.exports = {
PokemonClub: function (user, pass, self) {
return new Promise(function(resolve, reject) {
var options = {
url: login_url,
headers: {
'User-Agent': 'niantic'
}
};
self.request.get(options, function (err, response, body) {
var data;
if (err) {
return reject(err);
}
try {
data = JSON.parse(body);
} catch(e) {
return reject(e);
}
options = {
url: login_url,
form: {
'lt': data.lt,
'execution': data.execution,
'_eventId': 'submit',
'username': user,
'password': pass
},
headers: {
'User-Agent': 'niantic'
}
};
self.request.post(options, function (err, response, body) {
//Parse body if any exists, callback with errors if any.
if(err) {
return reject(err);
}
if (body) {
var parsedBody = JSON.parse(body);
if (parsedBody.errors && parsedBody.errors.length !== 0) {
return reject('Error logging in: ' + parsedBody.errors[0]);
}
}
var ticket = response.headers['location'].split('ticket=')[1];
options = {
url: login_oauth,
form: {
'client_id': 'mobile-app_pokemon-go',
'redirect_uri': 'https://www.nianticlabs.com/pokemongo/error',
'client_secret': 'w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR',
'grant_type': 'refresh_token',
'code': ticket
},
headers: {
'User-Agent': 'niantic'
}
};
self.request.post(options, function (err, response, body) {
var token;
if(err) {
return reject(err);
}
// console.log(body);
try {
token = body.split('token=')[1];
token = token.split('&')[0];
} catch(e) {
return reject('[x] Either the PTC servers are down OR your login information is wrong');
}
var expiry = body.split('token=')[1].split('&expires=')[1];
if (!token) {
return reject('Login failed');
}
self.DebugPrint('[i] Session token: ' + token);
return resolve([token, expiry]);
});
});
});
});
},
GoogleAccount: function (user, pass, self) {
return new Promise(function(resolve, reject) {
self.google.login(user, pass, android_id, function (err, data) {
if (data) {
self.google.oauth(user, data.masterToken, data.androidId, oauth_service, app, client_sig, function (err, data) {
if (err) {
return reject(err);
}
return resolve([data.Auth, data.Expiry]);
});
}
else {
return reject(err);
}
});
});
}
};