@@ -342,39 +342,39 @@ would initialize the passport like this::
342342 }
343343 }
344344
345- .. tip ::
345+ Passport Attributes
346+ -------------------
346347
347- Besides badges, passports can define attributes, which allows the
348- ``authenticate() `` method to store arbitrary information in the
349- passport to access it from other authenticator methods (e.g.
350- ``createAuthenticatedToken() ``)::
348+ .. versionadded :: 5.2
351349
352- // ...
353- use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
350+ Passport attributes were introduced in Symfony 5.2.
354351
355- class LoginAuthenticator extends AbstractAuthenticator
356- {
357- // ...
352+ Besides badges, passports can define attributes, which allows the `` authenticate() ``
353+ method to store arbitrary information in the passport to access it from other
354+ authenticator methods (e.g. `` createAuthenticatedToken() ``)::
358355
359- public function authenticate(Request $request): PassportInterface
360- {
361- // ... process the request
356+ // ...
357+ use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
358+
359+ class LoginAuthenticator extends AbstractAuthenticator
360+ {
361+ // ...
362362
363- $passport = new SelfValidatingPassport(new UserBadge($username), []);
363+ public function authenticate(Request $request): PassportInterface
364+ {
365+ // ... process the request
364366
365- // set a custom attribute (e.g. scope)
366- $passport->setAttribute('scope', $oauthScope);
367+ $passport = new SelfValidatingPassport(new UserBadge($username), []);
367368
368- return $passport;
369- }
369+ // set a custom attribute (e.g. scope)
370+ $passport->setAttribute('scope', $oauthScope);
370371
371- public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
372- {
373- // read the attribute value
374- return new CustomOauthToken($passport->getUser(), $passport->getAttribute('scope'));
375- }
372+ return $passport;
376373 }
377374
378- .. versionadded :: 5.2
379-
380- Passport attributes were introduced in Symfony 5.2.
375+ public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
376+ {
377+ // read the attribute value
378+ return new CustomOauthToken($passport->getUser(), $passport->getAttribute('scope'));
379+ }
380+ }
0 commit comments