Skip to content
This repository was archived by the owner on Dec 16, 2020. It is now read-only.

Commit fc02c6b

Browse files
committed
update to 9.14.2.0
1 parent b6e1bc4 commit fc02c6b

2 files changed

Lines changed: 96 additions & 57 deletions

File tree

src/snapchat.php

Lines changed: 94 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,42 @@ public function getAuthToken()
276276
return $return;
277277
}
278278

279+
public function getClientAuthToken($username, $password, $timestamp)
280+
{
281+
$data = array(
282+
"username" => $username,
283+
"password" => $password,
284+
"timestamp" => $timestamp
285+
);
286+
287+
$ch = curl_init();
288+
curl_setopt($ch, CURLOPT_URL, "http://client-auth.casper.io/");
289+
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
290+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
291+
curl_setopt($ch, CURLOPT_HEADER, FALSE);
292+
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
293+
curl_setopt($ch, CURLOPT_POST, TRUE);
294+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
295+
$return = curl_exec($ch);
296+
297+
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200)
298+
{
299+
$return["error"] = 1;
300+
$return["data"] = "HTTP Status Code != 200";
301+
302+
return $return;
303+
}
304+
curl_close($ch);
305+
$return = json_decode($return, true);
306+
if(!$return || $return["status"] != 200 || !isset($return["signature"]))
307+
{
308+
$return["error"] = 1;
309+
$return["data"] = "Invalid JSON / Incorrect status / No signature returned.";
310+
}
311+
312+
return $return;
313+
}
314+
279315
private function getGCMToken()
280316
{
281317
$ch = curl_init();
@@ -347,70 +383,72 @@ public function login($password, $force = FALSE)
347383

348384
if(($do == 1) || (!(array_key_exists($this->username,$this->totArray[0]))) || (!(array_key_exists($this->username,$this->totArray[1]))))
349385
{
350-
$dtoken = $this->getDeviceToken();
386+
$dtoken = $this->getDeviceToken();
351387

352-
if($dtoken['error'] == 1)
353-
{
354-
$return['message'] = "Failed to get new Device token set.";
355-
return $return;
356-
}
388+
if($dtoken['error'] == 1)
389+
{
390+
$return['message'] = "Failed to get new Device token set.";
391+
return $return;
392+
}
357393

358-
$timestamp = parent::timestamp();
359-
$req_token = parent::hash(parent::STATIC_TOKEN, $timestamp);
360-
$string = $this->username . "|" . $password . "|" . $timestamp . "|" . $req_token;
394+
$timestamp = parent::timestamp();
395+
$req_token = parent::hash(parent::STATIC_TOKEN, $timestamp);
396+
$string = $this->username . "|" . $password . "|" . $timestamp . "|" . $req_token;
361397

362-
$auth = $this->getAuthToken();
363-
$this->totArray[1][$this->username] = array($auth, time()+(55*60));
364-
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . self::DATA_FOLDER . DIRECTORY_SEPARATOR . "auth-$this->username.dat", serialize($this->totArray));
365-
if($auth['error'] == 1)
366-
{
367-
return $auth;
368-
}
369-
parent::setGAuth($auth);
370-
$attestation = $this->getAttestation($password, $timestamp);
398+
$auth = $this->getAuthToken();
399+
$this->totArray[1][$this->username] = array($auth, time()+(55*60));
400+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . self::DATA_FOLDER . DIRECTORY_SEPARATOR . "auth-$this->username.dat", serialize($this->totArray));
401+
if($auth['error'] == 1)
402+
{
403+
return $auth;
404+
}
405+
parent::setGAuth($auth);
406+
$attestation = $this->getAttestation($password, $timestamp);
407+
$clientAuthToken = $this->getClientAuthToken($this->username, $password, $timestamp);
371408

