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

Commit 0a0d718

Browse files
committed
update to 9.16.2.0. MUST GET AN API KEY, SEE README
1 parent 4c85707 commit 0a0d718

File tree

10 files changed

+523
-162
lines changed

10 files changed

+523
-162
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
composer require mgp25/snapapi
1111
```
1212

13+
## Getting a Casper API Key
14+
15+
This is required for the API to work.
16+
17+
Go to https://clients.casper.io/login.php and create an account.
18+
19+
Once you have created an account, go to "Projects" and create a new project.
20+
21+
![projects](http://s2.postimg.org/r7olutpah/projects.png)
22+
23+
Now you will have your project with your API Key and API Secret.
24+
25+
![api](http://s2.postimg.org/vi39qeudl/api.png)
26+
27+
You will need to set this data in the constructor, as shown in the [examples] (/examples).
28+
1329
### Special thanks
1430

1531
- [teknogeek](https://github.com/teknogeek)

examples/exampleBots/friendBot.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
include_once("../../src/snapchat.php");
44

55
/////////// DATA /////////////
6-
$username = '';
7-
$password = '';
8-
$gEmail = '';
9-
$gPasswd = '';
10-
$debug = false;
6+
$username = '';
7+
$password = '';
8+
$gEmail = '';
9+
$gPasswd = '';
10+
$casperKey = '';
11+
$casperSecret = '';
12+
$debug = false;
1113
//////////////////////////////
1214

1315
// Login
14-
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $debug);
16+
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $casperKey, $casperSecret, $debug);
1517
$snapchat->login($password);
1618

1719
// Get unconfirmed friends

examples/exampleFunctional.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
require_once("../src/snapchat.php");
44

55
//////////// CONFIG ////////////
6-
$username = ""; // Your snapchat username
7-
$password = ""; // Your snapchat password
8-
$gEmail = ""; // Gmail account
9-
$gPasswd = ""; // Gmail account password
6+
$username = ""; // Your snapchat username
7+
$password = ""; // Your snapchat password
8+
$gEmail = ""; // Gmail account
9+
$gPasswd = ""; // Gmail account password
10+
$casperKey = ""; // Casper API Key
11+
$casperSecret = ""; // Casper API Secret
1012
$debug = false; // Set this to true if you want to see all outgoing requests and responses from server
1113
////////////////////////////////
1214

1315

1416
$imagePath = ""; // URL or local path to a media file (image or video)
1517
$sendTo = array();
1618

17-
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $debug);
19+
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $casperKey, $casperSecret, $debug);
1820

1921
//Login to Snapchat with your username and password
2022
$snapchat->login($password);

examples/registerTool.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
echo "\nGmail password: ";
2222
$gPasswd = trim(fgets(STDIN));
2323

24-
$snapchat = new Snapchat($username, $gMail, $gPasswd, true);
24+
echo "\nCasper key: ";
25+
$casperKey = trim(fgets(STDIN));
26+
27+
echo "\nCasper secret: ";
28+
$casperSecret = trim(fgets(STDIN));
29+
30+
$snapchat = new Snapchat($username, $gMail, $gPasswd, $casperKey, $casperSecret, true);
2531

2632

2733
$id = $snapchat->register($username, $password, $email, $birthday);
@@ -35,15 +41,16 @@
3541
$result = trim(fgets(STDIN));
3642

3743
$result = $snapchat->sendCaptcha($result, $id);
38-
unlink(__DIR__."{$id}");
39-
if ($result == null)
44+
unlink(__DIR__.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."src".DIRECTORY_SEPARATOR.$id);
45+
if(property_exists($result, "error") && $result->error === 0 && property_exists($result->data, "find_friends_enabled"))
4046
{
4147
echo "Account successfully created\n";
4248
echo "\nUsername: $username\n";
4349
echo "Password: $password\n";
4450
echo "Email: $email\n";
4551
}
46-
else {
52+
else
53+
{
4754
echo "There was an error registering your account\n";
4855
echo "Error code: " . $result['code'];
49-
}
56+
}

examples/verifyPhone.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@
1515
echo "\nGmail password: ";
1616
$gPasswd = trim(fgets(STDIN));
1717

18-
echo "\Phone number: ";
18+
echo "\nCasper key: ";
19+
$casperKey = trim(fgets(STDIN));
20+
21+
echo "\nCasper secret: ";
22+
$casperSecret = trim(fgets(STDIN));
23+
24+
echo "\nPhone number: ";
1925
$phone = trim(fgets(STDIN));
2026

21-
$snapchat = new Snapchat($username, $gEmail, $gPasswd, true);
27+
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $casperKey, $casperSecret, true);
2228

2329
$snapchat->login($password);
2430

2531
$snapchat->sendPhoneVerification($phone);
2632

27-
echo "\Code: ";
33+
echo "\nCode: ";
2834
$code = trim(fgets(STDIN));
2935

3036
$snapchat->verifyPhoneNumber($code);

src/Casper-API-PHP/CasperAPI.php

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
include_once dirname(__FILE__) . '/CasperAgent.php';
4+
include_once dirname(__FILE__) . '/CasperException.php';
5+
6+
/**
7+
* @file
8+
* PHP implementation of the Casper API.
9+
*/
10+
class CasperAPI extends CasperAgent {
11+
12+
const SNAPCHAT_VERSION = "9.16.2.0";
13+
14+
public function __construct($api_key = null, $api_secret = null){
15+
parent::setAPIKey($api_key);
16+
parent::setAPISecret($api_secret);
17+
}
18+
19+
public function getSnapchatInfo(){
20+
return parent::get("/snapchat");
21+
}
22+
23+
/**
24+
* Fetches a Snapchat Client Auth Signature (X-Snapchat-Client-Auth) from the Casper API
25+
*
26+
* @param string $username
27+
* Your Snapchat Username
28+
*
29+
* @param string $password
30+
* Your Snapchat Password
31+
*
32+
* @param string $timestamp
33+
* The timestamp you send in the Snapchat Login Request
34+
*
35+
* @return string
36+
* The Client Auth Token
37+
*
38+
* @throws CasperException
39+
* An exception is thrown if an error occurs.
40+
*/
41+
public function getSnapchatClientAuth($username, $password, $timestamp){
42+
43+
$response = parent::post("/snapchat/clientauth/signrequest", null, array(
44+
"username" => $username,
45+
"password" => $password,
46+
"timestamp" => $timestamp,
47+
"snapchat_version" => self::SNAPCHAT_VERSION
48+
));
49+
50+
if(!isset($response->signature)){
51+
throw new CasperException("Signature not found in Response");
52+
}
53+
54+
return $response->signature;
55+
56+
}
57+
58+
/**
59+
* Fetches an Attestation by making multiple API calls to the Google and Casper APIs.
60+
*
61+
* @param string $nonce
62+
* Base64 encoded value of the nonce
63+
* sha256(username|password|timestamp|/loq/login)
64+
*
65+
* @return string
66+
* The Client Auth Token
67+
*
68+
* @throws CasperException
69+
* An exception is thrown if an error occurs.
70+
*/
71+
public function getSnapchatAttestation($nonce){
72+
73+
$response = parent::get("/snapchat/attestation/create");
74+
75+
if(!isset($response->binary)){
76+
throw new CasperException("Binary not found in Response");
77+
}
78+
79+
$binary = base64_decode($response->binary);
80+
81+
$response = parent::externalRequest("https://www.googleapis.com/androidantiabuse/v1/x/create?alt=PROTO&key=AIzaSyBofcZsgLSS7BOnBjZPEkk4rYwzOIz-lTI", array(
82+
"Content-Type: application/x-protobuf",
83+
"User-Agent: SafetyNet/7899000 (klte KOT49H); gzip"
84+
), $binary, true);
85+
86+
$protobuf = base64_encode($response);
87+
88+
$response = parent::post("/snapchat/attestation/attest", null, array(
89+
"protobuf" => $protobuf,
90+
"nonce" => $nonce,
91+
"snapchat_version" => self::SNAPCHAT_VERSION
92+
));
93+
94+
if(!isset($response->binary)){
95+
throw new CasperException("Binary not found in Response");
96+
}
97+
98+
$binary = base64_decode($response->binary);
99+
100+
$response = parent::externalRequest("https://www.googleapis.com/androidcheck/v1/attestations/attest?alt=JSON&key=AIzaSyDqVnJBjE5ymo--oBJt3On7HQx9xNm1RHA", array(
101+
"Content-Type: application/x-protobuf",
102+
"User-Agent: SafetyNet/7899000 (klte KOT49H); gzip"
103+
), $binary, true);
104+
105+
$json = json_decode($response);
106+
if($json == null){
107+
throw new CasperException("Failed to decode response!");
108+
}
109+
110+
if(!isset($json->signedAttestation)){
111+
throw new CasperException("Attestation not found in Response");
112+
}
113+
114+
return $json->signedAttestation;
115+
116+
}
117+
118+
/**
119+
* Generates an Nonce for Attestation requests.
120+
*
121+
* @param string $username
122+
* Snapchat Username
123+
*
124+
* @param string $password
125+
* Snapchat Password
126+
*
127+
* @param string $timestamp
128+
* Snapchat Login Timestamp
129+
*
130+
* @param string $endpoint
131+
* Snapchat Login Endpoint, always /loq/login at this stage.
132+
*
133+
* @return string
134+
* The Base64 Encoded Nonce
135+
*
136+
* @throws CasperException
137+
* An exception is thrown if an error occurs.
138+
*/
139+
public function generateSnapchatNonce($username, $password, $timestamp, $endpoint = "/loq/login"){
140+
return base64_encode(hash("sha256", "{$username}|{$password}|{$timestamp}|{$endpoint}", true));
141+
}
142+
143+
}

0 commit comments

Comments
 (0)