Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Update experimental_authenticators : add UserBadge#14672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
duboiss wants to merge1 commit intosymfony:5.2fromduboiss:patch-3
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletionssecurity/experimental_authenticators.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -295,8 +295,8 @@ method that fits most use-cases::
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;

Expand DownExpand Up@@ -328,14 +328,7 @@ method that fits most use-cases::
throw new CustomUserMessageAuthenticationException('No API token provided');
}

$user = $this->entityManager->getRepository(User::class)
->findOneBy(['apiToken' => $apiToken])
;
if (null === $user) {
throw new UsernameNotFoundException();
}

return new SelfValidatingPassport($user);
return new SelfValidatingPassport(new UserBadge($apiToken));
}

public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
Expand DownExpand Up@@ -472,12 +465,23 @@ are supported by default:
$apiToken
));

.. note::

If you don't need any credentials to be checked (e.g. a JWT token), you
can use the
:class:`Symfony\\Component\\Security\\Http\\Authenticator\\Passport\\SelfValidatingPassport`.
This class only requires a user and optionally `Passport Badges`_.
Self Validating Passport
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you don't need any credentials to be checked (e.g. a JWT token), you can use the
:class:`Symfony\\Component\\Security\\Http\\Authenticator\\Passport\\SelfValidatingPassport`.
This class only requires a ``UserBadge`` object and optionally `Passport Badges`_.

You can also pass a user loader to the ``UserBadge``. This callable receives the
``$userIdentifier`` as argument and must return a ``UserInterface`` object
(otherwise a ``UsernameNotFoundException`` is thrown). If this is not set,
the default user provider will be used with ``$userIdentifier`` as username::

// ...
return new SelfValidatingPassport(new UserBadge($email, function ($username) {
return $this->userRepository->findOneBy(['email' => $username]);
});


Passport Badges
~~~~~~~~~~~~~~~
Expand DownExpand Up@@ -547,7 +551,7 @@ authenticator, you would initialize the passport like this::
``createAuthenticatedToken()``)::

// ...
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;

class LoginAuthenticator extends AbstractAuthenticator
{
Expand All@@ -557,7 +561,7 @@ authenticator, you would initialize the passport like this::
{
// ... process the request

$passport = new SelfValidatingPassport($username, []);
$passport = new SelfValidatingPassport(new UserBadge($username), []);

// set a custom attribute (e.g. scope)
$passport->setAttribute('scope', $oauthScope);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp