From c09da27dea421ced9aae24996291a10b79293925 Mon Sep 17 00:00:00 2001 From: Alexander Gabriel Date: Mon, 10 Nov 2025 22:38:22 +0000 Subject: [PATCH] Logout --- config/filament-oauth2.php | 1 + routes/web.php | 5 ++--- src/FilamentOauth2Plugin.php | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config/filament-oauth2.php b/config/filament-oauth2.php index b3c04b5..89bd8b3 100644 --- a/config/filament-oauth2.php +++ b/config/filament-oauth2.php @@ -10,6 +10,7 @@ return [ 'urlAuthorize' => env("OAUTH2_URL_AUTHORIZE", env("OAUTH2_BASE_URL")."/auth"), 'urlAccessToken' => env("OAUTH2_URL_ACCESS_TOKEN", env("OAUTH2_BASE_URL")."/token"), 'urlResourceOwnerDetails' => env("OAUTH2_URL_RSOURCE_OWNER_DETAILS", env("OAUTH2_BASE_URL")."/userinfo"), + 'urlLogout' => env("OAUTH2_URL_LOGOUT", env("OAUTH2_BASE_URL")."/logout"), 'scopes' => env("OAUTH2_SCOPES", "profile email openid"), 'updateRoles' => env("OAUTH2_UPDATE_ROLES", false) diff --git a/routes/web.php b/routes/web.php index d79883e..635f75a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,12 +15,11 @@ Route::prefix($panel->getPath()) Route::name('filament-oauth2.') ->prefix('filament-oauth2') ->group(function () { + Route::post('handleLogout', [Oauth2Controller::class, 'handleLogout'])->name('handleLogout'); Route::get('redirectToOauth2Server', [Oauth2Controller::class, 'redirectToOauth2Server']) ->name('redirectToOauth2Server'); Route::get('handleCallback', [Oauth2Controller::class, 'handleCallback']) ->name('handleCallback'); }); - }); - - +}); diff --git a/src/FilamentOauth2Plugin.php b/src/FilamentOauth2Plugin.php index 606bdca..60ef2d7 100644 --- a/src/FilamentOauth2Plugin.php +++ b/src/FilamentOauth2Plugin.php @@ -4,6 +4,7 @@ namespace AlexanderGabriel\FilamentOauth2; use AlexanderGabriel\FilamentOauth2\Facades\FilamentOauth2; use Filament\Contracts\Plugin; +use Filament\Navigation\MenuItem; use Filament\Panel; class FilamentOauth2Plugin implements Plugin @@ -15,7 +16,15 @@ class FilamentOauth2Plugin implements Plugin public function register(Panel $panel): void { - $panel->login(FilamentOauth2::getLoginRouteAction()); + $panel + ->login(FilamentOauth2::getLoginRouteAction()) + ->userMenuItems([ + 'logout' => MenuItem::make()->url(function () { + $panel = filament()->getCurrentPanel(); + return '/'.$panel->getPath().'/'.$this->getId().'/handleLogout'; + }), + ]); + } public function boot(Panel $panel): void