This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGoogleSession.php
132 lines (115 loc) · 3.42 KB
/
GoogleSession.php
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
126
127
128
129
130
131
132
<?php
namespace POGOAPI\Session;
use Exception;
use Monolog\Logger;
use GuzzleHttp\Client;
use POGOAPI\Map\Location;
class GoogleSession extends Session {
protected $authClient;
protected $username;
protected $password;
protected $androidId;
protected $service;
protected $app;
protected $clientSig;
protected $token;
/**
* @param Logger $logger
* @param Location $location
* @param $username
* @param $password
* @param string $androidId
* @param string $service
* @param string $app
* @param string $clientSig
*/
public function __construct(Logger $logger, Location $location, $username, $password, $androidId = "3764d56d68ae549c", $service = "audience:server:client_id:848232511240-7so421jotr2609rmqakceuu1luuq0ptb.apps.googleusercontent.com", $app = "com.nianticlabs.pokemongo", $clientSig = "321187995bc7cdc2b5fc91b11a96e2baa8602c62") {
parent::__construct($logger, $location);
$this->username = $username;
$this->password = $password;
$this->androidId = $androidId;
$this->service = $service;
$this->app = $app;
$this->clientSig = $clientSig;
$this->authClient = new Client([
"base_uri" => "https://android.clients.google.com",
"headers" => ["User-Agent" => "POGOAPI/1.0"]
]);
}
/**
* @throws Exception
*/
public function authenticate() {
// Master login
$loginRes = $this->authClient->post("auth", ["form_params" => [
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => $this->username,
"has_permission" => 1,
"add_account" => 1,
"Passwd" => $this->password,
"service" => "ac2dm",
"source" => "android",
"androidId" => $this->androidId,
"device_country" => "us",
"operatorCountry" => "us",
"lang" => "en",
"sdk_version" => 17
]]);
$this->logger->debug("Google authentication");
$masterLogin = parse_ini_string($loginRes->getBody());
if (!isset($masterLogin['Token'])) {
throw new Exception("Failed master login");
}
$this->logger->debug("Google auth: master login");
// OAuth
$oauthRes = $this->authClient->post("auth", ["form_params" => [
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => $this->username,
"has_permission" => 1,
"EncryptedPasswd" => $masterLogin['Token'],
"service" => $this->service,
"source" => "android",
"androidId" => $this->androidId,
"app" => $this->app,
"client_sig" => $this->clientSig,
"device_country" => "us",
"operatorCountry" => "us",
"lang" => "en",
"sdk_version" => 17
]]);
$auth = parse_ini_string($oauthRes->getBody());
if (!isset($auth['Auth'])) {
throw new Exception("Failed auth");
}
$this->token = $auth['Auth'];
$this->logger->debug("Google auth: obtained token");
}
/**
* @return bool
*/
public function hasToken() {
return !is_null($this->token);
}
/**
* @return string
* @throws Exception
*/
public function getToken() {
if (!$this->hasToken()) {
throw new Exception("No token set");
}
return $this->token;
}
/**
* @param string $token
*/
public function setToken($token) {
$this->token = $token;
}
/**
* @return AccountType
*/
public function getType() {
return AccountType::GOOGLE();
}
}