From d913e63460137291bd357ade245de8d71e9e804b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 4 Jan 2022 15:46:23 +0100 Subject: [PATCH] [Security] Move Passport Attributes to their own section --- security/custom_authenticator.rst | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/security/custom_authenticator.rst b/security/custom_authenticator.rst index cd18e7bbd81..bc5a8ea7b30 100644 --- a/security/custom_authenticator.rst +++ b/security/custom_authenticator.rst @@ -342,39 +342,39 @@ would initialize the passport like this:: } } -.. tip:: +Passport Attributes +------------------- - Besides badges, passports can define attributes, which allows the - ``authenticate()`` method to store arbitrary information in the - passport to access it from other authenticator methods (e.g. - ``createAuthenticatedToken()``):: +.. versionadded:: 5.2 - // ... - use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; + Passport attributes were introduced in Symfony 5.2. - class LoginAuthenticator extends AbstractAuthenticator - { - // ... +Besides badges, passports can define attributes, which allows the ``authenticate()`` +method to store arbitrary information in the passport to access it from other +authenticator methods (e.g. ``createAuthenticatedToken()``):: - public function authenticate(Request $request): PassportInterface - { - // ... process the request + // ... + use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; + + class LoginAuthenticator extends AbstractAuthenticator + { + // ... - $passport = new SelfValidatingPassport(new UserBadge($username), []); + public function authenticate(Request $request): PassportInterface + { + // ... process the request - // set a custom attribute (e.g. scope) - $passport->setAttribute('scope', $oauthScope); + $passport = new SelfValidatingPassport(new UserBadge($username), []); - return $passport; - } + // set a custom attribute (e.g. scope) + $passport->setAttribute('scope', $oauthScope); - public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface - { - // read the attribute value - return new CustomOauthToken($passport->getUser(), $passport->getAttribute('scope')); - } + return $passport; } -.. versionadded:: 5.2 - - Passport attributes were introduced in Symfony 5.2. + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface + { + // read the attribute value + return new CustomOauthToken($passport->getUser(), $passport->getAttribute('scope')); + } + }