Przeglądaj źródła

fix: Added verbose debug information

Edgard 3 lat temu
rodzic
commit
3ba5059245
3 zmienionych plików z 33 dodań i 4 usunięć
  1. 2 1
      front/callback.php
  2. 29 1
      inc/provider.class.php
  3. 2 2
      inc/toolbox.class.php

+ 2 - 1
front/callback.php

@@ -30,11 +30,12 @@ $signon_provider->checkAuthorization();
 $test = PluginSinglesignonToolbox::getCallbackParameters('test');
 
 if ($test) {
+   $signon_provider->debug = true;
    Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
    echo '<div class="left spaced">';
    echo '<pre>';
    echo "### BEGIN ###\n";
-   print_r($signon_provider->getResourceOwner());
+   $signon_provider->getResourceOwner();
    echo "### END ###";
    echo '</pre>';
    Html::nullFooter();

+ 29 - 1
inc/provider.class.php

@@ -29,6 +29,8 @@ class PluginSinglesignonProvider extends CommonDBTM {
     */
    protected $_resource_owner = null;
 
+   public $debug = false;
+
    public static function canCreate() {
       return static::canUpdate();
    }
@@ -85,7 +87,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
       echo "<tr class='tab_bg_1'>";
       echo "<td>" . __('Name') . "</td>";
       echo "<td>";
-      Html::autocompletionTextField($this, "name");
+      echo Html::input("name", ['value' => $this->fields["name"], 'class' => 'form-control']);
       echo "</td>";
       echo "<td>" . __('Comments') . "</td>";
       echo "<td>";
@@ -970,13 +972,23 @@ class PluginSinglesignonProvider extends CommonDBTM {
          CURLOPT_SSL_VERIFYPEER => false,
       ]);
 
+      if ($this->debug) {
+         print_r("\ngetAccessToken:\n");
+      }
+
       try {
          $data = json_decode($content, true);
+         if ($this->debug) {
+            print_r($data);
+         }
          if (!isset($data['access_token'])) {
             return false;
          }
          $this->_token = $data['access_token'];
       } catch (\Exception $ex) {
+         if ($this->debug) {
+            print_r($content);
+         }
          return false;
       }
 
@@ -1012,14 +1024,27 @@ class PluginSinglesignonProvider extends CommonDBTM {
          CURLOPT_SSL_VERIFYPEER => false,
       ]);
 
+      if ($this->debug) {
+         print_r("\ngetResourceOwner:\n");
+      }
+
       try {
          $data = json_decode($content, true);
+         if ($this->debug) {
+            print_r($data);
+         }
          $this->_resource_owner = $data;
       } catch (\Exception $ex) {
+         if ($this->debug) {
+            print_r($content);
+         }
          return false;
       }
 
       if ($this->getClientType() === "linkedin") {
+         if ($this->debug) {
+            print_r("\nlinkedin:\n");
+         }
          $email_url = "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))";
          $content = Toolbox::callCurl($email_url, [
             CURLOPT_HTTPHEADER => $headers,
@@ -1029,6 +1054,9 @@ class PluginSinglesignonProvider extends CommonDBTM {
 
          try {
             $data = json_decode($content, true);
+            if ($this->debug) {
+               print_r($content);
+            }
 
             $this->_resource_owner['email-address'] = $data['elements'][0]['handle~']['emailAddress'];
          } catch (\Exception $ex) {

+ 2 - 2
inc/toolbox.class.php

@@ -9,12 +9,12 @@ class PluginSinglesignonToolbox {
     * @param array $query
     * @return string
     */
-   public static function getCallbackUrl($row, $query = []) {
+   public static function getCallbackUrl($id, $query = []) {
       global $CFG_GLPI;
 
       $url = $CFG_GLPI['root_doc'] . '/plugins/singlesignon/front/callback.php';
 
-      $url .= "/provider/".$row['id'];
+      $url .= "/provider/".$id;
 
       if (!empty($query)) {
          $_SESSION['redirect'] = $query['redirect'];