Skip to content

Commit bff0769

Browse files
committed
bug #13524 Fix test login example for 4.4 - 5.0 applications (wouterj)
This PR was merged into the 4.4 branch. Discussion ---------- Fix test login example for 4.4 - 5.0 applications Fixes part of #13376 Since Symfony 4.4, user equality is checked on each request thus the current method (with a non-existent user) is broken. I've updated the example to use something similar to the new `loginUser()` method in Symfony 5.1. This fixes the docs for 4.4 and 5.0. See #13523 for improvements of this chapter in 5.1. Commits ------- fb8123a Fix test login example for 4.4 - 5.0 applications
2 parents 63543e8 + fb8123a commit bff0769

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

testing/http_authentication.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ needs::
113113
{
114114
$session = self::$container->get('session');
115115

116+
// somehow fetch the user (e.g. using the user repository)
117+
$user = ...;
118+
116119
$firewallName = 'secure_area';
117120
// if you don't define multiple connected firewalls, the context defaults to the firewall name
118121
// See https://symfony.com/doc/current/reference/configuration/security.html#firewall-context
119122
$firewallContext = 'secured_area';
120123

121124
// you may need to use a different token class depending on your application.
122125
// for example, when using Guard authentication you must instantiate PostAuthenticationGuardToken
123-
$token = new UsernamePasswordToken('admin', null, $firewallName, ['ROLE_ADMIN']);
126+
$token = new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
124127
$session->set('_security_'.$firewallContext, serialize($token));
125128
$session->save();
126129

0 commit comments

Comments
 (0)