Log in or register to post comments

VWS Authorization problem

December 21, 2012 - 12:48am #1

Hi

 

I have class for operations with VWS in php, but i dont know authorize with my  account.

Php code for target list:

 

  $vuforia = new vuforiaTargetAPI("{server secret key}", "{server access key}");
  $curlInfo = $vuforia->getTargetList();

  public function getTargetList(){
    $credentials = $this->createSignature("/targets");
    return $this->getData($credentials, "https://vws.vuforia.com/targets");
  }

Php code for submiting data:

  public function getData($credentials, $target, $postType = "GET"){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials));
    $page = curl_exec($ch);
    curl_close($ch);
    return $page;
  }

Php code for generating credentials:

  private function createSignature($requestPath, $postType = "GET", $contentType = "", $content = ""){
    $contentMD5 = md5($content);
    $date = new DateTime("now", new DateTimeZone("GMT"));
    $stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . "\n" . $requestPath;
    $signature = base64_encode(hash_hmac('sha1', $stringToSign, $this->serverSecretKey));
    $credentials = $this->serverAccessKey . ":" . $signature;
    return $credentials;
  }

$stringToSign for this example is

GET
d41d8cd98f00b204e9800998ecf8427e

Fri, 21 Dec 2012 08:35:31
/targets

 

Http header is

