Skip to content

Commit d5b6e4e

Browse files
committed
minor #16369 [Security] Move Passport Attributes to their own section (javiereguiluz)
This PR was merged into the 5.3 branch. Discussion ---------- [Security] Move Passport Attributes to their own section I think attributes are important enough to move them to their own section, which also allows them to appear in the page TOC. Commits ------- d913e63 [Security] Move Passport Attributes to their own section
2 parents 33f0534 + d913e63 commit d5b6e4e

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

security/custom_authenticator.rst

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)