i am using laravel version 8, i did single signon, i created EventServiceProvider
, in this provide i did login by email data, i can see by Auth::check
command login is working, but when it redirected to home page Auth::check doesn’t work, can anyone please help me why i am getting this issue ? here i uploaded my code, can anyone please help me how to resolve this issue ?
class EventServiceProvider extends ServiceProvider { protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], ]; public function boot() { try{ Event::listen('AacotroneoSaml2EventsSaml2LoginEvent', function (Saml2LoginEvent $event) { $messageId = $event->getSaml2Auth()->getLastMessageId(); $user = $event->getSaml2User(); $userData = [ 'id' => $user->getUserId(), 'attributes' => $user->getAttributes(), 'assertion' => $user->getRawSamlAssertion() ]; $userInfo = User::where('email',$userData['id'])->first(); if($userInfo) { //$loggedInUser = Auth::loginUsingId($userInfo->id); $loggedInUser = Auth::login($userInfo); } }); } catch (Throwable $e) { echo $e->getMessage(); die; report($e); } } }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I think there is some session issue. In Laravel when you try to login manually, you should also regenerate a new session token.
You can add the below code above Auth::login($userInfo)
to generate new session token
request()->session()->invalidate(); request()->session()->regenerateToken();
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0