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

Commit

Permalink
update to 9.16.2.0. MUST GET AN API KEY, SEE README
Browse files Browse the repository at this point in the history
  • Loading branch information
teknogeek committed Oct 10, 2015
1 parent 4c85707 commit 0a0d718
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 162 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
composer require mgp25/snapapi
```

## Getting a Casper API Key

This is required for the API to work.

Go to https://clients.casper.io/login.php and create an account.

Once you have created an account, go to "Projects" and create a new project.

![projects](http://s2.postimg.org/r7olutpah/projects.png)

Now you will have your project with your API Key and API Secret.

![api](http://s2.postimg.org/vi39qeudl/api.png)

You will need to set this data in the constructor, as shown in the [examples] (/examples).

### Special thanks

- [teknogeek](https://github.com/teknogeek)
Expand Down
14 changes: 8 additions & 6 deletions examples/exampleBots/friendBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
include_once("../../src/snapchat.php");

/////////// DATA /////////////
$username = '';
$password = '';
$gEmail = '';
$gPasswd = '';
$debug = false;
$username = '';
$password = '';
$gEmail = '';
$gPasswd = '';
$casperKey = '';
$casperSecret = '';
$debug = false;
//////////////////////////////

// Login
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $debug);
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $casperKey, $casperSecret, $debug);
$snapchat->login($password);

// Get unconfirmed friends
Expand Down
12 changes: 7 additions & 5 deletions examples/exampleFunctional.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
require_once("../src/snapchat.php");

//////////// CONFIG ////////////
$username = ""; // Your snapchat username
$password = ""; // Your snapchat password
$gEmail = ""; // Gmail account
$gPasswd = ""; // Gmail account password
$username = ""; // Your snapchat username
$password = ""; // Your snapchat password
$gEmail = ""; // Gmail account
$gPasswd = ""; // Gmail account password
$casperKey = ""; // Casper API Key
$casperSecret = ""; // Casper API Secret
$debug = false; // Set this to true if you want to see all outgoing requests and responses from server
////////////////////////////////


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

$snapchat = new Snapchat($username, $gEmail, $gPasswd, $debug);
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $casperKey, $casperSecret, $debug);

//Login to Snapchat with your username and password
$snapchat->login($password);
Expand Down
17 changes: 12 additions & 5 deletions examples/registerTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
echo "\nGmail password: ";
$gPasswd = trim(fgets(STDIN));

$snapchat = new Snapchat($username, $gMail, $gPasswd, true);
echo "\nCasper key: ";
$casperKey = trim(fgets(STDIN));

echo "\nCasper secret: ";
$casperSecret = trim(fgets(STDIN));

$snapchat = new Snapchat($username, $gMail, $gPasswd, $casperKey, $casperSecret, true);


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

$result = $snapchat->sendCaptcha($result, $id);
unlink(__DIR__."{$id}");
if ($result == null)
unlink(__DIR__.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."src".DIRECTORY_SEPARATOR.$id);
if(property_exists($result, "error") && $result->error === 0 && property_exists($result->data, "find_friends_enabled"))
{
echo "Account successfully created\n";
echo "\nUsername: $username\n";
echo "Password: $password\n";
echo "Email: $email\n";
}
else {
else
{
echo "There was an error registering your account\n";
echo "Error code: " . $result['code'];
}
}
12 changes: 9 additions & 3 deletions examples/verifyPhone.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
echo "\nGmail password: ";
$gPasswd = trim(fgets(STDIN));

echo "\Phone number: ";
echo "\nCasper key: ";
$casperKey = trim(fgets(STDIN));

echo "\nCasper secret: ";
$casperSecret = trim(fgets(STDIN));

echo "\nPhone number: ";
$phone = trim(fgets(STDIN));

$snapchat = new Snapchat($username, $gEmail, $gPasswd, true);
$snapchat = new Snapchat($username, $gEmail, $gPasswd, $casperKey, $casperSecret, true);

$snapchat->login($password);

$snapchat->sendPhoneVerification($phone);

echo "\Code: ";
echo "\nCode: ";
$code = trim(fgets(STDIN));

$snapchat->verifyPhoneNumber($code);
143 changes: 143 additions & 0 deletions src/Casper-API-PHP/CasperAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

include_once dirname(__FILE__) . '/CasperAgent.php';
include_once dirname(__FILE__) . '/CasperException.php';

/**
* @file
* PHP implementation of the Casper API.
*/
class CasperAPI extends CasperAgent {

const SNAPCHAT_VERSION = "9.16.2.0";

public function __construct($api_key = null, $api_secret = null){
parent::setAPIKey($api_key);
parent::setAPISecret($api_secret);
}

public function getSnapchatInfo(){
return parent::get("/snapchat");
}

/**
* Fetches a Snapchat Client Auth Signature (X-Snapchat-Client-Auth) from the Casper API
*
* @param string $username
* Your Snapchat Username
*
* @param string $password
* Your Snapchat Password
*
* @param string $timestamp
* The timestamp you send in the Snapchat Login Request
*
* @return string
* The Client Auth Token
*
* @throws CasperException
* An exception is thrown if an error occurs.
*/
public function getSnapchatClientAuth($username, $password, $timestamp){

$response = parent::post("/snapchat/clientauth/signrequest", null, array(
"username" => $username,
"password" => $password,
"timestamp" => $timestamp,
"snapchat_version" => self::SNAPCHAT_VERSION
));

if(!isset($response->signature)){
throw new CasperException("Signature not found in Response");
}

return $response->signature;

}

/**
* Fetches an Attestation by making multiple API calls to the Google and Casper APIs.
*
* @param string $nonce
* Base64 encoded value of the nonce
* sha256(username|password|timestamp|/loq/login)
*
* @return string
* The Client Auth Token
*
* @throws CasperException
* An exception is thrown if an error occurs.
*/
public function getSnapchatAttestation($nonce){

$response = parent::get("/snapchat/attestation/create");

if(!isset($response->binary)){
throw new CasperException("Binary not found in Response");
}

$binary = base64_decode($response->binary);

$response = parent::externalRequest("https://www.googleapis.com/androidantiabuse/v1/x/create?alt=PROTO&key=AIzaSyBofcZsgLSS7BOnBjZPEkk4rYwzOIz-lTI", array(
"Content-Type: application/x-protobuf",
"User-Agent: SafetyNet/7899000 (klte KOT49H); gzip"
), $binary, true);

$protobuf = base64_encode($response);

$response = parent::post("/snapchat/attestation/attest", null, array(
"protobuf" => $protobuf,
"nonce" => $nonce,
"snapchat_version" => self::SNAPCHAT_VERSION
));

if(!isset($response->binary)){
throw new CasperException("Binary not found in Response");
}

$binary = base64_decode($response->binary);

$response = parent::externalRequest("https://www.googleapis.com/androidcheck/v1/attestations/attest?alt=JSON&key=AIzaSyDqVnJBjE5ymo--oBJt3On7HQx9xNm1RHA", array(
"Content-Type: application/x-protobuf",
"User-Agent: SafetyNet/7899000 (klte KOT49H); gzip"
), $binary, true);

$json = json_decode($response);
if($json == null){
throw new CasperException("Failed to decode response!");
}

if(!isset($json->signedAttestation)){
throw new CasperException("Attestation not found in Response");
}

return $json->signedAttestation;

}

/**
* Generates an Nonce for Attestation requests.
*
* @param string $username
* Snapchat Username
*
* @param string $password
* Snapchat Password
*
* @param string $timestamp
* Snapchat Login Timestamp
*
* @param string $endpoint
* Snapchat Login Endpoint, always /loq/login at this stage.
*
* @return string
* The Base64 Encoded Nonce
*
* @throws CasperException
* An exception is thrown if an error occurs.
*/
public function generateSnapchatNonce($username, $password, $timestamp, $endpoint = "/loq/login"){
return base64_encode(hash("sha256", "{$username}|{$password}|{$timestamp}|{$endpoint}", true));
}

}
Loading

0 comments on commit 0a0d718

Please sign in to comment.