Page 1 of 1

CDS Login prolbem

PostPosted: Mon May 04, 2015 2:02 pm
by GhostMaster75
Hi,
I'm trying to use the API with PHP but are still at login.
He keeps telling me that my password is incorrect but does not with response 552.

this is my code:
  Code:
$data = date("D, d M Y H:i:s e");
$pass = "mypass";
$string = hash_hmac("sha1", $data, $pass);
$password = base64_encode($string);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:23424/cds/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml | application/json", "Date: " . $data, "X-Serviio-Date: " . $data,  "Authorization: Serviio " . $password));
$response = curl_exec($ch);
curl_close($ch);

var_dump($response);


what's wrong???

thank you

Re: CDS Login prolbem

PostPosted: Tue May 05, 2015 4:35 pm
by zip
the Accept header must be either application/xml or application/json

Re: CDS Login prolbem

PostPosted: Wed Mar 29, 2017 2:45 pm
by wasant
Hi ,
I found this problem as well --> '{"errorCode":552}'

my code below:

$data = gmdate('D, d M Y H:i:s T');
$pass = "1234"; // This password I set with GUI Console in Remote menu.
$string = hash_hmac("sha1", $data, $pass);
$password = base64_encode($string);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://localhost:23424/cds/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Date: ".$data,
"X-Serviio-Date:".$data,
"Authorization:Serviio ".$password
));

what's wrong?

thank you

Re: CDS Login prolbem

PostPosted: Wed Mar 29, 2017 6:56 pm
by zip
does this code produce the example value specified in the API docs?

Re: CDS Login prolbem

PostPosted: Thu Mar 30, 2017 2:14 am
by wasant
zip wrote:does this code produce the example value specified in the API docs?


Yes,I followed the example in the API documentation.
I'm a beginner. I'm not sure in the steps below.

Calculating the Signature
Calculating the value to include in the request is a simple procedure.
1.Calculate an RFC 2104-compliant HMAC-SHA1 hash, using the string (see 4.3.2) and the user's password as the key.
2.Convert the resulting value to base64.
3.The result is the signature you include in the request.

my code below , I'm doing it right?

$data = gmdate('D, d M Y H:i:s T');
$pass = "1234"; // This password I set with GUI Console in Remote menu.
$string = hash_hmac("sha1", $data, $pass);
$password = base64_encode($string);


Do you have any suggestions or samples for me?

Thanks in advance for your help.

Re: CDS Login prolbem

PostPosted: Thu Mar 30, 2017 8:04 am
by zip
it looks ok to me. Do you get the right value when you use the date and password defined in the API ocs as an example? (search for "The following table shows a string, a fake Secret Access Key, and what the resulting base64 encoded signature would be.")

Re: CDS Login prolbem

PostPosted: Mon Apr 08, 2019 11:51 am
by y3ti
This is the code i use to Generate the Auth Token to then be able to pass through the API for the rest of the functions.

replace $server with your Server IP (eg: 192.168.x.x)
replace $pass with the password from your Serviio

  Code:
   $data = gmdate('D, d M Y H:i:s T');
   $auth_signature = base64_encode(hash_hmac("sha1", $data, $pass, true));
   
   $ch = curl_init();
   curl_setopt($ch,CURLOPT_VERBOSE, true);
   curl_setopt($ch,CURLOPT_HEADER, false);
   curl_setopt($ch,CURLOPT_URL, "http://" . $server . "/cds/login");
   curl_setopt($ch,CURLOPT_HTTPHEADER, array(
      "Content-Type: application/json",
      "Accept: application/json",
      "Date: " . $data,
      "X-Serviio-Date: " . $data,
      "Authorization: Serviio " . $auth_signature
   ));
   curl_setopt($ch,CURLOPT_POST, true);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);
   curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

   $output = curl_exec($ch);
   $info = curl_getinfo($ch);
   curl_close($ch);   

   $json = json_decode($output, true);
   
   @$authToken = $json['parameter'][0];


Hope this helps