This is an automated email from the ASF dual-hosted git repository.
yasith pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airavata-portals.git
The following commit(s) were added to refs/heads/main by this push:
new 788a6e41d fix login flow in php gateway for php 8.1 and laravel 8
788a6e41d is described below
commit 788a6e41d2cf830d967ed001844aee5dcc4b42dd
Author: yasithdev <[email protected]>
AuthorDate: Fri Jul 4 06:53:01 2025 -0500
fix login flow in php gateway for php 8.1 and laravel 8
---
.../app/Http/Controllers/AccountController.php | 4 +-
.../app/libraries/Keycloak/API/RoleMapper.php | 14 +++---
.../app/libraries/Keycloak/KeycloakUtil.php | 5 ++-
airavata-php-gateway/config/logging.php | 52 ++++++++++++++++++++++
.../resources/views/partials/login-form.blade.php | 2 +-
5 files changed, 67 insertions(+), 10 deletions(-)
diff --git a/airavata-php-gateway/app/Http/Controllers/AccountController.php
b/airavata-php-gateway/app/Http/Controllers/AccountController.php
index 04d6f4255..0edb7cd6f 100644
--- a/airavata-php-gateway/app/Http/Controllers/AccountController.php
+++ b/airavata-php-gateway/app/Http/Controllers/AccountController.php
@@ -140,9 +140,9 @@ class AccountController extends BaseController
public function loginSubmit()
{
+ Log::debug("loginSubmit", array($_POST));
if (CommonUtilities::form_submitted()) {
- $username = strtolower(Input::get("username"));
-
+ $username = strtolower($_POST['username']);
$password = $_POST['password'];
$response = Keycloak::authenticate($username, $password);
if(!isset($response->access_token)){
diff --git a/airavata-php-gateway/app/libraries/Keycloak/API/RoleMapper.php
b/airavata-php-gateway/app/libraries/Keycloak/API/RoleMapper.php
index 7e724bae1..88d63a34c 100644
--- a/airavata-php-gateway/app/libraries/Keycloak/API/RoleMapper.php
+++ b/airavata-php-gateway/app/libraries/Keycloak/API/RoleMapper.php
@@ -38,14 +38,18 @@ class RoleMapper extends BaseKeycloakAPIEndpoint {
));
$response = curl_exec($r);
+ $httpCode = curl_getinfo($r, CURLINFO_HTTP_CODE);
if ($response == false) {
- Log::error("Failed to retrieve realm role mappings for user");
+ Log::error("Failed to retrieve realm role mappings for user! GET "
. $url . " " . curl_error($r));
die("curl_exec() failed. Error: " . curl_error($r));
+ } elseif ($httpCode != 200) {
+ Log::error("Failed to retrieve realm role mappings for user! GET "
. $url . " " . $httpCode);
+ die("curl_exec() failed. Error: " . $url . " " . $httpCode);
+ } else {
+ $result = json_decode($response);
+ Log::debug("getRealmRoleMappingsForUser result: " .
json_encode($result));
+ return $result;
}
- $result = json_decode($response);
- Log::debug("getRealmRoleMappingsForUser result: " .
json_encode($result));
- return [];
- // return $result;
}
/**
diff --git a/airavata-php-gateway/app/libraries/Keycloak/KeycloakUtil.php
b/airavata-php-gateway/app/libraries/Keycloak/KeycloakUtil.php
index e79a20d58..74278c6c0 100644
--- a/airavata-php-gateway/app/libraries/Keycloak/KeycloakUtil.php
+++ b/airavata-php-gateway/app/libraries/Keycloak/KeycloakUtil.php
@@ -12,7 +12,8 @@ class KeycloakUtil {
// curl -d client_id=admin-cli -d username=username \
// -d "password=password" -d grant_type=password
https://149.165.156.62:8443/auth/realms/master/protocol/openid-connect/token
- $r = curl_init($base_endpoint_url . '/realms/' . rawurlencode($realm)
. '/protocol/openid-connect/token');
+ $url = $base_endpoint_url . '/realms/' . rawurlencode($realm) .
'/protocol/openid-connect/token';
+ $r = curl_init($url);
curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($r, CURLOPT_ENCODING, 1);
curl_setopt($r, CURLOPT_SSL_VERIFYPEER, $verify_peer);
@@ -29,7 +30,7 @@ class KeycloakUtil {
$response = curl_exec($r);
if ($response == false) {
- Log::error("Failed to retrieve API Access Token");
+ Log::error("Failed to retrieve API Access Token! " . $url . " " .
curl_error($r));
die("curl_exec() failed. Error: " . curl_error($r));
}
diff --git a/airavata-php-gateway/config/logging.php
b/airavata-php-gateway/config/logging.php
new file mode 100644
index 000000000..f5626baeb
--- /dev/null
+++ b/airavata-php-gateway/config/logging.php
@@ -0,0 +1,52 @@
+<?php
+
+return [
+ 'default' => 'stack',
+
+ 'channels' => [
+ 'stack' => [
+ 'driver' => 'stack',
+ 'channels' => ['single'],
+ 'ignore_exceptions' => false,
+ ],
+
+ 'single' => [
+ 'driver' => 'single',
+ 'path' => storage_path('logs/laravel.log'),
+ 'level' => 'debug',
+ ],
+
+ 'daily' => [
+ 'driver' => 'daily',
+ 'path' => storage_path('logs/laravel.log'),
+ 'level' => 'debug',
+ 'days' => 14,
+ ],
+
+ 'slack' => [
+ 'driver' => 'slack',
+ 'url' => null, // Set your Slack webhook URL if needed
+ 'username' => 'Laravel Log',
+ 'emoji' => ':boom:',
+ 'level' => 'critical',
+ ],
+
+ 'stderr' => [
+ 'driver' => 'monolog',
+ 'handler' => StreamHandler::class,
+ 'with' => [
+ 'stream' => 'php://stderr',
+ ],
+ ],
+
+ 'syslog' => [
+ 'driver' => 'syslog',
+ 'level' => 'debug',
+ ],
+
+ 'errorlog' => [
+ 'driver' => 'errorlog',
+ 'level' => 'debug',
+ ],
+ ],
+];
\ No newline at end of file
diff --git a/airavata-php-gateway/resources/views/partials/login-form.blade.php
b/airavata-php-gateway/resources/views/partials/login-form.blade.php
index 5c45f4dbd..5bccb0608 100644
--- a/airavata-php-gateway/resources/views/partials/login-form.blade.php
+++ b/airavata-php-gateway/resources/views/partials/login-form.blade.php
@@ -28,7 +28,7 @@
{{{ Session::get("account-created-success") }}}
</div>
@endif
-
+ @csrf
<div class="form-group">
<label class="sr-only" for="username">Username</label>
<input type="text" class="form-control" name="username"
placeholder="Username" autofocus required>