From c409b958b71bb5bd4b10faa6847c548a3e03cacc Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 3 Jun 2025 11:01:03 +0530 Subject: [PATCH] FEAT_BOOKSTACK_SSO --- app/Config/Routes.php | 2 +- .../RestAuthenticationController.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f11f6451..782e4293 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -536,7 +536,7 @@ $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrol // Ticketing System End's - +$routes->get("autobookstackLogin", "RestAuthenticationController::bookstackLoginToken"); //BDSReports $routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) { $routes->match( ['get', 'post'], 'irba_report','BDSReportController::irba_report'); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 77c6854c..c62b2f91 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -505,5 +505,28 @@ class RestAuthenticationController extends AdminController } + // TokenController.php + public function bookstackLoginToken() + { + // $user = session()->get('user'); + // $secret = getenv('BOOKSTACK_TOKEN_SECRET'); + $user = 'staff@staff.com'; + $secret = '5a8c1e9b18e6a94f724f6a6b36b6f26d9eec0e4a15e88b6e3e2d5efad23a8f4f'; + + $payload = [ + 'email' => $user, + 'name' => 'Hi', + 'exp' => time() + 60 // expires in 1 minute + ]; + + $token = base64_encode(json_encode($payload)); + $signature = hash_hmac('sha256', $token, $secret); + + $url = 'https://localhost/PHP828APPS/manual/bookstack/public/autologin?token=' . urlencode($token) . '&sig=' . $signature; + return redirect()->to($url); + } + + + } \ No newline at end of file