Код: Выделить всё
class SamlController extends AbstractController
{
private LoggerInterface $logger;
private EntityManagerInterface $entityManager;
private UserPasswordHasherInterface $userPasswordHasher;
private UserAuthenticatorInterface $userAuthenticator;
public function __construct(LoggerInterface $logger, EntityManagerInterface $entityManager, UserPasswordHasherInterface $userPasswordHasher, UserAuthenticatorInterface $userAuthenticator)
{
$this->logger = $logger;
$this->entityManager = $entityManager;
$this->userPasswordHasher = $userPasswordHasher;
$this->userAuthenticator = $userAuthenticator;
}
#[Route('/saml/login', name: 'saml_login')]
public function saml(Request $request, Security $security, string $sp = "default-sp", ): Response
{
$session = $request->getSession();
$userInfo = $this->samlMSAuth($sp);
$user = $this->entityManager->getRepository(Zuser::class)->findOneBy(['email' => '[email protected]']);
$security->login($zuser, 'security.authenticator.form_login.main', 'main');
return $this->redirect('/home');
}
#[Route('/saml/logout', name: 'saml_logout')]
public function samlLogout(Security $security): Response
{
$security->logout(false);
return $this->redirectToRoute('saml_login');
}
public function samlMSAuth(string $sp = "default-sp")
{
$as = new \SimpleSAML\Auth\Simple($sp);
$as->requireAuth();
$attributes = $as->getAttributes();
$email = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'];
$surname = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname'];
$givenname = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname'];
$userInfo = [
"Email" => $email[0],
"Surname" => $surname[0],
"Givenname" => $givenname[0],
];
return $userInfo;
}
}
Но когда вы переходите на другие страницы, пользователь больше не входит в систему.
Но удалите $userInfo = $this->samlMSAuth($sp); и жестко запрограммируйте адрес электронной почты и войдите в систему программно, пользователь сохранится на всех страницах.
Код: Выделить всё
$as = new \SimpleSAML\Auth\Simple($sp);
$as->requireAuth();
Даже если сеанс испортился, после входа в систему был создан новый сеанс, но почему он не сохраняется ?
Сессия перед входом в систему пуста,
Пробовал $request->getSession()->set('_security_main', сериализация($token));< /p>
Сеанс должен сохраняться во время перенаправления, но почему-то этого не происходит.
Но удаляет $userInfo = $this->samlMSAuth($sp ); так что без внешнего перенаправления все работает.
Как решить эту проблему?
Подробнее здесь: https://stackoverflow.com/questions/791 ... gin-not-wo