Default Logout Bevahior

As there is no way to override default login, i couldnt implement this government socialite provider. This is really sad. Here is my code
public function logout(Request $request)
{
$id_token = session('efaas_id_token');

$request->session()->invalidate();

$request->session()->regenerateToken();

Auth::logout();

if ($id_token) {
$post_logout_redirect_url = 'https://fwd.host/http://students-parents-portal.test';

return Socialite::driver('efaas')->logOut($id_token, $post_logout_redirect_url);
}

return redirect('/');
}

//and here is the route
Route::post('/logout', [LogoutController::class, 'logout'])->name('filament.admin.auth.logout');
public function logout(Request $request)
{
$id_token = session('efaas_id_token');

$request->session()->invalidate();

$request->session()->regenerateToken();

Auth::logout();

if ($id_token) {
$post_logout_redirect_url = 'https://fwd.host/http://students-parents-portal.test';

return Socialite::driver('efaas')->logOut($id_token, $post_logout_redirect_url);
}

return redirect('/');
}

//and here is the route
Route::post('/logout', [LogoutController::class, 'logout'])->name('filament.admin.auth.logout');
15 Replies
Adel
Adel2w ago
add admin at the beginning of your route Route::post('/admin/logout', [LogoutController::class, 'logout'])->name('filament.admin.auth.logout');
shaan
shaanOP2w ago
that method is keep loginout to this url https://developer.gov.mv/efaas
Efaas - Your key to a digital Maldives
eFaas is the Maldives' National Digital Identity, enabling you to identify yourself in-person and online, unlocking a world of digital possibilities.
LeandroFerreira
Could you create a minimal repo on github to reproduce the issue?
Dennis Koch
Dennis Koch2w ago
@shaan you can create your own LogoutResponse and bind this via a service provider: $this->app->bind(LogoutResponse::class, YourLogoutResponse::class);
shaan
shaanOP2w ago
Nope, It doesnt work, when i tried to dd the id_token, it gets null. However, in the above logout controller, it does work
shaan
shaanOP2w ago
now the issue is it doesnt redirect to tjat url, it redirects to this url https://developer.gov.mv/efaas
Efaas - Your key to a digital Maldives
eFaas is the Maldives' National Digital Identity, enabling you to identify yourself in-person and online, unlocking a world of digital possibilities.
Dennis Koch
Dennis Koch2w ago
Can't check if you don't provide any code for that. Sounds like that's related to the Socialite driver.
shaan
shaanOP2w ago
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;
use Auth;
use Laravel\Socialite\Facades\Socialite;

class EfaasAuthController extends Controller
{
public function callback()
{
/* @var User $efaas_user */
$efaas_user = Socialite::driver('efaas')->stateless()->user();
// dd($efaas_user);
$gov_id = $efaas_user->attributes['idnumber'] ?? null;
$user = User::where('government_id', $gov_id)->first();

if ($user) {
$id_token = $efaas_user->id_token;
$sid = $efaas_user->sid;

session()->put('efaas_id_token', $id_token);
session()->put('efaas_sid', $sid);

Auth::login($user);

return match (true) {
$user->hasRole('admin') => redirect()->intended('/admin'),
$user->hasRole('teacher') => redirect()->intended('/admin'),
$user->hasRole('student') => redirect()->intended('/student'),
$user->hasRole('parent') => redirect()->intended('/parent'),
default => redirect()->intended('/'),
};
}

if (! $user) {
return redirect()->route('filament.admin.auth.login')
->withErrors(['government_id' => 'No account found with this Government ID.']);
}

return redirect('/')->withErrors(['errors']);
}
}
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;
use Auth;
use Laravel\Socialite\Facades\Socialite;

class EfaasAuthController extends Controller
{
public function callback()
{
/* @var User $efaas_user */
$efaas_user = Socialite::driver('efaas')->stateless()->user();
// dd($efaas_user);
$gov_id = $efaas_user->attributes['idnumber'] ?? null;
$user = User::where('government_id', $gov_id)->first();

if ($user) {
$id_token = $efaas_user->id_token;
$sid = $efaas_user->sid;

session()->put('efaas_id_token', $id_token);
session()->put('efaas_sid', $sid);

Auth::login($user);

return match (true) {
$user->hasRole('admin') => redirect()->intended('/admin'),
$user->hasRole('teacher') => redirect()->intended('/admin'),
$user->hasRole('student') => redirect()->intended('/student'),
$user->hasRole('parent') => redirect()->intended('/parent'),
default => redirect()->intended('/'),
};
}

if (! $user) {
return redirect()->route('filament.admin.auth.login')
->withErrors(['government_id' => 'No account found with this Government ID.']);
}

return redirect('/')->withErrors(['errors']);
}
}
` this is the callback
Dennis Koch
Dennis Koch2w ago
Where is callback() used?
shaan
shaanOP2w ago
Route::post('/admin/logout', [LogoutController::class, 'logout'])->name('filament.admin.auth.logout');

class LogoutController
{
public function logout(Request $request)
{
$id_token = session('efaas_id_token');

$request->session()->invalidate();

$request->session()->regenerateToken();

Auth::logout();

if ($id_token) {
$post_logout_redirect_url = 'https://fwd.host/http://students-parents-portal.test';

return Socialite::driver('efaas')->logOut($id_token, $post_logout_redirect_url);
}

return redirect('/');
}
}
Route::post('/admin/logout', [LogoutController::class, 'logout'])->name('filament.admin.auth.logout');

class LogoutController
{
public function logout(Request $request)
{
$id_token = session('efaas_id_token');

$request->session()->invalidate();

$request->session()->regenerateToken();

Auth::logout();

if ($id_token) {
$post_logout_redirect_url = 'https://fwd.host/http://students-parents-portal.test';

return Socialite::driver('efaas')->logOut($id_token, $post_logout_redirect_url);
}

return redirect('/');
}
}
Route::get('/oauth/efaas', function () {
return Socialite::driver('efaas')->redirect();
})->name('efaas.login');

Route::post('/oauth/efaas/callback',
[EfaasAuthController::class, 'callback']);
Route::get('/oauth/efaas', function () {
return Socialite::driver('efaas')->redirect();
})->name('efaas.login');

Route::post('/oauth/efaas/callback',
[EfaasAuthController::class, 'callback']);
this is in web.php
Dennis Koch
Dennis Koch2w ago
If this code return Socialite::driver('efaas')->logOut($id_token, $post_logout_redirect_url); doesn't redirect properly, I'd say check the Socialite provider.
shaan
shaanOP2w ago
Im sorry. How? you mean the package? or efaas providers?
Dennis Koch
Dennis Koch2w ago
Yes. If there's a magic redirect to https://developer.gov.mv/efaas, it's probably not from Filament 😅
shaan
shaanOP2w ago
Thanks A lot 😄 As you mentioned this is an issue with provider that was the redirect issue it was solved, however it should remove id token before logout

Did you find this page helpful?