Identification check from OpenFlyers for third party software

From OpenFlyers Documentation
Jump to navigation Jump to search

Presentation

Here is an presentation of how to check if an identification/password couple submitted by your own scripts is correct according to the OpenFlyers database.

The script returns a value which indicate if the connexion with the given login/password has succeeded and it states. An OpenFlyers cookie is also sent to manage a user session on your website, using the user's OpenFlyer's account.

How it works

If your OpenFlyers is located at http://openflyers.com/platform-name/ just post at http://openflyers.com/platform-name/checkIdent.php with login and rawPassword variables.

Warning: OpenFlyers release 2 or higher required a password hashed with MD5 (see the commented $postData line below in the PHP script).

Possible return values

The script display return an answer code which should be one of this value:

  • 0: OK
  • 1: OK but several profile availables. OpenFlyers select automatically the best profile.
  • 2: outdate but authorized
  • 3: outdate but authorized with outdate profile
  • 4: outdate subscription, unauthorized
  • 5: bad Ident, unauthorized
  • 6: Banned (ip or login), unauthorized
  • 7: no Ident -> ask one

We recommend you to consider 0-2 OK and 3-7 bad

Warning: you have to filter public access login (with no right) because for OF, it's a valid access !!!

JavaScript

If you are using your own authenticate form, use javascript function submit_pwd() located into \javascript\submitPwd.js

PHP code example

Please replace platform-name with your OpenFlyers platform's name, replace your-login with your OpenFlyers login and your-password with your OpenFlyers password.


Here an example how to send a post request with php : <syntaxhighlight lang="php">// PHP 5.6 is required // OpenSSL 1.0.1 is required function httpPostRequest($host, $path, $postData) {

   $result= "";
   
   $request = "POST $path HTTP/1.1\n".
   "Host: $host\n".
   (isset($referer) ? "Referer: $referer\n" : "").
   "Content-type: Application/x-www-form-urlencoded\n".
   "Content-length: ".strlen($postData)."\n".
   "Connection: close\n\n".
   $postData."\n";
   
   // Some debug informations:

print("

Request:\n".htmlentities($request)."

");

   if ($fp = fsockopen($host, 443, $errno, $errstr, 3)) {
       // Set cryptology method
       // @link http://php.net/manual/en/function.stream-socket-enable-crypto.php
       if (!defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
           die('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT IS REQUIRED');
       }
       $cryptoMethod = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
       // Activate encryption while authenticating
       stream_socket_enable_crypto($fp, true, $cryptoMethod);
       if (fputs($fp, $request)) {
           while(! feof($fp)) {
               $result.= fgets($fp, 128);
           }
           // Deactivate encryption once authenticating done
           stream_socket_enable_crypto($fp, false);
           fclose($fp);
           //print($result);
           return $result;
       }
   }

}

$postData = 'login=jbond&rawPassword='.md5('007'); $rawContent = httpPostRequest('openflyers.com','https://openflyers.com/plateform-name/checkIdent.php',$postData);

list($header, $content) = explode("\r\n\r\n", $rawContent, 2); list($byteQty, $realContent, $dummy) = explode("\r\n", $content, 3);

// the answer is in $realContent</php>

Joomla authentification plugin

If you have a Joomla website and you want that Openflyers users could connect to your Joomla restricted access zone, you may add this plugin to have only one account database: Openflyers one. You don't need to update Joomla user database, this plugin ask directly Openflyers thanks to CheckIdent.php script.