/**
  * Authenticate
  *
  * @param void
  * @return null
  */
 function authenticate()
 {
     $provider_class = AUTH_PROVIDER;
     use_auth_provider($provider_class);
     if (!class_exists($provider_class)) {
         use_error('ClassNotImplementedError');
         return new ClassNotImplementedError($provider_class);
     }
     // if
     $provider = new $provider_class();
     if (!instance_of($provider, 'AuthenticationProvider')) {
         return new InvalidInstanceError('provider', $provider, 'AuthenticationProvider');
     }
     // if
     $manager =& Authentication::instance($provider, false);
     $token = false;
     if (FORCE_QUERY_STRING) {
         if (ANGIE_QUERY_STRING) {
             $query_string_aprams = parse_string(ANGIE_QUERY_STRING);
             if (isset($query_string_aprams['token'])) {
                 $token = $query_string_aprams['token'];
             }
             // if
         }
         // if
     } else {
         $token = isset($_GET['token']) ? $_GET['token'] : false;
     }
     // if
     // Handle token based authentication
     if ($token !== false) {
         // Die if disabled or read-only with POST parameters
         if (API_STATUS == API_DISABLED || API_STATUS == API_READ_ONLY && count($_POST) > 0) {
             header('HTTP/1.1 403 Forbidden');
             print "<h1>HTTP/1.1 403 Forbidden</h1>\n";
             if (API_STATUS == API_DISABLED) {
                 print '<p>API is disabled</p>';
             } else {
                 print '<p>API is read-only</p>';
             }
             // if
             die;
         }
         // if
         // Get token and auth_id (old and new API key formats are supported)
         if (strpos($token, '-') !== false) {
             list($auth_id, $token) = explode('-', $token);
         } else {
             $auth_id = array_var($_GET, 'auth_id');
         }
         // if
         $user = null;
         if ($auth_id) {
             $user = Users::findById($auth_id);
         }
         // if
         if (instance_of($user, 'User') && $user->getToken() == $token) {
             $manager->provider->logUserIn($user, array('silent' => true));
             return true;
         } else {
             header('HTTP/1.1 403 Forbidden');
             print '<h1>HTTP/1.1 403 Forbidden</h1>';
             die;
         }
         // if
     }
     // if
     $manager->provider->initialize();
     return true;
 }
 /**
  * Initialize authentication
  * 
  * First we get authentication provider and then we create authentication 
  * manager instance...
  *
  * @param void
  * @return null
  */
 function authenticate()
 {
     $provider_class = AUTH_PROVIDER;
     use_auth_provider($provider_class);
     if (!class_exists($provider_class)) {
         use_error('ClassNotImplementedError');
         return new ClassNotImplementedError($provider_class);
     }
     // if
     $provider = new $provider_class();
     if (!instance_of($provider, 'AuthenticationProvider')) {
         return new InvalidInstanceError('provider', $provide, 'AuthenticationProvider');
     }
     // if
     $manager =& Authentication::instance($provider);
 }