Răsfoiți Sursa

debug authtoken call

andre 5 ani în urmă
părinte
comite
56446d8cd2
1 a modificat fișierele cu 46 adăugiri și 0 ștergeri
  1. 46 0
      api/Zm/Auth.php

+ 46 - 0
api/Zm/Auth.php

@@ -276,7 +276,53 @@ class Zm_Auth
 				}
 			}
 		}
+		return $result;
+	}
+
+	/**
+	 * preauth
+	 *
+	 * Use this method to login to a Zimbra server after you create an instance of this class
+	 *
+	 * Login parameters must be specified when calling the constructor
+	 */
+	function preauth($key)
+	{
+		$result = null;
 
+		$n = 0;
+		while (true)
+		{
+			try
+			{
+				$this->setSoapHeader();
+
+				$result = $this->client->__soapCall("AuthRequest", $this->params, null, $this->getSoapHeader());
+				// $result = $this->client->__getLastResponse();
+				// print_var($result);
+				// Save the soapHeader with token
+				$this->setSoapHeader($result['authToken']);
+				break;
+			}
+			catch (SoapFault $exception)
+			{
+				// if $retryAttempts>0 retry after a random time using exponential backoff
+				// for user logins retries just once
+				$n++;
+				if ($this->retryAttempts > 0 &&
+					$n <= $this->retryAttempts && ($this->context == "admin" || $n == 1) ) {
+					$minT = 1+$n*1000000/10;
+					$maxT = pow(2, $n-1)*1000000;
+					$waitT = rand($minT, $maxT);
+					// wait times are shorter on login
+					$waitT = $waitT/5;
+					usleep($waitT);
+				} else {
+					$result = $exception;
+					break;
+				}
+			}
+		}
 		return $result;
 	}
 }