372-
$result = parent::post(
373-
'/loq/login',
374-
array(
375-
'username' => $this->username,
376-
'password' => $password,
377-
'height' => 1280,
378-
'width' => 720,
379-
'max_video_height' => 640,
380-
'max_video_width' => 480,
381-
'dsig' => substr(hash_hmac('sha256', $string, $dtoken['data']->dtoken1v), 0, 20),
382-
'dtoken1i' => $dtoken['data']->dtoken1i,
383-
'ptoken' => "ie",
384-
'timestamp' => $timestamp,
385-
'attestation' => $attestation,
386-
'sflag' => 1,
387-
'application_id' => 'com.snapchat.android',
388-
'req_token' => $req_token,
389-
),
390-
array(
391-
parent::STATIC_TOKEN,
392-
$timestamp,
393-
$auth['auth']
394-
),
395-
$multipart = false,
396-
$debug = $this->debug
397-
);
409+
$result = parent::post(
410+
'/loq/login',
411+
array(
412+
'username' => $this->username,
413+
'password' => $password,
414+
'height' => 1280,
415+
'width' => 720,
416+
'max_video_height' => 640,
417+
'max_video_width' => 480,
418+
'dsig' => substr(hash_hmac('sha256', $string, $dtoken['data']->dtoken1v), 0, 20),
419+
'dtoken1i' => $dtoken['data']->dtoken1i,
420+
'ptoken' => "ie",
421+
'timestamp' => $timestamp,
422+
'attestation' => $attestation,
423+
'sflag' => 1,
424+
'application_id' => 'com.snapchat.android',
425+
'req_token' => $req_token,
426+
),
427+
array(
428+
parent::STATIC_TOKEN,
429+
$timestamp,
430+
$auth['auth'],
431+
$clientAuthToken["signature"]
432+
),
433+
$multipart = false,
434+
$debug = $this->debug
435+
);
398436

399437

400-
if($result['error'] == 1)
401-
{
402-
return $result;
403-
}
438+
if($result['error'] == 1)
439+
{
440+
return $result;
441+
}
404442

405-
if(isset($result['data']->updates_response->logged) && $result['data']->updates_response->logged)
406-
{
407-
$this->auth_token = $result['data']->updates_response->auth_token;
408-
$this->device();
409-
$this->totArray[0][$this->username] = $this->auth_token;
410-
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . self::DATA_FOLDER . DIRECTORY_SEPARATOR . "auth-$this->username.dat", serialize($this->totArray));
411-
}
443+
if(isset($result['data']->updates_response->logged) && $result['data']->updates_response->logged)
444+
{
445+
$this->auth_token = $result['data']->updates_response->auth_token;
446+
$this->device();
447+
$this->totArray[0][$this->username] = $this->auth_token;
448+
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . self::DATA_FOLDER . DIRECTORY_SEPARATOR . "auth-$this->username.dat", serialize($this->totArray));
449+
}
412450

413-
return $result;
451+
return $result;
414452
}
415453
else
416454
{

src/snapchat_agent.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class SnapchatAgent {
1111
* Before updating this value, confirm
1212
* that the library requests everything in the same way as the app.
1313
*/
14-
const USER_AGENT = 'Snapchat/9.10.0.0 (HTC One; Android 4.4.2#302626.7#19; gzip)';
14+
const USER_AGENT = 'Snapchat/9.14.2.0 (HTC One; Android 4.4.2#302626.7#19; gzip)';
1515

1616
/*
1717
* The API URL. We're using the /bq endpoint, the one that the iPhone
@@ -362,6 +362,7 @@ public function post($endpoint, $data, $params, $multipart = FALSE, $debug = FAL
362362
{
363363
$headers = array_merge(self::$CURL_HEADERS, array(
364364
"X-Snapchat-Client-Auth-Token: Bearer {$params[2]}",
365+
"X-Snapchat-Client-Auth: {$params[3]}",
365366
"Accept-Encoding: gzip"));
366367
}
367368
else

0 commit comments

Comments
 (0)