@@ -342,39 +342,39 @@ would initialize the passport like this::
342
342
}
343
343
}
344
344
345
- .. tip ::
345
+ Passport Attributes
346
+ -------------------
346
347
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
351
349
352
- // ...
353
- use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
350
+ Passport attributes were introduced in Symfony 5.2.
354
351
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() ``)::
358
355
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
+ // ...
362
362
363
- $passport = new SelfValidatingPassport(new UserBadge($username), []);
363
+ public function authenticate(Request $request): PassportInterface
364
+ {
365
+ // ... process the request
364
366
365
- // set a custom attribute (e.g. scope)
366
- $passport->setAttribute('scope', $oauthScope);
367
+ $passport = new SelfValidatingPassport(new UserBadge($username), []);
367
368
368
- return $passport;
369
- }
369
+ // set a custom attribute (e.g. scope)
370
+ $passport->setAttribute('scope', $oauthScope);
370
371
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;
376
373
}
377
374
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