Forum General Basic Authentication using a shared key

Discussion and help relating to the PlayerIO JavaScript SDK

Basic Authentication using a shared key

Postby Darma » September 12th, 2017, 12:22 am

Hello.

Does the javascript library support the "auth" param on secure basic authentication?

This is the code:

Code: Select all
PlayerIO.authenticate(gameID, connectionID, { auth: data.hash, userId: username }, null, function (client) {

}, function (error)   {
   
});


I'm getting the hash from the server (using PHP) for the given username. No issues getting the hash, but still getting the "Basic Authentication: The given 'auth' string was invalid" error :( .

I have 2 clients (using the same way to get the hash), Unity3d and HTML5, and only the last one is getting the error.

What am i doing wrong? Please help
Darma
 
Posts: 5
Joined: September 21st, 2016, 4:39 am

Re: Basic Authentication using a shared key

Postby Henrik » September 13th, 2017, 6:40 am

There's nothing special in the client libraries for this, all parameters are just passed to the webservice as-is.

Have you tried passing in a userid and auth that was calculated on a different platform? My best guess would be that something went wrong when you calculated the auth string in javascript?
Henrik
.IO
 
Posts: 1822
Joined: January 4th, 2010, 1:53 pm

Re: Basic Authentication using a shared key

Postby Darma » September 13th, 2017, 8:36 am

Hello @Henrik, thanks for the answer.

I am using exactly the same file on server to generate the hash on both platforms (Unity and Web browser).

Code: Select all
<?php
      $userId = $_POST['userId'];
      
      $sharedHash = "my_shared_key";
      
      $unix_time = time();
      $hash = hash_hmac("sha256", $unix_time . ":" . $userId, $sharedHash);
      
      $result = "{";
      $result .= '"hash": "' . $unix_time . ':' . $hash . '"';
      $result .= "}";
         
      echo $result;
?>


I'm so confused. The only way i got connected to the server on a Web browser is if useriId = "" (empty). If userId is anything different than that, i get the hash error.
Darma
 
Posts: 5
Joined: September 21st, 2016, 4:39 am


Return to General



cron