GET /targets HTTP/1.1 Host: vws.vuforia.com Accept: */* Authorization: VWS 08a061624dabe0c1871f9c93e680a38d8d073e19:NjY2ODI1OTMwZDhiZTk1NWNlMzFmYTRhNzkzN2ZmNjA3YTQ2MjY3YQ==

I m trying date in 3 different formats(Fri, 21 Dec 2012 08:35:31, Fri, 21 Dec 2012 08:43:49 +0000, Fri, 21 Dec 2012 08:35:31 GMT) and request path in 2 formats(/targets, https://vws.vuforia.com/targets). And now, i havent any idea what is wrong. Can you help me? If it post in wrong category please move it to right category.

VWS Authorization problem

July 28, 2017 - 6:06am #56

Hi Everybody,

I am directly trying to get the target from the vuforia API request to postman webservices , but it shows an error.Can anybody give me a Idea.

 

 

{

    "result_code": "AuthenticationFailure",

    "transaction_id": "e38ab514715c447ba79a77084c1f45fe"

}

VWS Authorization problem

September 1, 2015 - 4:34am #55

Hey, 
I fixed the problem by using the code from this link:
https://github.com/jacobtabak/curl-vuforia-client

 

:)

VWS Authorization problem

September 1, 2015 - 2:32am #54

Hey,

I wrote a little PHP script base on the Sample Code (PostNewTarget.php) and this thread here, to upload an image target.

When I try to add an image target to cloud database I get the following Authentication Failure error:

HTTP/1.1 100 Continue HTTP/1.1 401 Unauthorized Content-Type: application/json; charset=utf-8 Date: Tue, 01 Sep 2015 09:17:05 GMT Server: nginx Content-Length: 91 Connection: keep-alive {"result_code":"AuthenticationFailure","transaction_id":"f32ebafc66a84b77b15a3b37a313cc03"}1

The main functions of my PostNewTarget class are this:

function postNewTargetWithCurl(){

		// date and signature for header
		$date = new DateTime("now", new DateTimeZone("GMT"));
		$signature = $this->createSignature($date);

		// Create CURL Object
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->url . $this->requestPath);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
		curl_setopt($ch, CURLOPT_POST, TRUE);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$this->jsonRequestObject);
		curl_setopt($ch, CURLOPT_HEADER, TRUE);
		curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$signature,'DATE: '.$date->format("D, d M Y H:i:s") . ' GMT'));

		// Send and get result
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}

	private function createSignature($date){
		$stringToSign = "POST" . "\n" . 
			md5($this->jsonRequestObject) . "\n" . 
			$this->contentType . "\n" . 
			$date->format("D, d M Y H:i:s") . " GMT\n" . 
			$this->requestPath;
		$signature = $this->hexToBase64(hash_hmac('sha1', $stringToSign, $this->secret_key));
		$credentials = $this->access_key . ":" . $signature;
		return $credentials;
	}

Secret and Access key are set correctly. The hexToBase64 and getImageAsBase64 function and jsonRequestObject are from the example. Can anyone please please help me?

Thanks!!!!!

 

VWS Authorization problem

August 8, 2014 - 6:39am #53

try this.

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

PUT => change to DELETE,GET,PUT

all the best.

p/s : i forget the code i wrote.. veryvery long time ago.

VWS Authorization problem

August 1, 2014 - 4:52pm #52

Hey David 

as usual i get same unauthorized 401

HTTP/1.1 401 Unauthorized Server: Apache-Coyote/1.1 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked

my code is

$tmp = $_FILES['imagetarget']['tmp_name'];
 $name = basename($_FILES['imagetarget']['name']);
 if(move_uploaded_file($tmp, $path.$name)){
 
 
//print_r($tmp ." helli ".$path.$name);die;
$result = getTargetList();
print_r("hello");
print_r($result);
 }
 
 
function getTargetList(){
global $name;
global $path;
$body = json_encode(array(
    "name" => $name,
        "width" => 1024.0,
        "image_url" => base64_encode($path.$name),
        "active_flag" => 1,
        "application_metadata_url" => base64_encode($_POST["metadata"]))
     );
 
$credentials = createSignature("/targets",$body);
return getData($credentials, "https://vws.vuforia.com/targets");
}
 
function getData($credentials, $target, $postType = "GET"){
$date = new DateTime("now", new DateTimeZone("GMT"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials,'DATE: '.$date->format("D, d M Y H:i:s") . ' GMT'));
$page = curl_exec($ch);
curl_close($ch);
return $page;
}
            
function createSignature($requestPath, $content, $postType = "GET", $contentType = "application/json" ){
$access_key = "access key";
$secret_key = "secret key";
$contentMD5 = md5($content);
$date = new DateTime("now", new DateTimeZone("GMT"));
$stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . " GMT\n" . $requestPath;
//print_r($content);die;
$signature = hexToBase64(hash_hmac('sha1', $stringToSign, $secret_key));
$credentials = $access_key . ":" . $signature;
return $credentials;
}
 
function hexToBase64($hex){
$return = '';
foreach(str_split($hex, 2) as $pair){
$return .= chr(hexdec($pair));
}
return base64_encode($return);
}

VWS Authorization problem

May 20, 2013 - 11:04am #51

Hi,

        how to delete the cloud targets and meta data packages using curl method in php, could please give some sample code using curl method

VWS Authorization problem

May 18, 2013 - 9:47am #50

hi

        could you please  anyone share answer for this question??

VWS Authorization problem

May 8, 2013 - 9:20pm #49

khong20 wrote:

CUrl operator put wrongly.. LOL

 

Hey khong,

could you share your answer? I'm trying to update and delete target using curl and php but I can't make it work :(

Thank you

VWS Authorization problem

May 1, 2013 - 3:38am #48

CUrl operator put wrongly.. LOL

VWS Authorization problem

April 30, 2013 - 10:44am #47

What had been the problem? - how did you fix it?

VWS Authorization problem

April 30, 2013 - 7:15am #46

nvm... i search back my BOOK of Curl.. and figure it out.

now it working

VWS Authorization problem

April 30, 2013 - 3:08am #45

even i try this method also not working

 

function getDeleteID($TargetID){
    $credentials = createSignature("/targets/".$TargetID,"DELETE"); // /targets 68fa8868c8e043ea8e776d76c929d4a4
    return delData($credentials, "https://vws.vuforia.com/targets/".$TargetID);
    
}

function delData($credentials, $target, $TargetID){
    $date = new DateTime("now", new DateTimeZone("GMT"));
    
    // Create a stream
    $opts = array(
      'http'=>array(
          'method'=>'DELETE',
        'header'=>"DELETE /targets/".$TargetID." HTTP/1.1\r\n" .
                  "Host: vws.vuforia.com\r\n" .
                  "Accept-Encoding: identity\r\n".
                  "DATE: ".$date->format("D, d M Y H:i:s")." GMT\r\n" .
                  "Authorization: VWS ".$credentials."\r\n"
      )
    );
    
    $context = stream_context_create($opts);
    
    // Open the file using the HTTP headers set above
    return $file = file_get_contents($target, false, $context);
   
}

VWS Authorization problem

April 30, 2013 - 1:00am #44

Need some help from forum member,

what when wrong in this code as i always get , any expert could slove my problem

HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 30 Apr 2013 07:56:38 GMT

{"result_code":"AuthenticationFailure","transaction_id":"fa348c2ed9ea41cabe5239c376604877"}

 

-------------------------

 

function getDeleteID($TargetID){
    $credentials = createSignature("/targets/".$TargetID,"DELETE"); // /targetsID c01b73868ac0447395a12c01300b9400
    return delData($credentials, "https://vws.vuforia.com/targets/",$TargetID);
}

function delData($credentials, $target ,$TargetID){
    $date = new DateTime("now", new DateTimeZone("GMT"));
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("DELETE /targets/".$TargetID." HTTP/1.1","Host: vws.vuforia.com",'Authorization: VWS ' .$credentials,'DATE: '.$date->format("D, d M Y H:i:s") . ' GMT'));
    $page = curl_exec($ch);
    curl_close($ch);
    return $page;
}

 

VWS Authorization problem

April 26, 2013 - 11:28am #43

tips?

I found  hash_hmac problem in php is working correctry as follows,

    $signature = base64_encode(hash_hmac('sha1', $stringToSign, $ServerSecret,true));

 

/////////

function createSignature($requestPath, $postType="GET" , $contentType="" , $content="" ){
    global $date;
    global $ServerAccess,$ServerSecret;

    $contentMD5 = md5($content);
    $stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . " GMT\n" . $requestPath;
    $signature = base64_encode(hash_hmac('sha1', $stringToSign, $ServerSecret,true));
    $credentials = $ServerAccess.":".$signature;
//    echo " credentials ::" . $credentials . '<br />';
    return $credentials;
}

/////////

 

Now you don't have to use  below function...

/////////

function hexToBase64($hex){
    $return = '';
    foreach(str_split($hex, 2) as $pair){
        $return .= chr(hexdec($pair));
    }
    return base64_encode($return);
}

/////////

 

thanks.

VWS Authorization problem

April 21, 2013 - 10:55pm #42

I am trying to post new targets using ruby but I am having problems with the authentication, does anyone has sample code in ruby that I can use as an example?

VWS Authorization problem

April 19, 2013 - 1:35pm #41

Hi,

I have been struggling to get past Authorization Failed when connecting up to VWS. It would be nice to have a more step by step process with sample PHP code. The generic error really only tells you that there is some issue with your header. Do you have a sample file that just helps to make sure you got the header authorization correct and returns Success. It will make it easier to build on from there.

 

Thanks,

Nin

VWS Authorization problem

March 22, 2013 - 10:13am #40

hi guys..

i cant post target... i m getting 

HTTP/1.1 100 Continue HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Fri, 22 Mar 2013 17:09:42 GMT Connection: close {"result_code":"Fail","transaction_id":"2a5a2c0d11194a6ba96d5e8f448f6eb8"}

 

why this error is shown?

any help plzz 

VWS Authorization problem

March 20, 2013 - 7:03am #39

hi everyone,

does posting a target works for php?

have anyone posted a target yet.. ?

i m getting RESULT CODE:FAIL

any help?

VWS Authorization problem

March 10, 2013 - 9:55am #38

You can  monitor the status of you targets through the Target Manager or using the VWS API. If you are using the VWS API, you will need to implement some way to poll VWS. There are a variety of ways to accomplish this depending on the application environment that you are using. How are you hosting your app?

VWS Authorization problem

March 10, 2013 - 1:44am #37

when i get the image contents using file_get_contents() , the contents of image i get from this funtion is not converted to base64 the result is empty i cant see anything on the browser page??

 

VWS Authorization problem

March 10, 2013 - 1:29am #36

@maksim13

hi

why u are using file_get_contents()?

trying to convert image to base64_encode() , cant we put the image inbase64 funtion? 

what is the use of file_get_contents()?

 

when i get the file contents , and pass it to base64 funtion , and echo the encoded pic.. it do nothing..

thanx.. plz help

VWS Authorization problem

March 9, 2013 - 11:13pm #35

how we monitor the status of our uploaded target? in php?

 

VWS Authorization problem

March 9, 2013 - 10:13pm #34

actually we were sending request from local server, then i used the code below to find error in my Curl funtion 

if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}

and the error was..

Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Using the funtion below it worked

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

now the problems are in adding a new target.. i m working on it .. if any help provided will lead me to complete my task..

 

VWS Authorization problem

March 9, 2013 - 3:50pm #33

@ejo_khan

You should get a response body that  looks like the JSON below..

 

HTTP/1.1 200 OK
Content-Type: application/json
{
“result_code”:”Success”,
“transaction_id”:”550e8400e29440000b41d4a716446655”,
 “results”:[
      ”00550e84e29b41d4a71644665555678”,
      ”578fe7fd60055a5a84c2d215066b7a9d”
]
}

see:

https://developer.vuforia.com/resources/dev-guide/listing-targets-cloud-database

What is the response body that your are receiving?

VWS Authorization problem

March 9, 2013 - 3:46pm #32

@Maksim13

What is the response that you are getting from the server?

Can you post an example of your request body?

VWS Authorization problem

March 9, 2013 - 3:32am #31

hi sir..

sir i have made the connection , it dont give any error but.. do not print the $result  , 

i have to ask that what will be the response of server when we want to get all targets? 

my $result dont print any thing neigther there is error in my code.. plz help if possible

thanx

VWS Authorization problem

February 15, 2013 - 1:48am #30

May be somebody know how to create array of data, in particular upload picture

VWS Authorization problem

February 14, 2013 - 4:39am #29

 

It didn`t help.  
 
function InsData(){
$image = base64_encode($byte_array);
$byte_array2 = file_get_contents('http://192.168.1.144:86/vuforia/test.txt');
$text_file = base64_encode($byte_array2);
 
 $arr = array("name"=>"tarprueba","width"=>"320","image"=>$image , "active_flag" => "1","application_metadata"=>$text_file);
 $content = json_encode($arr);
 
$credentials = createSignature("/targets", "POST", "application/json", $content);
return postData($credentials, "https://vws.vuforia.com/targets", $content);
 
function postData($credentials, $target, $data){
$date = new DateTime("now", new DateTimeZone("GMT")); 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Date: ' .$date->format("D, d M Y H:i:s"), 'Content-Type: application/json', 'Authorization: VWS ' .$credentials));
    $json = curl_exec($ch);
    curl_close($ch);
    return $json;
  } 

VWS Authorization problem

February 14, 2013 - 4:26am #28

Replace foreach loops with base64_encode() function. And use my curl methods from this post https://developer.vuforia.com/forum/cloud-recognition/questions-php-developers

VWS Authorization problem

February 14, 2013 - 3:58am #27

I tried  to do  so: 

 

 
$array = array(); 
foreach(str_split($data) as $char){ 
    array_push($array, ord($char)); 
}
 
$image_byte = implode(' ', $array);
 
$meta_file = file_get_contents("http://192.168.1.144:86/vuforia/test.txt");
 
$array2 = array(); 
foreach(str_split($meta_file) as $char){ 
    array_push($array2, ord($char)); 
}
$meta_data = implode(' ', $array2);
 $arr = array("name"=>"tarprueba","width"=>32.0,"image"=>$image_byte,"application_metadata"=>$meta_data);
 $content = json_encode($arr);
 
 
but it don`t work too.

VWS Authorization problem

February 14, 2013 - 3:44am #26

I think that add target via url for metadata and picture isnt work. I read this in one older topic. Try upload picture and metadata directly.

VWS Authorization problem

February 14, 2013 - 2:37am #25

 

I can`t add target. Get "result_code":"AuthenticationFailure","transaction_id":"fe32db28f4fa49f68a545da9e55c4867".  
 
 
 
 
$result = InsData();
 
print_r($result);
 
 
 function getTargetList(){
 $postType = 'POST';
 
$credentials = createSignature("/targets");
return getData($credentials, "https://vws.vuforia.com/targets");
}
 
function InsData(){
 $content = json_encode($arr);
 
$credentials = createSignature("/targets", "POST", "application/json", $content);
 
return postData($credentials, "https://vws.vuforia.com/targets", $content);
 
function postData($credentials, $target, $data){
$date = new DateTime("now", new DateTimeZone("GMT")); 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials,'DATE: '.$date->format("D, d M Y H:i:s") . ' GMT'));
    $json = curl_exec($ch);
    curl_close($ch);
    return $json;
  } 
  
  
 function getData($credentials, $target, $postType = "GET"){
$date = new DateTime("now", new DateTimeZone("GMT"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials,'DATE: '.$date->format("D, d M Y H:i:s") . ' GMT'));
$page = curl_exec($ch);
 
curl_close($ch);
 
return $page;
}
 
 function createSignature($requestPath, $postType = "GET", $contentType = "", $content = ""){
$serverAccessKey = '';
$serverSecretKey = '';
$contentMD5 = md5($content);
 
$date = new DateTime("now", new DateTimeZone("GMT"));
$stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . " GMT\n" . $requestPath;
$signature = hexToBase64(hash_hmac('sha1', $stringToSign, $serverSecretKey));
$credentials = $serverAccessKey . ":" . $signature;
return $credentials;
}
 
 function hexToBase64($hex){
$return = '';
foreach(str_split($hex, 2) as $pair){
$return .= chr(hexdec($pair));
}
return base64_encode($return);
}

VWS Authorization problem

February 1, 2013 - 10:20am #24

We're going to be developing PHP samples and want some feedback from devs on how to approach these. Please see - https://developer.vuforia.com/forum/cloud-recognition/questions-php-developers

VWS Authorization problem

January 30, 2013 - 3:52am #23

Thank you very much chiwo. At least I receive a success response.

Next step is to send a POST with the target I want to add.

VWS Authorization problem

January 30, 2013 - 2:15am #22

You need add datetime value from createSignature to getData method. That $datetime is same as $datetime in createSignature.

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: VWS " .$credentials,"DATE: ".$datetime));

VWS Authorization problem

January 30, 2013 - 2:05am #21

The requestPath is "/targets" ($credentials = $this->createSignature("/targets");)

The keys are corrects and postType it's a GET:

 

public function getData($credentials, $target, $postType = "GET" ){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials));
    $page = curl_exec($ch);
    curl_close($ch);
    return $page;
  }

VWS Authorization problem

January 30, 2013 - 1:54am #20

@ Creadsmedia: not entering in the PHP discussion, but just a little note:

  as Chiwo suggests, you may want to double-check that your keys are correct; for that you can also use our Java samples (those are guaranteed to work, if you use correct keys)

 

VWS Authorization problem

January 30, 2013 - 1:48am #19

How requestPath did you use? And are you sure that your secret and access keys are correct? And how type(get all targets, get target by id or other?) of request do you use?

VWS Authorization problem

January 30, 2013 - 1:41am #18

No way...

i always get {"result_code":"AuthenticationFailure","transaction_id":"a5faaf1682ec4dc6865e34aa800e26a8"}

This is the code i use based  in yours:

private function createSignature($requestPath, $postType = "GET", $contentType = "", $content = ""){

    $contentMD5 = md5($content);
    $date = new DateTime("now", new DateTimeZone("GMT"));
    $datetime = $date->format("D, d M Y H:i:s ") . "GMT";
    $stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $datetime . "\n" . $requestPath;
    $signature = $this->hexToBase64(hash_hmac('sha1', $stringToSign, "7fa5543c5b658bac1ae0050c8d42d1c162802ada"));
...

VWS Authorization problem

January 30, 2013 - 1:32am #17

I use this for date.   

$date = new DateTime("now", new DateTimeZone("GMT"));
$datetime = $date->format("D, d M Y H:i:s ") . "GMT";

VWS Authorization problem

January 29, 2013 - 8:15am #16

Hi everyone,

I'm using the chiwo code but i retrieve always {"result_code":"AuthenticationFailure","transaction_id":"cc7399b95c69491c8a3b8fc0c8447f5a"}.

As chiwo said I use his function hexToBase64 but it does not work.

My line of code is $this->hexToBase64(hash_hmac('sha1', $stringToSign, "7fa5543c5b658bac1ae0050c8d42d1c162802ada"));

Now I have doubts about the date format, i'm using gmdate('D, d M Y H:i:s T', time()) is this correct?

Has anyone the same problem? How do did you solve it? Have anybody a complete code or part of them tht works properly?

Thanks in advance.

@ all: if you would like to

January 18, 2013 - 5:08am #15

@ all: if you would like to see some official PHP implementation (next to the Java samples that we provide already), it could also be a good idea for you to post an extra note in the wish-list section of our Forum ?

https://developer.vuforia.com/forum/general-discussion/wish-list

 

 

Could you please help?

January 18, 2013 - 4:26am #14

Hello chiwo,

It's feels great by viewing your answer. There is no one had(accept you) posted or helped in PHP code because there is no PHP code is available to upload image using webservice. Can you please provide PHP code to post target ? By creating code as per your last suggestion its only throwing "Authentication Failed" error.

 

Thanks & Regards.
 

 

c4m10 i think that you havent

January 11, 2013 - 4:35pm #13

c4m10 i think that you havent idea how vws authorization works. 95 percents of your code is by me. If you want create a post request you must set up createSignature function with all required parameters. For post request is necessary used $requestPath, $postType, $contentType, $content. Request path is /targers, post type is POST content type is application/json and content is your json encoded array cause signature is builded by your request type, time of request, content, md5 hash of your content and type of content. And after your script deliver your http request on server, server take all your request and build signature from nedded http headers by hash function and compare your hash from createSignature with hash generated on server. Next thing, its better make one  function with curl params for each request type getData for GET, postData for POST etc and getTargetList is function developed only for get all targets list from database. For creating new post is better make function createTarget and define code nedded for succesfull creation of target. 

Hi c4m10, as always, I

January 11, 2013 - 12:31am #12

Hi c4m10, as always, I recommend to carefully compare your implementation with the reference samples in Java;

pieterdekker might be able to share his (working) code also for the Post method (?)

Thanks for the code

January 10, 2013 - 8:56pm #11

Hi, i have a question. this code really works for me too and now i have the authentication working, but when i want to post data y got the authentication error again. what i`m doing wrong? im gonna write my code here. when i put this line curl_setopt($ch, CURLOPT_POST, true); the authentication error back. thanks again. waiting for an answer.

$result = getTargetList();

 
print_r($result);
 
 $contents = json_encode($arr);
 
function getTargetList(){
 
$credentials =  createSignature("/targets");
 
return  getData($credentials, "https://vws.vuforia.com/targets");
 
}
 
 
function getData($credentials, $target, $postType = "POST"){
 
$date = new DateTime("now", new DateTimeZone("GMT"));
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $target);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
 
curl_setopt($ch, CURLOPT_HEADER, true);
 
curl_setopt($ch, CURLOPT_VERBOSE, true);
 
curl_setopt($ch, CURLOPT_POST, true);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("POST /targets HTTP/1.1","Host: vws.vuforia.com","Authorization: VWS " .$credentials,"DATE: ".$date->format("D, d M Y H:i:s") . " GMT"));
 
$page = curl_exec($ch);
 
curl_close($ch);
return $page;
 
}
 
function createSignature($requestPath, $postType = "GET", $contentType = "", $content = ""){
 
$contentMD5 = md5($content);
 
$date = new DateTime("now", new DateTimeZone("GMT"));
 
$stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . " GMT\n" . $requestPath;
 
$signature =  hexToBase64(hash_hmac("sha1", $stringToSign,  "a5e1a1e56322b9bed1ac3c8eee4a34070c827981"));
 
$credentials =  "91e8b95f2bebda3fde5ba624bdfa0d2d2d5fdba4" . ":" . $signature;
 
return $credentials;
 
}
 
function hexToBase64($hex){
 
$return = "";
 
foreach(str_split($hex, 2) as $pair){
 
$return .= chr(hexdec($pair));
 
}
 
return base64_encode($return);
 
}

Thanks pieterdekker for

January 7, 2013 - 12:44am #10

Thanks pieterdekker for sharing this code snippet; I am sure it will be useful to many others in the forum.

Just as a side note (for future posts): it would be good if you could post these kind of topics in the "CloudRecognition" section of the Forum, as probably many Forum users will search for similar topics in that section.

https://developer.vuforia.com/forum/ar-technical-discussion/cloud-recognition

 

Thank you! I have now a

January 6, 2013 - 4:05am #9

Thank you! I have now a working connection. If someone else needs this, below the functions I use, based on chiwo's work:

 

$result = $this->getTargetList();
print_r($result);

 

private function getTargetList(){
$credentials = $this->createSignature("/targets");
return $this->getData($credentials, "https://vws.vuforia.com/targets");
}
 
private function getData($credentials, $target, $postType = "GET"){
$date = new DateTime("now", new DateTimeZone("GMT"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials,'DATE: '.$date->format("D, d M Y H:i:s") . ' GMT'));
$page = curl_exec($ch);
curl_close($ch);
return $page;
}
 
private function createSignature($requestPath, $postType = "GET", $contentType = "", $content = ""){
$contentMD5 = md5($content);
$date = new DateTime("now", new DateTimeZone("GMT"));
$stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . " GMT\n" . $requestPath;
$signature = $this->hexToBase64(hash_hmac('sha1', $stringToSign, $this->serverSecretKey));
$credentials = $this->serverAccessKey . ":" . $signature;
return $credentials;
}
 
private function hexToBase64($hex){
$return = '';
foreach(str_split($hex, 2) as $pair){
$return .= chr(hexdec($pair));
}
return base64_encode($return);
}

I m used own function,

January 5, 2013 - 6:00pm #8

I m used own function, where $hex is result of hash_hmac function

private function hexToBase64($hex){

 

    $word = "";
    while(strlen($hex)>0){
        $word .= chr(hexdec(substr($hex, 0, 2)));
        $hex = substr($hex, 2);
    }
    return base64_encode($word);
}

 

Good to know. The samples

January 5, 2013 - 5:53pm #7

Good to know. The samples have been updated to include the SignatureBuilder. Which PHP has function are you using to obtain a correct text string?

Log in or register to post comments