Difference between revisions of "Identification check from OpenFlyers for third party software"

Jump to: navigation, search
(Presentation)
(PHP code example)
Line 33: Line 33:
  
 
Here an example how to send a post request with php :
 
Here an example how to send a post request with php :
<php>function httpPostRequest($host, $path, $postData) {  
+
<php>// PHP 5.6 is required
  $result= "";  
+
function httpPostRequest($host, $path, $postData) {
 
+
    $result= "";
  $request = "POST $path HTTP/1.1\n".  
+
   
  "Host: $host\n".  
+
    $request = "POST $path HTTP/1.1\n".
  (isset($referer) ? "Referer: $referer\n" : "").  
+
    "Host: $host\n".
  "Content-type: Application/x-www-form-urlencoded\n".
+
    (isset($referer) ? "Referer: $referer\n" : "").
  "Content-length: ".strlen($postData)."\n".  
+
    "Content-type: Application/x-www-form-urlencoded\n".
  "Connection: close\n\n".  
+
    "Content-length: ".strlen($postData)."\n".
  $postData."\n";  
+
    "Connection: close\n\n".
 
+
    $postData."\n";
  // Some debug informations:
+
   
  // print("<pre>Request:\n".htmlentities($request)."</pre>");  
+
    // Some debug informations:
 
+
    print("<pre>Request:\n".htmlentities($request)."</pre>");
  if ($fp = fsockopen($host, 80, $errno, $errstr, 3))
+
   
  // for PHP release < 5.3.0, use the following syntax:
+
    if ($fp = fsockopen($host, 443, $errno, $errstr, 3)) {
  // if ($fp = fsockopen($host, 80, &$errno, &$errstr, 3))
+
        // Set cryptology method
    {
+
        // @link http://php.net/manual/en/function.stream-socket-enable-crypto.php
    if (fputs($fp, $request))  
+
        if (!defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
    {  
+
            die('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT IS REQUIRED');
      while(! feof($fp))  
+
        }
      {  
+
        $cryptoMethod = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
      $result.= fgets($fp, 128);  
+
        // Activate encryption while authenticating
      }  
+
        stream_socket_enable_crypto($fp, true, $cryptoMethod);
      fclose($fp);  
+
        if (fputs($fp, $request)) {
//     print($result);
+
            while(! feof($fp)) {
      return $result;  
+
                $result.= fgets($fp, 128);
    }  
+
            }
  }  
+
            // Deactivate encryption once authenticating done
 +
            stream_socket_enable_crypto($fp, false);
 +
            fclose($fp);
 +
            //print($result);
 +
            return $result;
 +
        }
 +
    }
 
}
 
}
  
//$postData='login=your-login&rawPassword='.md5('your-password'); // for OpenFlyers release 2 or higher
+
$postData   = 'login=jbond&rawPassword='.md5('007');
$postData='login=your-login&rawPassword=your-password';
+
$rawContent = httpPostRequest('openflyers.com','https://openflyers.com/plateform-name/checkIdent.php',$postData);
$rawContent = httpPostRequest('openflyers.com','http://openflyers.com/platform-name/checkIdent.php',$postData); [^]
+
  
 
list($header, $content) = explode("\r\n\r\n", $rawContent, 2);
 
list($header, $content) = explode("\r\n\r\n", $rawContent, 2);

Revision as of 09:48, 12 March 2018

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 :

// PHP 5.6 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("<pre>Request:\n".htmlentities($request)."</pre>");
 
    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

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.