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

Jump to: navigation, search
(Created page with "__TOC__ =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 databa...")
 
(PHP code example)
 
(5 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
=Presentation=
 
=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.
 
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=
 
=How it works=
Line 31: 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= "";  
+
// OpenSSL 1.0.1 is required
 
+
function httpPostRequest($host, $path, $postData) {
  $request = "POST $path HTTP/1.1\n".  
+
    $result= "";
  "Host: $host\n".  
+
   
  (isset($referer) ? "Referer: $referer\n" : "").  
+
    $request = "POST $path HTTP/1.1\n".
  "Content-type: Application/x-www-form-urlencoded\n".
+
    "Host: $host\n".
  "Content-length: ".strlen($postData)."\n".  
+
    (isset($referer) ? "Referer: $referer\n" : "").
  "Connection: close\n\n".  
+
    "Content-type: Application/x-www-form-urlencoded\n".
  $postData."\n";  
+
    "Content-length: ".strlen($postData)."\n".
 
+
    "Connection: close\n\n".
  // Some debug informations:
+
    $postData."\n";
  // print("<pre>Request:\n".htmlentities($request)."</pre>");  
+
   
 
+
    // Some debug informations:
  if ($fp = fsockopen($host, 80, $errno, $errstr, 3))
+
    print("<pre>Request:\n".htmlentities($request)."</pre>");
  // for PHP release < 5.3.0, use the following syntax:
+
   
  // if ($fp = fsockopen($host, 80, &$errno, &$errstr, 3))
+
    if ($fp = fsockopen($host, 443, $errno, $errstr, 3)) {
    {
+
        // Set cryptology method
    if (fputs($fp, $request))  
+
        // @link http://php.net/manual/en/function.stream-socket-enable-crypto.php
    {  
+
        if (!defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
      while(! feof($fp))  
+
            die('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT IS REQUIRED');
      {  
+
        }
      $result.= fgets($fp, 128);  
+
        $cryptoMethod = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
      }  
+
        // Activate encryption while authenticating
      fclose($fp);  
+
        stream_socket_enable_crypto($fp, true, $cryptoMethod);
//     print($result);
+
        if (fputs($fp, $request)) {
      return $result;  
+
            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=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);
Line 74: Line 82:
 
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.
 
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.
 
You don't need to update Joomla user database, this plugin ask directly Openflyers thanks to CheckIdent.php script.
There are two files depending on your Joomla version:
 
 
*[[Media:Openflyers.zip|Joomla plugin for OpenFlyers]]
 
  
<php>#File two</php>
+
*[http://wiki.openflyers.org/wiki/images/0/00/Openflyers.zip Joomla plugin for OpenFlyers]

Latest revision as of 13:46, 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
// 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("<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.