From 0e06bf6c97e76a42fa6dec88015e41025fd656d8 Mon Sep 17 00:00:00 2001 From: "Angus B. Grieve-Smith" Date: Mon, 27 Apr 2020 17:00:45 -0400 Subject: [PATCH] Line breaks and diagnostic logs --- oauth/LDAP/LDAP.php | 6 ++++-- oauth/resource.php | 14 ++++++++++++-- oauth/token.php | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/oauth/LDAP/LDAP.php b/oauth/LDAP/LDAP.php index 5b050c2..2175fc7 100755 --- a/oauth/LDAP/LDAP.php +++ b/oauth/LDAP/LDAP.php @@ -225,7 +225,7 @@ class LDAP implements LDAPInterface throw new Exception('An error has occured during ldap_first_entry execution. Please check parameter of LDAP/getData.'); } - error_log("LDAP \$data = " . json_encode($data)); + error_log("LDAP \$data = " . var_dump($data)); $mail = ldap_get_values($this->ldap_server, $data, "mail"); if (!$mail) @@ -239,7 +239,9 @@ class LDAP implements LDAPInterface throw new Exception('An error has occured during ldap_get_values execution (complete name). Please check parameter of LDAP/getData.'); } - return array("mail" => $mail[0], "cn" => $cn[0]); + $return_data = array("mail" => $mail[0], "cn" => $cn[0]); + error_log("LDAP \$return_data = " . json_encode($return_data)); + return $return_data; } /* diff --git a/oauth/resource.php b/oauth/resource.php index 3ebfc1d..b083bb8 100755 --- a/oauth/resource.php +++ b/oauth/resource.php @@ -34,8 +34,17 @@ try { $data = $ldap->getDataForMattermost($ldap_base_dn,$ldap_filter,$ldap_bind_dn,$ldap_bind_pass,$ldap_search_attribute,$user); - // Here is the patch for Mattermost 4.4 and older. Gitlab has changed the JSON output of oauth service. Many data are not used by Mattermost, but there is a stack error if we delete them. That's the reason why date and many parameters are null or empty. - error_log("resource.php \$data = " . json_encode($data); + /* Here is the patch for Mattermost 4.4 and older. Gitlab has changed + the JSON output of oauth service. Many data are not used by + Mattermost, but there is a stack error if we delete them. That's the + reason why date and many parameters are null or empty. + */ + if ($data) { + error_log("resource.php \$data = " . json_encode($data)); + } else { + error_log("$data is null"); + } + $resp = array( "id" => $assoc_id, "name" => $data['cn'], @@ -70,6 +79,7 @@ try "external" => false, "shared_runners_minutes_limit" => null ); + error_log("\$resp = " . json_encode($resp)); // Below is the old version, still consistent with Mattermost before version 4.4 // $resp = array("name" => $data['cn'],"username" => $user,"id" => $assoc_id,"state" => "active","email" => $data['mail']); diff --git a/oauth/token.php b/oauth/token.php index a15973c..fc38279 100644 --- a/oauth/token.php +++ b/oauth/token.php @@ -9,6 +9,8 @@ require_once __DIR__.'/server.php'; // Handle a request for an OAuth2.0 Access Token and send the response to the client error_log("token.php \$_POST = " . json_encode($_POST)); +// The Mattermost server seems to be returning bare http urls, even though there is no http url in the config.json + if (substr($_POST["redirect_uri"],0,5) == "http:") { $_POST["redirect_uri"] = "https" . substr($_POST["redirect_uri"],4); }