1. Go to this page and download the library: Download rizalrepo/sso-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
class Authenticate extends Middleware
{
private function getConfig($configName)
{
switch ($configName) {
case 'serverUrl':
return "http://127.0.0.1:8000/login";
default:
return null;
}
}
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : $this->getConfig('serverUrl');
}
}
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
class Authenticate extends Middleware
{
private function getConfig($configName)
{
switch ($configName) {
case 'serverUrl':
return "http://127.0.0.1:8000/login";
default:
return null;
}
}
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : $this->getConfig('serverUrl');
}
}
$username = $data->username; // this code add before delete()
$ssoController = new \App\Http\Controllers\SSO\SSOController();
$ssoController->deleteUserOnServer($username);
php artisan make:middleware VerifyApiToken
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class VerifyApiToken
{
public function handle($request, Closure $next)
{
$token = $request->bearerToken();
if (!$token) {
Log::warning('No bearer token provided and no access token in session');
return response()->json(['error' => 'Unauthorized'], 401);
}
try {
$serverUrl = Config::get('sso.serverUrl');
$response = Http::timeout(5)->withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $token,
])->get($serverUrl . '/api/verify-token');
if ($response->successful()) {
$request->merge(['sso_user' => $response->json()]);
return $next($request);
}
return response()->json(['error' => 'Invalid token'], 401);
} catch (\Exception $e) {
return response()->json(['error' => 'Error verifying token'], 500);
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.