Browse Source

add ServiceSingleSignOn test function

andre 5 years ago
parent
commit
d2aa7cdc58
1 changed files with 50 additions and 0 deletions
  1. 50 0
      zimbraSingle.php

+ 50 - 0
zimbraSingle.php

@@ -718,3 +718,53 @@ function zimbraSingle_ConfigOptions($params) {
     );
     return $configOptions;
 }
+
+/**
+ * Perform single sign-on for a given instance of a product/service.
+ *
+ * Called when single sign-on is requested for an instance of a product/service.
+ *
+ * When successful, returns an URL to which the user should be redirected.
+ *
+ * @param array $params common module parameters
+ *
+ * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
+ *
+ * @return array
+ */
+function zimbraSingle_ServiceSingleSignOn($params) {
+    $api = new Zm_Auth($params['serverhostname'], $params['serverusername'], $params['serverpassword'], 'admin');
+    $login = $api->login();
+    if(is_a($login, 'Exception')) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $params,
+            'Error: cannot login to ' . $params['serverhostname'],
+            $login->getMessage()
+        );
+        return $login->getMessage();
+    }
+    $apiAccountManager = new Zm_Account($api);
+    $accountOptions = $apiAccountManager->getAccountOptions($params['username']);
+    if(is_a($accountOptions, 'Exception')) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $params,
+            'Error : could not find quota for ' . $params['username'],
+            $accountOptions->getMessage()
+        );
+    }
+    logModuleCall(
+        'zimbrasingle',
+        __FUNCTION__,
+        $params,
+        'Debug',
+        $accountOptions
+    );
+    return array(
+        'success' => true,
+        'redirectTo' => 'https://testserver.test.local/',
+    );
+}