Answer the question
In order to leave comments, you need to log in
Authorization of users on Symfony 2?
Good afternoon
I have such a question - using an external authentication service, I need to launch users to the site, without saving their state in the database, that is, only sessions.
In other words:
1. The user enters a login and password;
2. Press Login;
3. A request is sent from the application to the SA (login and password);
4. The response of the CA is processed (entry is possible or not);
5. The user gets or doesn't get access to the application.
Actually, the check itself should not particularly worry you, you are interested in the principle of operation of such a scheme and possible ways of implementation.
Answer the question
In order to leave comments, you need to log in
check authorization as you like, and then do like this
$session = $this->client->getContainer()->get('session');
$firewall = 'secured_area';
$token = new UsernamePasswordToken('username', null, $firewall, array('ROLE_USER'));
$session->set('_security_'.$firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
Read the documentation. You need to implement your userProvider based on session data, and a firewall.
If you use one of the popular methods, then symphony has many bandals for different authentication protocols .
If everything is custom, then, as mentioned above, you need to write your own authentication provider.
If, nevertheless, we transfer authentication to symphony, and the service can return by username and password hash, then it’s enough to make your own UserProvider :
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question