L
L
leoismyname2014-06-04 11:58:32
symfony
leoismyname, 2014-06-04 11:58:32

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

3 answer(s)
P
Pavel Solovyov, 2014-06-04
@leoismyname

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);

or make your own authentication provider
symfony.com/doc/current/cookbook/security/custom_a...

S
Sergey, 2014-06-04
Protko @Fesor

Read the documentation. You need to implement your userProvider based on session data, and a firewall.

F
faost, 2014-06-26
@faost

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 :

  1. We create a user class that implements the UserInterface interface (there are only 5 methods)
  2. We write a class that implements UserProviderInterface , which will retrieve the user by name with a password hash and other data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question