@@ -1599,6 +1599,52 @@ and set the ``limiter`` option to its service ID:
1599
1599
;
1600
1600
};
1601
1601
1602
+ Login Programmatically
1603
+ ----------------------
1604
+
1605
+ .. versionadded :: 6.2
1606
+
1607
+ The :class: `Symfony\B undle\S ecurityBundle\S ecurity\S ecurity <Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security> `
1608
+ class was introduced in Symfony 6.2. Prior to 6.2, it was called
1609
+ ``Symfony\Component\Security\Core\Security ``.
1610
+
1611
+ .. versionadded :: 6.2
1612
+
1613
+ The :method: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security::login `
1614
+ method was introduced in Symfony 6.2.
1615
+
1616
+ You can log in a user programmatically using the `login() ` method of the
1617
+ :class: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security ` helper::
1618
+
1619
+ // src/Controller/SecurityController.php
1620
+ namespace App\Controller\SecurityController;
1621
+
1622
+ use App\Security\Authenticator\ExampleAuthenticator;
1623
+ use Symfony\Bundle\SecurityBundle\Security\Security;
1624
+
1625
+ class SecurityController
1626
+ {
1627
+ public function someAction(Security $security): Response
1628
+ {
1629
+ // get the user to be authenticated
1630
+ $user = ...;
1631
+
1632
+ // log the user in on the current firewall
1633
+ $this->security->login($user);
1634
+
1635
+ // if the firewall has more than one authenticator, you must pass it explicitly
1636
+ // by using the name of built-in authenticators...
1637
+ $this->security->login($user, 'form_login');
1638
+ // ...or the service id of custom authenticators
1639
+ $this->security->login($user, ExampleAuthenticator::class);
1640
+
1641
+ // you can also log in on a different firewall
1642
+ $this->security->login($user, 'form_login', 'other_firewall');
1643
+
1644
+ // ... redirect the user to its account page for instance
1645
+ }
1646
+ }
1647
+
1602
1648
.. _security-logging-out :
1603
1649
1604
1650
Logging Out
0 commit comments