Skip to content

Commit 11de2ed

Browse files
committed
Documented passport attributes
1 parent ca8621d commit 11de2ed

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

security/experimental_authenticators.rst

+36
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,39 @@ authenticator, you would initialize the passport like this::
502502
]);
503503
}
504504
}
505+
506+
.. tip::
507+
508+
Besides badges, passports can also have generic attributes. This is
509+
useful if you want to access information from ``authenticate()`` in
510+
another authenticator method (e.g. ``createAuthenticatedToken()``)::
511+
512+
// ...
513+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
514+
515+
class LoginAuthenticator extends AbstractAuthenticator
516+
{
517+
// ...
518+
519+
public function authenticate(Request $request): PassportInterface
520+
{
521+
// ... process the request
522+
523+
$passport = new SelfValidatingPassport($username, []);
524+
525+
// set a custom attribute (e.g. scope)
526+
$passport->setAttribte('scope', $oauthScope);
527+
528+
return $passport;
529+
}
530+
531+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
532+
{
533+
// read the attribute value
534+
return new CustomOauthToken($passport->getUser(), $passport->getAttribute('scope'));
535+
}
536+
}
537+
538+
.. versionadded:: 5.2
539+
540+
Passport attributes were introduced in Symfony 5.2.

0 commit comments

Comments
 (0)