-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session loss when refreshing the page. #101
Comments
i solved this problem by overriding the routes/web.php Route::group([
'prefix' => config('saml2.routesPrefix'),
'middleware' => array_merge(['saml2.resolveTenant'], config('saml2.routesMiddleware')),
], function () {
Route::get('/{uuid}/logout', array(
'as' => 'saml.logout',
'uses' => 'Slides\Saml2\Http\Controllers\Saml2Controller@logout',
));
Route::get('/{uuid}/login', array(
'as' => 'saml.login',
'uses' => 'Slides\Saml2\Http\Controllers\Saml2Controller@login',
));
Route::get('/{uuid}/metadata', array(
'as' => 'saml.metadata',
'uses' => 'Slides\Saml2\Http\Controllers\Saml2Controller@metadata',
));
Route::post('/{uuid}/acs', array(
'as' => 'saml.acs',
'uses' => 'App\Http\Controllers\SSOAuthController@acs',
));
Route::get('/{uuid}/sls', array(
'as' => 'saml.sls',
'uses' => 'Slides\Saml2\Http\Controllers\Saml2Controller@sls',
));
}); controller public function acs(Auth $auth): Redirector|RedirectResponse
{
$errors = $auth->acs();
if (!empty($errors)) {
$error = $auth->getLastErrorReason();
$uuid = $auth->getTenant()->uuid;
logger()->error('saml2.error_detail', compact('uuid', 'error'));
session()->flash('saml2.error_detail', [$error]);
logger()->error('saml2.error', $errors);
session()->flash('saml2.error', $errors);
return redirect(config('saml2.errorRoute'));
}
$user = $auth->getSaml2User();
event(new SignedIn($user, $auth));
// set cookies so that the browser can remember the session
$res = response()->noContent();
$res->headers->setCookie(new Cookie('XSRF-TOKEN', csrf_token(), now()->addDay()));
$res->headers->setCookie(new Cookie(config('session.cookie'), session()->getId(), now()->addDay()));
Log::info('Sending cookie with redirect response', [
'headers' => $res->headers->all(),
]);
$redirectUrl = $user->getIntendedUrl();
if ($redirectUrl) {
// pass the headers to the redirect
return redirect($redirectUrl, headers: $res->headers->all());
}
return redirect($auth->getTenant()->relay_state_url ?: config('saml2.loginRoute'), headers: $res->headers->all()); // pass the headers to the redirect
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have this code lo listen SignedIn. This part seems to work fine, I retrieve the User from SSO and save it as User in my database and log in. The problem is when I reload the page, I realize that the session has been lost. What could be the error?
And I also have a "CheckIfAdmin" midelware which is where I detect that the login is lost when refreshing the page
The text was updated successfully, but these errors were encountered: